Generating Express scaffolding
Express works both as a Node module and as a command-line executable. When we run express
from the command line it generates a project skeleton for us, accelerating the preparation process.
Getting ready
We need to install express
using the -g
flag (install globally) in order to run the express
executable from any directory.
sudo npm -g install express
We use sudo
to ensure we get permission to install globally. This doesn't apply under Windows.
How to do it...
First, we decide upon the name of our app. Let's call it nca
(Node Cookbook App) and simply do:
express nca
This will generate all of our project files under a new directory called nca
. Before we can run our app, we must ensure that all dependencies are installed. We can find app dependencies in nca/package.json:
{
"name": "application-name"
, "version": "0.0.1"
, "private": true
, "dependencies": {
"express": "2.5.8"
, "jade": ">= 0.0.1"
}
}
For portability, it's important to have relevant modules...