Skip to content

paulswebapps/expressAPI

Repository files navigation

dependencies Build Status License

Simple Web Service

This is a bare-bones web service, to quickly get started in building a stateless (and therefore clusterable) web service.

Setup

Clone this repo.

git clone https://github.com/paulswebapps/expressAPI

Install yarn

brew install yarn

Install using npm or yarn.

yarn

Run all tests

yarn test

Debugging

When debugging, run server.js directly. For VS Code, the debugger's configuration file could look like this:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch Program",
      "program": "${workspaceRoot}/server.js"
    }
  ]
}

To confirm that the server is up and responding to request, ping http://localhost:3001/healthcheck. It should return some sort of positive confirmation message, like "we are healthy and good".

Clustering

Node, by default, runs on a single core. To spawn multiple processes, load-balanced across cores, we use the cluster module, called in by PM2.

Start the server cluster, one process per core, load balanced.

yarn start

You should see PM2's report of online node load-balanced processes.

For benchmarking, it can be useful to monitor your node processes.

yarn run monitor

When you're done using your cluster, stop all processes.

yarn stop

License

MIT

About

Simple REST API Server

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published