A lightweight, robust, modular server built on Express and Alasql
- 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');
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();
Configure the server
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');
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
Start the server
The ndx
object gets passed to each controller and service
ndx.app
- The express appndx.server
- The express serverndx.database
- The databasendx.settings
- Server settingsndx.host
- Server hostndx.port
- Server port
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 implementationndx.postAuthenticate(req, res, next)
used internallyndx.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.
- 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
Use the ndx-framework app to quickly create, connect to and configure ndx-server apps