Tag: node.js
-
Stubbing middleware when testing an Express with Supertest
When testing a simple express app / api I like to use supertest. This can feel like integration testing, and to an extent it is. But we can stub things out with sinon, and tidy up our tests. Let’s look at an example. Suppose we have a simple API with the following router: var express…
-
Transparent proxy from node.js app to WordPress for /blog route
For a recent car wash directory start up I have created, I wanted a blog. GetCarClean uses node.js; While there are node blogging platforms, what I really wanted to do, was proxy /blog of my main site, to a WordPress site (actually hosted on a subdomain – blog.<domain>.com) What I did, was to set up…
-
Introducing mongoose-status-manager – status updates for mongoose models
For a project I’m currently working on, I needed to be able to update the status of a document. For example, let’s assume it’s an Order. I need to create it, then set it’s status to ‘Pending’ When the Payment is completed, I need to set it to ‘Paid’ Then, as the order progresses, I…
-
How to assert.throws on an async function with a callback
Recently, I was writing a module that took a callback, and needed to write a test, asserting on an exception. Here’s how to do it: it(‘throws error if myParam is less than 10’, function(done) { var fn = function(){ myModule.doSomething(8, function(err) { if (err) throw err }); } assert.throws( function() { fn() }, /Value is…
-
Create a standalone EXE to run a Node.js application
Download Advanced BAT to EXE converter (http://www.battoexeconverter.com/) Download Node.exe from Joyent http://nodejs.org/dist/v0.8.2/node.exe Now we’re ready to bundle the node.js executable and our js files into a single exe file. As for our BAT command, all we need is: CD %MYFILES%/ node test.js %MYFILES% is the variable given to the location of embedded files (more on…
-
Node RailwayJS app – Deploying to Heroku – ENOENT, open ‘/app/log/production.log
I’m currently working on a project involving a node.js app, using RailwayJS, deploying to Heroku. After doing my git push Heroku Everything seemed ok, however, the app was not running. I ran Heroku logs and was shown: app[web.1]: listening on port 32168 within production environment app[web.1]: app[web.1]: events.js:48 app[web.1]: throw arguments[1]; // Unhandled ‘error’ event…
-
Running node.js on Windows
Download node.exe http://nodejs.org/#download At the time of writing, the version was v0.5.4 (unstable) Don’t worry about it being unstable, you wouldn’t dream of running it on Windows in production, would you Put it somewhere sensible For me, I have node.exe on the root of C:\ Some people have a subfolder, such as “tools” where they’ve…