Mike Valstar

Web Development, Programming, Random Thoughts

Twitter Status...

Coding with Node.js: Part 7; Upgrading to Express 3.x and Mongoose 3.x

Posted on

See Coding with Node.js: Part 1; Getting started with Express. for the beginning of this tutorial series.

Node is a fast moving technology, and so to this applies to the libraries and tools. since I started this blog Node has been upgraded from 6.0 to 8.12, and express has migrated from 2.5.0 to 3.0.0 and mongoose is now at 3.2 as well.

Upgrading Express to 3.0.0

Express in 3.0.0 has added and removed quite a few things. you can read more here: https://github.com/visionmedia/express/wiki/Migrating-from-2.x-to-3.x

For the purposes of this project the major changes come in 3 places:

app.js

Express has been changed to break out the http server from the main express itself as a separate module; thus changing slightly how we interact with express, but not overly effecting this blog.

In addition Express has added a nice built in log for development purposes.

And lastly they have added in a new prefered method of setting the port.

ErrorHandler.js

The error handler is mainly affected by the removal of the status option from res.render() to it’s own call.

View file

Templates (all of them)

Finally all of our templates need to be updated, express no longer renders a layout.jade file then inserts your “content”. The new method uses jade’s “extend” and “block” functionallity

layout.jade

Replace != body

block content

All other templates

Add to the top:

extends layout
block content

Upgrading Mongoose to 3.2

Mongoose in reference to this application has only had one change that I have been able to find; and that is in reference to how you sort your queries.

Old Way:

blogpost.find().sort("sid", -1)

New Way:

blogpost.find().sort(“-sid")

A subtle differnce, butenough tomake your application no longer work.

The Code

All code created for this website is available on the github page page and this tutorial specifically is available here: Tag: NodeTutorial_pt7

Sorry for the massive change, I converted the project from tabs to spaces for indenting. You can see a diff of all the changes here: Commit: 37986074d43d2194f8e6c5f3234e9a7f1c88ede4

Next Time

Shortly I’ll be releasing some information about the site redesign. After that I plan on adding a site search.

bp_113
comments powered by Disqus
Mike Valstar © 2012