Latest node.js, npm, express and jade

I’ve been dabbling with these over the last few months and trying to make some time to use them in some new projects, but they’ve been making great strides recently and it has been hard to keep up with all the developments. I tried to update to node.js v0.5 but in the end got confused with the different mixes of versions between older projects. I’d had some problems installing some of the modules with various dependencies. I decided to start again with the latest on all fronts. It has shown me how different it has become. express has a guide here, but I just want to give you something simple. Using version 5 should be more compatible with the soon to be released v6, as well.

I’ve been working on a C# driver for node, on Windows, using 5.8 exe which is impressive, but in the following install I’m working on a Mac.

The node modules may now be held within the project directories, rather than centrally, which gives more flexible versioning and the projects are growing together to allow a variety of templating and css engines.

I installed the development version of node, to get the latest 5.10 version; found that I needed latest python27 upgrade as well (in for a penny…)
sudo port install nodejs-devel

and npm was installed to be similarly up to date,
curl | sudo sh

express now gives similar facilities to Rails and will create a working structure of directories and source code files when creating a new project. I next installed express, but globally, which puts the files at /opt/local/lib/node_modules/express

sudo npm install express -g

and did the same for the jade templating engine,

To create a project, just run express,

sudo express ./foo && cd foo

this will create the directory with all basic project files within it; jade is the default templating engine used. You can add a ‘-s stylus’ option to further add a css engine.

create : ./foo
create : ./foo/package.json
create : ./foo/app.js
create : ./foo/public
create : ./foo/routes
create : ./foo/routes/index.js
create : ./foo/views
create : ./foo/views/layout.jade
create : ./foo/views/index.jade
create : ./foo/public/javascripts
create : ./foo/public/images
create : ./foo/public/stylesheets
create : ./foo/public/stylesheets/style.css

We then need to run npm to bring in all the dependencies,
sudo npm install

express@2.5.0 ./node_modules/express
├── mime@1.2.4
├── mkdirp@0.0.7
├── connect@1.7.2
└── qs@0.3.1
jade@0.16.4 ./node_modules/jade
├── mkdirp@0.0.7
└── commander@0.2.1

The result is a well structured set of files, built-in session and cookie features and a single command to change easily from development to production (or other) configurations. There is an app.js file that node will use to give the basic site.

One module that I always bring in on the first test is nodemon. It monitors the files in your project. If any changes/edits are gone it restarts the node server. Excellent; it saves so much time, thanks Remy.

I also took some help and inspiration from this url,

Next, I shall probably have a look at zepto.js, the mini-jQuery lookalike for mobiles and the Raphael javascript graphics library which have now released a new 2.0 version.


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s