Skip to content

A Node.js starter containing common components and services as a reference API.

Notifications You must be signed in to change notification settings

bluehalo/node-rest-starter

Repository files navigation

Node REST Starter

Build Status Maintainability Test Coverage

Getting Started

Prereqs

Required

  • nodejs 14.x, 16.x - this project supports .tool-versions via asdf
  • mongodb 4.0, 4.2

Recommended

  • docker - Start Up contains instructions for installing mongo via docker

Start Up

  1. To get started run npm run init(if you do not have mongo running use npm run init:mongo)
    • This will install the dependencies and setup the development.js environment from the template
  2. Start the application via npm start

Related Commands

  • init - initalizes project
  • init:mongo - initalizes project and runs mongodb via docker
  • init:env:dev - copies development environment config template to usable location
  • init:mongo:up - uses docker compose to run containerized mongodb
  • init:mongo:express - uses docker compose to run mongo express at http://localhost:8081 for mongo debugging
  • init:mongo:down - removes node-rest-starter docker container group
  • start - runs project and watches for changes and reloads
  • start:dev - runs with node_env set to development
  • start:prod - runs compiled version of project

API Documentation

Endpoint Documentation for this application is generated from the *.routes.js files in each module.
Model/Schema documentation should be included in with each model and will be compiled from any file matching *.model.js.

When the application is started, Swagger provides an interface for this API that is available by default at http://localhost:3000/api-docs

The existence and path for this Swagger page is configurable via the apiDocs parameter, which defaults to:

{
	"enabled": true,
	"path": "/api-docs"
}

Providers

Several services use configurable "providers" in order to easily swap functionality in and out of the application.

For example, the Email Service at ./src/app/core/email/email.service.ts can be controlled via the mailer.provider configuration to use any of the out-of-the-box providers:

  1. HTTPS
  2. SMTP
  3. Log
  4. File
  5. Noop

The default provider for a service will be included in dependencies in NPM's package.json. On the other hand, any non-default providers should include their dependencies as devDependencies in order to reduce the inclusion of unnecessary modules in production builds.

If a non-default provider is used (e.g., node-kafka for the Event service), the application instance should include this module in dependencies on its own fork, instead of updating the node-rest-starter reference application.

Testing

Tests run as an NPM script. To support development, npm run test will watch all files via nodemon and will run tests as files are updated.

In order to generate code coverage output via a single run of the test suite, npm run test:ci will output coverage results into the top-level ./coverage directory, both in HTML and LCOV formats.

Installing on Production

Since Mongoose suggests not automatically creating Mongo indices on-the-fly, the following utility script can be run, targeting the production Mongo instance / cluster, to create/sync all required indices.

node ./src/sync-indexes.js

About

A Node.js starter containing common components and services as a reference API.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published