npm install server --save

Conceptually server is a function that accepts options and other functions. The heavy lifting is already implemented so you can focus on your project:

// Import the variable into the file
const server = require('server');

// options and fn1, fn2, etc are optional
server(options, fn1, fn2, fn3, ...);

The most important concepts to use server are: options, middleware and router.

Subscribe here to receive tutorials when released. Tutorials are good for learning while the documentation is good for reference/quick use once you know the basics.


In its basic form it's a plain object with several key:values pairs:

const server = require('server');

// Set the options (shown here with the defaults)
const options = {
  port: 3000
  secret: 'secret-XXXX'
  public: 'public'
  engine: 'pug'
  env: 'development'

// Launch the server with the options

Options documentation


Middleware are functions that accepts a context, does some work and is resolved either synchronous or asynchronous. Mandatory Hello World here:

// Load the server from the dependencies
const server = require('server');

// Display "Hello 世界" for any request
const middleware = ctx => 'Hello 世界';

// Launch the server with a single middleware

Middleware documentation


The last but maybe most important part is the router that is used to create routes. A route is really a middleware and is used for handling user requests to specific places:

const server = require('server');

// Import some of the routers available
const { get, post, put, del } = server.router;

// Handle requests to http://localhost:3000/
const home = get('/', ctx => 'Homepage!');

// Handle requests to http://localhost:3000/SOMETHING
const page = get('/:page', ctx => `Page ${}`);

server(home, page);

Router documentation


Some recommendations on using and debugging server. A peak into the technology inside for understanding it better. Explanation on some of the design constrains for server.

Advanced documentation