Node.js API server/backend build with Express.js, GitHub Actions build, babel, minimal tooling (nodemon, standard), and mocha tests. Can be used as a template to quickly bootstrap yor Node.js server projects.
- automatic reloading using nodemon
- linting and fixing using standard
- git pre-commit hooks using husky and lint-staged
- latest ECMAScript2015 support using babel 7
- unit and integration tests using mocha
- coverage tests using nyc
- code coverage tracking using coveralls
- load .env to environment using dotenv
- continuous integration using GitHub Actions CI
- code documentation using JSDoc JSDoc
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
git clone [email protected]:mihaur/node-server-template.git
cd cd node-server-template
cp .env.sample .env
npm install
npm start
Use .env to store your environment dependant configuration options and secrets. This file should not be checked in to your repository, use .env.sample as example but exclude real secrets.
To run the build use npm run build
. Build artifacts along source maps are stored in dist folder.
To debug build code run npm run debug
.
Then you can attach your IDE or Chrome DevTools to a running process by appending WebSocket UUID printed to console to chrome-devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=localhost:9229/ . See Node.js documentation for details.
Linting is done using standard. Use npm run lint
to run linter. Linter output is piped trough snazzy which converts "compact" text from a linter to "stylish". You can also automatically fix linter errors by running npm run lint:fix
.
Tests can be run by mocha. Run npm run test
to run both unit and integration tests.
Unit tests are stored in src/**.spec.js.
Integration tests are stored in test/**.spec.js.
Run npm run coverage
to generate test coverage report. Both unit and integration tests are run. Report is generated in coverage/ directory using HTML and lcov formatters. Use npx serve coverage
to serve generated HTML.
Run npm run doc
to create HTML documentation from JSDoc annotations. Documentation is stored in doc/ directory. Use npx serve coverage
to serve generated documentation.