Home

Updating an Old Node.js Project

By Morgan Conrad

Intro

My first "serious" NodeJS application, NextQ, a site to search for upcoming Dog Agility Trials, has been sputtering along for several years. Not much used, but it's been reasonably reliable. It was hosted on OpenShift Online 2, which hosted both the Node code and the MongoDB. In September I started getting emails that OpenShift 2 was in "sunset" mode and I should upgrade to OpenShift 3. While I was at it, may as well update the application. That part proved to be fairly simple.


Updating the Application

NPM has a nice command, npm outdated, to see how up to date are your current modules in package.json. My results were:

> npm outdated
Package          Current  Wanted      Latest  Location
body-parser       1.15.0  1.15.2      1.17.2  nextq.info
cheerio           0.20.0  0.20.0  1.0.0-rc.2  nextq.info
compression        1.6.1   1.6.2       1.7.0  nextq.info
errorhandler       1.4.3   1.4.3       1.5.0  nextq.info
express           4.13.4  4.13.4      4.15.4  nextq.info
express-session   1.13.0  1.13.0      1.15.5  nextq.info
method-override    2.3.5   2.3.9       2.3.9  nextq.info
mocha             1.14.0  1.14.0       3.5.0  nextq.info
mongodb           2.1.16  2.1.21      2.2.31  nextq.info
morgan             1.7.0   1.7.0       1.8.2  nextq.info
multer             1.1.0   1.1.0       1.3.0  nextq.info
request           2.71.0  2.71.0      2.81.0  nextq.info
serve-favicon      2.3.0   2.3.2       2.4.3  nextq.info
xmldoc             0.4.0   0.4.0       1.1.0  nextq.info

As you can see, many were way out of date. The above list doesn't include Jade, which was at 1.11.0. It's successor, renamed to pug, was at 2.0.0-rc.4 I decided not to update Jade nor cheerio to "release candidate" versions, especially of major semantic revisions. I'm not using any fancy features of most of these packages, but let'snot push it.

Not sure if there is an automatic way to tell npm to update most but not all of package.json, and it was simplest to do some manual editing of package.json. Then run npm update and everything looks good.

As a relative newbie to JavaScript and Node, I use the WebStorm IDE for much of the development. Did a minor update of it from 2016.3.3 to 2016.3.4. There's newer versions but they require a new download, not a patch, so ignored them. Somewhat to my surprise, everything ran fine with WebStorm on localhost. There were three deprecation warnings, all in the same file in nearby lines.

...express deprecated req.param(name, default): Use req.params, req.body, or req.query instead at orgs\UKI.js:108:64

I liked having the "default" parameter in the function call, but easy enough to change to req.params.something || ''. Everything continued to run fine. In "local" mode, the app connects to a small mLab copy of my small MongoDB DB.


Updating OpenShift to V3

This part had more hassles. First you login to OpenShift Online 3 Starter (starter == free). Since I already had a RedHat account, no hassle. Had to add my Name and Location, then select a server location (California). It took quite a while while "Your account is being provisioned". I had to hit refresh and login again to get to the console.

Your new project has a "name" and a "display name". Seems like overkill to me, and at this stage who knows where there is any difference? Picked same name, nextq, for both, and gave a brief description.