Skip to content

angelsanchez/nodejs-api-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nodejs-api-template

A boilerplate for building a NodeJS API server. Use it as a template project when you want to start a new project.

Dependencies

  • restify is a smallish framework, similar to express for building REST APIs.
  • mongoose is a MongoDB object modeling tool designed to work in an asynchronous environment.
  • config organizes hierarchical configurations for your app deployments.
  • bunyan is a JSON logging library for node.js services
  • pm2 is a production process manager for Node.js applications with a built-in load balancer

Dev. dependencies

  • supertest is a library for testing node.js HTTP servers using a fluent API
  • gulp Automate and enhance your workflow
  • gulp-jshint is a tool that helps to detect errors and potential problems in your JavaScript code
  • gulp-jscs is a code style linter for programmatically enforcing your style guide
  • gulp-cucumber gulp task for running cucumber.js features
  • gulp-bump bump npm versions with Gulp
  • gulp-git is a git plugin for gulp
  • gulp-tag-version tag git repository with current package version
  • pre-commit A better pre-commit hook for git
  • mongoose-simple-fixtures Simple default data for mongoose models.
  • istanbul Code Coverage Tool.

Run the application as a service

Install dependencies (Requires nodejs+npm)

$ npm install

Start the service

$ npm start

Show the service status

$  npm status

Stop the service

$  npm stop

Logs

All application logs (requests, responses, traces and mongodb accesses) are stored in a file. The log file path is ~/.pm2/logs/library-example-[id].log.

Read logs

$ npm run logs

Read error logs

Show errors in http requests:

$ tail -f ~/.pm2/logs/[name]-[id].log | node_modules/bunyan/bin/bunyan -c 'this.res && this.res.statusCode >= 500'

Development

The pre-commit doesn't allow you to commit files with invalid format. We use the airbnb style guide. And the tests are going to be checked before the git commit.

Run the application

$ node src/server.js

Read the logs better using bunyan:

$ node src/server.js | ./node_modules/bunyan/bin/bunyan

Run tests

$ npm test

Debug tests

This command initializes node in debug mode and runs the cucumbers.

$ npm run debug:test

Versioning

Versioning Used: Semantic

  • major: version when you make incompatible API changes, e.g. 1.0.0
  • minor: version when you add functionality in a backwards-compatible manner, e.g. 0.1.0
  • patch: version when you make backwards-compatible bug fixes, e.g. 0.0.1
Increase patch version

This command increases the package version, commits changes and create a tag for the new version.

$ npm run patch
Increase minor version

This command increases the package version, commits changes and create a tag for the new version.

$ npm run minor
Increase major version

This command increases the package version, commits changes and create a tag for the new version.

$ npm run major

Run Code Coverage Tool

$ npm run coverage

About

An archetype of a Node JS API server. Use it as a template project when you want to start a new project.

Resources

License

Stars

Watchers

Forks

Packages

No packages published