Code Monkey home page Code Monkey logo

nodejs-api-template's Introduction

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

Run the application as a service

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/[name]-[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

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.