Node.js Cheatsheet

I am learning about node.js. This is my cheatsheet. It may not be useful to you at all.

Also see My JavaScript Cheatsheet.

Documentation

Installation

  • Downloadable installers: http://nodejs.org/download/
  • Installing via various package managers: https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager
  • Source code: https://github.com/joyent/node

Debugging

Utilities

  • npm - package manager for Node
  • supervisor - automatically restarts Node-based server when files change
  • nodemon - automatically restarts Node-based server when files change
  • forever - ensures that a script runs continuously
  • Winser - runs Node as a Windows service, using nssm
  • docco and docco-husky - documentation generator
  • node-inspector - browser-based debugging interface

Modules

These libraries are especially useful (to me, for what I have done):

  • Express - web application framework
  • Connect - middleware framework
  • Jade - template engine
  • Socket.IO - support for WebSockets and other connection mechanisms
  • Request - simplified HTTP requests
  • xml2js - simple XML-to-JavaScript converter
  • nconf - configuration files
  • PDFKit - PDF generation
  • Backbone - client-side data models, views, UI binding
  • Underscore - functional programming helper library
  • Async.js - asynchronous JavaScript
  • Q.js - asynchronous promises
  • Mocha - testing framework
  • should.js - BDD-style assertion library
  • Chai - BDD- and TDD-style assertion library

See https://npmjs.org for a complete list of all available modules.

Creating a New Web App with the Express Framework

If you don't already have the Express framework installed, do this:

npm install -g express

To create a new app, do this:

express --sessions MyNewApp
cd MyNewApp
npm install

To run the app:

cd MyNewApp
node app

By default, the app will listen for requests on port 3000, so you can browse to http://locahost:3000/ to view the app. Modify app.js or set the PORT environment variable to use a different port.

Snippets

© 2003-2023 Kristopher Johnson