Generating Express scaffolding
Express works both as a Node module and as a command-line executable. The express-generator
module (part of the Express project) provides an easy way to generate a project skeleton using its command-line tool (express
).
Getting ready
We need to install express-generator
using the -g
flag (install globally) in order to run the subsequently installed express
executable from any directory:
sudo npm -g install express-generator
We use sudo
to ensure that we have appropriate permission to install globally. This doesn't apply with Windows or Mac OS X, so it should be run without sudo
.
How to do it...
First, we decide upon the name of our app. Let's call it nca
(Node Cookbook App) and simply run the following command:
express nca
The preceding command 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 at nca/package.json
. The package.json
file...