NodeJs Tips

I started developing in Node Js 8 months ago and at the beginning I wish to know everything that I know today. With this post I want to share some tips and good practices that I learned.

Use Strict

“use strict” was introduced in Javascript 5, you should use it when you are writing javascript code in Client (Browser) or Server Side (NodeJs) ALWAYS!!! To change the compiler to strict mode it’s only necessary to write “use strict”; and the compiler will automatically change to strict mode.

Strict Mode Benefits

  • Easier to write “secure” JavaScript.
  • Converts mistakes into errors.
  • Simplifies variable uses.

Bad Example:

This piece of code runs fine in javascript but if you use the “use strict” the Js compiler will throw “ReferenceError” because the variables x and y are not defined.

Good Example:

More information about use strict

NPM Good practices

Npm (Node Package Module) it’s the package manager for javascript applications like gems in Ruby or nuget in .Net.

The npm uses the package.json file to register the application information like dependencies, versions, name, etc..


Useful commands

  • npm init (Create the package.json file)
  • npm update (Update all packages satisfying the dependencies)
  • npm install package –save-dev (DevDependencies)
  • npm install package –save (Dependencies)
  • npm install –production (Only Install Dependencies)
  • npm install git+ (Install from GIT Https)
  • npm install git+ssh:// (Install from GIT SSH)

Differences between Dependencies and devDependencies?

Your Dependencies are the modules that your application needs to run and your devDependencies are modules just to development environment like test frameworks.

In production you should use (npm install –production) to install just the dependencies.

Use npm to run your scrips

In the package.json in the section “Scripts” it’s possible to define scripts. Npm already have some default scripts like start or test, check this list to see the default scripts.


To run the scripts you should use “run-script” after npm.

npm run-script YourScript

Node Inspector

Node inspector is a tool do debug NodeJs application, it’s really simple to use and the interface it’s similar to Chrome debugger.

First install the node inspector globally (-g)
npm install -g node-inspector

To debug your application you just need to run the command node-debug and specify the port (if you dont want to use the default) and the startup file.

node-debug – -web-port=9000 server.js

Node Inspector Interface



is an application performance monitoring and analytics service for NodeJs applications and it’s really easy to use.

You just need to register and follow the Installation Guide.

npm install nodetime

Node Time Interface


Leave a Reply

Your email address will not be published. Required fields are marked *

Connect with Facebook