@harvard.dce/express
Pre-configured express server
Last updated a year ago by harvard-linlee .
MIT · Original npm · Tarball · package.json
$ cnpm install @harvard.dce/express 
SYNC missed versions from official npm registry.

Express Server

Express server is preconfigured standard security modules and standard middleware modules installed and configured. It also installs with morgan to output standard apache log for HTTP transactions. External memory storage for memcached, redis, and redis cluster is optional.

Install

$ npm install @harvard.dce/express-server

Usage

Initialization

Before start express server, it must be configured with some required parameters.

const server = require('@harvard.dce/express-server')

server({
  // apply required attributes
  port: '5000',
  // apply the following optional attributes
  isHttpsForced: false,
  isClusterEnabled: false,
  numClusterWorkers: 0,
  cache: {
    sessionStorage: "redis",
    sessionExpiration : 20,
    sessionPassPhase : "SOME PASSWORD",
    redis: {
      masterHost: "redis",
      masterPort: 6379
    }
  },
  middlewares: function setup (app, callback) {
    app.get('/api/hello-world', function sayHello (req, res) {
      res.status(200).send('Hello World!')
    })
    app.get("/bye", function sayGoodbye(req, res) {
      res.status(200).send("Goodbye.")
    })
    callback(null, app)
  }
}, function startServer (err) {
  if (err) {
    console.error(err)
    process.exit(1)
  }
  console.log('Express server started on pid ' + process.pid)
}) 

Cache (Session Storage)

Options for cache.sessionStorage

  1. local - Local server's memory storage (not recommended)
  2. memcahed - Memcached instance
  3. redis - Redis instance
  4. redisCluster - Redis cluster; A sentinel instance is required to provide.

Current Tags

  • 1.0.0                                ...           latest (a year ago)

1 Versions

  • 1.0.0                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 1
Last Month 2
Dependencies (14)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |