ndx-server

0.18.1 • Public • Published

ndx-server

A lightweight, robust, modular server built on Express and Alasql

Features

  • No need for a database server
  • Persists to S3 with as few reads and writes as possible
  • Sessionless tokens can withstand a server restart
  • Scale servers easily using ndx-sync
  • Schemaless SQL database which treats javascript objects as first class citizens

npm install --save ndx-server

var ndx = require('ndx-server');

Example

  var ndx = require('ndx-server')
  .config({
    database: 'rb',
    tables: ['users', 'tasks'],
    port: 23000
  })
  .controller(function(ndx) {
    ndx.app.get('/api/thing', function(req, res) {
      res.json({
        hey: 'yo'
      });
    });
  })
  .start();

Methods

ndx.config(object args) -> ndx

Configure the server

ndx.controller(function controller) -> ndx

Register a controller

ndx.controller(function(ndx) {
  //use the ndx controller
  //register some routes etc
});
ndx.controller(require('./controllers/my-controller'));
ndx.controller('npm-module');

ndx.use(function controller) -> ndx

Register a service

ndx.use(function(ndx) {
  //use the ndx service
  //register some routes etc
});
ndx.use(require('./services/my-service'));
ndx.use('npm-module');

all modules from the folders /startup, /services and /controllers now get auto-loaded so you no longer need to reference them

ndx.start()

Start the server

the ndx object

The ndx object gets passed to each controller and service

Properties

  • ndx.app - The express app
  • ndx.server - The express server
  • ndx.database - The database
  • ndx.settings - Server settings
  • ndx.host - Server host
  • ndx.port - Server port

Methods

  • ndx.generateHash(string) -> hashed string
  • ndx.validPassword(password, hashedPassword) -> bool
  • ndx.authenticate() middleware to authenticate a route, see ndx-user-roles for a more robust implementation
  • ndx.postAuthenticate(req, res, next) used internally
  • ndx.generateToken(string userId, string ip) -> new user token
  • ndx.setAuthCookie(req, res) used internally

other modules can add extra properties and methods to the ndx object, eg ndx-passport which adds ndx.passport for the other passport modules to use.

all ndx modules get auto-loaded by default, so all you need to do is npm install them

modules

ndx-framework

Use the ndx-framework app to quickly create, connect to and configure ndx-server apps

Readme

Keywords

none

Package Sidebar

Install

npm i ndx-server

Weekly Downloads

224

Version

0.18.1

License

MIT

Unpacked Size

77.7 kB

Total Files

23

Last publish

Collaborators

  • ndxbxrme