DEV Community

Cover image for Node.js Application Template
Anshuman Chhapolia
Anshuman Chhapolia

Posted on • Edited on

Node.js Application Template

This post discuss about the template we use at SmokeTrees.

To start the server run

$ npm start 

Note: This will run a server for development environment.
For information on deploying express application to production server and learn best practices refer this.

logger

This directory has 2 files.

  • logger.js exports a winston object which we use for logging. You should edit logger.js to write your config for the logs.
  • morgan.js exports a pre-configured morgan object to log using stream to winston object. It is used to intercept the HTTP request and log the request and response details. For more details visit the official page for morgan.

routes

Directory for defining routes. I don't think this need more explanation.

Additional Information

  • If on Linux running the following command add ./node_modules/.bin to the path.
  $ source ./activate

By doing so we can use the commands installed with packages using the terminal.
This won't be required in many IDEs like Webstorm but I thought it will be a good idea to include it.

  • standard.js has been added as the default linting and styling tool

Use :

  $ npm run lint

Fixes whatever can be fixed. Above command logs out the errors which it couldn't fix.

  • mocha is used for testing and chai is used for assertion. chai-http is used to test http endpoints.

Use:

    $ npm test
  • nyc is used as the default coverage tool. Use:
   $ npm run coverage
  • The master contains code for an HTTP server. Checkout the branch https for the HTTP server. Replace the self-signed certificates in the certs with your SSL certificates.

Dependency information

Dependency Usage
compression Compresses the response
express Express
morgan HTTP request logger
winston General purpose logger for the application
nyc Code Coverage tool
standard Linting and styling tool.
chai Assertion Library
chai-http Middleware for chai to test http endpoints

Top comments (4)

Collapse
 
lineldcosta profile image
lineldcosta

Why compression is used??? U can use nginx to achieve the same right?

Collapse
 
achhapolia10 profile image
Anshuman Chhapolia

Yes, nginx can be used to achieve the same. But I wanted to make this template as generic as possible. So if some project is not using nginx as reverse proxy it still has compression.

Collapse
 
johnmunsch profile image
John Munsch

You accidentally misspelled the URL above for the template repo. Here's the correct one: github.com/smoke-trees/nodejs-back...

Collapse
 
achhapolia10 profile image
Anshuman Chhapolia

Thank you for pointing out the error.