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-auth - oauth2 style authentication endpoints for ndx-server
- ndx-connect - external database connection for superadmin users
- ndx-database-backup - regularly backs up the database
- ndx-keep-awake - keeps the server alive (useful for free hosts, eg heroku)
- ndx-memory-check - check the memory status of your server
- ndx-passport - local login
- ndx-passport-facebook - facebook login
- ndx-passport-github - github login
- ndx-passport-twitter - twitter login
- ndx-publish - pub/sub with sockets
- ndx-socket - sockets
- ndx-static-routes - clientside routing
- ndx-superadmin - creates a default superadmin user then bugs you about updating the password
- ndx-sync - synchronize multiple instances of ndx-server using sockets, scale gracefully
- ndx-user-roles - user roles
ndx-framework
Use the ndx-framework app to quickly create, connect to and configure ndx-server apps