ndx-server

my server framework

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
ndx-server
0180.18.15 years ago7 years agoMinified + gzip package size for ndx-server in KB

Readme

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
  • Schemaless SQL database which treats javascript objects as first class citizens
npm install --save ndx-server ```javascript var ndx = require('ndx-server'); ```

Example

```javascript 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 ```javascript ndx.controller(function(ndx) { //use the ndx controller //register some routes etc }); ``` ```javascript ndx.controller(require('./controllers/my-controller')); ``` ```javascript ndx.controller('npm-module'); ```

ndx.use(function controller) -> ndx

Register a service ```javascript ndx.use(function(ndx) { //use the ndx service //register some routes etc }); ``` ```javascript ndx.use(require('./services/my-service')); ``` ```javascript 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-keep-awake - keeps the server alive (useful for free hosts, eg heroku)
  • 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-framework

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