Setting NODE_PATH on Windows

If your getting errors like ‘cannot find module x’ when trying to start a nodejs server on windows then you probably have some code which is looking for node modules but they are not being found. This could be a number of reasons but node will look in the default folders for the module and …

npm install error

I have no idea why the install of npm is failing. There is nothing online about this error so here it is. “AgentSSL.prototype.addRequest” -> “TypeError: Cannot read property ‘prototype’ of undefined”. I’ve tried to install npm using the following with no luck (as suggested). curl https://npmjs.org/install.sh | sh curl https://npmjs.org/install.sh | sudo sh git clone …

Node.js Get the Curent URL and Params

In your server code use the following to display the current URL and params. // API / GET exports.get = function( req, res ) {      var fullUrl = req.protocol + ‘://’ + req.get(’host’) + req.originalUrl;      res.send(fullUrl);      return true; } Or you can display the headers of the request like …

NODEJS COMMAND Shorthands

Official NODEJS COMMAND Shorthands. I found these when taking a look at the utils source code. Lovin the -gangsta one haha! exports . shorthands =    { s : [ "–loglevel" , "silent" ]    , d : [ "–loglevel" , "info" ]    , dd : [ "–loglevel" , "verbose" ]    , ddd …

cannot find module ‘jsdom’

An error I came across when trying to install jsdom npm package on my windows machine. “cannot find module ‘jsdom’. Solutions: 1. Follow instructions on this blog post to get jsdom working on windows. http://www.steveworkman.com/node-js/2012/installing-jsdom-on-windows/ 2. Use an alternative (lighter) package called Cheerio. Notes: Something I ran into was this error when using cheerio. “cheerio …

Node.js Silence Middleware Output When Testing

So I wanted to have the console output of my tests clean and not polluted by node app middleware output, such as that output by request modules when performing http requests. I remember briefly touching on this subject before when Silencing Log Output when testing. This is what the output looks like when I run …

Mocha Test JSON Schema is Valid

OK so it’s important to test your JavaScript applications especially in full-stack JS. I’ve touched on this subject before when I wanted to test if JSON was returned in a valid format. So let’s take this a bit further and look at how you can use Mocha to test your JSON Schema is valid (how …

Mocha Test Silence Log Output

When testing my server I have log output which I don’t want to appear when I run my tests using Mocha. I want to Silence Log Output!!! Ofcourse a solution is suggested by TJ! Let’s take a look… OK, so include this in your server.js file. // api middleware if (process.env.NODE_ENV !== ‘test’) {   …

Nodejs Mocha Test for Valid JSON

Mocha This is how you can use the Node.js test suite Mocha to Test for Valid JSON. This could come in handy when testing if API’s are returning valid JSON – essential part of your web application integration testing. Note: I’ve taken this testing concept further and added tests for JSON Schema as well. See …

How to completely Uninstall node.js on Ubuntu

For some reason or another you want to uninstall node.js. This can depend on how you installed node.js in the first place but here are a couple of methods which you can use to uninstall node.js complete from Ubuntu Linux. Uninstall node.js on Ubuntu – Method 1 Check where your node is installed. which node …