2.10.0 • Published 4 years ago

@dollarshaveclub/nodejs-server v2.10.0

Weekly downloads
320
License
ISC
Repository
github
Last release
4 years ago

Node.js Server

CircleCI codecov Greenkeeper badge

This is the main server to be used in all of Dollar Shave Club's node.js applications.

Features

  • Graceful shutdown
  • Health checks via GET /ping
  • Supports both Express and Koa
  • Datadog metrics
  • Rollbar

Environment Variables

  • NODE_ENV=development
  • PORT or LISTEN_PORT
  • SOCKET_TIMEOUT_SECONDS=120
  • GRACEFUL_SHUTDOWN_TIMEOUT_SECONDS=15
  • ROLLBAR_POST_SERVER_ITEM_ACCESS_TOKEN - access token for server-side rollbar

Usage

API

serve(app, options)

Options:

  • name - name of the repo
  • port
  • socketTimeout
  • gracefulShutdownTimeout
  • rollbarPostServerItemAccessToken

For development only:

  • proxy = false - whether to proxy requests
  • proxyHostname = process.env.PROXY_HOSTNAME || release.dollarshaveclub.com - what server to proxy
  • proxyMatch = /^\/(api|cms|face-assets)\// - regex to match paths to proxy

To support proxying locally and internationally, add the following to your /etc/hosts:

::1             localhost     # should have already been added
::1             localhost.au
::1             localhost.ca
::1             localhost.uk

Express

const serve = require('@dollarshaveclub/nodejs-server')

const app = require('express')()

// app logic

serve(app, {
  name: 'my-app',
}).then(({ port }) => {
  console.log(port)
})

Koa

const serve = require('@dollarshaveclub/nodejs-server')
const Koa = require('koa')

const app = new Koa()

// app logic

serve(app, {
  name: 'my-app'
})

Typescript w/ Koa

import serve from "@dollarshaveclub/nodejs-server"
await serve(new Koa(), {name: "my-app"})
2.10.0

4 years ago

2.9.5

4 years ago

2.9.4

4 years ago

2.9.3

5 years ago

2.9.2

6 years ago

2.9.1

6 years ago

2.9.0

6 years ago

2.8.0

6 years ago

2.7.0

6 years ago

2.6.0

6 years ago

2.5.1

6 years ago

2.5.0

6 years ago

2.4.0

6 years ago

2.3.1

7 years ago

2.3.0

7 years ago

2.2.0

7 years ago

2.2.0-rc.1

7 years ago

2.1.0

7 years ago

2.0.0

7 years ago

1.2.0

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago