Latest Node.js Recipes

Easy and quick way to jump into node.js library from command line?

I'm trying build up good habits and a robust understanding of node/javascript.

Great answers to questions often come from Stackoverflow-ers who have taken time to look closely at the source code. (No surprise there, right?)

So, I'm getting myself...

Read the entire recipe Recipe added 54 minutes ago

How can I detect whether a server is connected?

I am developing an app using and appjs. I am having trouble giving a notice to the user when he causes EADDRINUSE by starting two instances of the app, which he is not supposed to. does detect EADDRINUSE, but I only receive a...

Read the entire recipe Recipe added 1 hour, 53 minutes ago

docpad: Where is the preview node server serving files from?

When I run docpad run docpad would run a preview node server defaulting at port 9778. If I navigate to localhost:9778 I would see the site as being served from the out directory.

But if I delete a file now from the out directory, say the...

Read the entire recipe Recipe added 2 hours, 49 minutes ago

npm throws error without sudo

I just installed node and npm through the package on and whenever I try to search or install something with npm it throws the following error, unless I sudo the command. I have a feeling this is a permissions issue? I am already the...

Read the entire recipe Recipe added 3 hours, 49 minutes ago

Callback get function in combination with a event-driven design

I want to make an API(node.js) with a get function. The module I use supports a write, and all incoming data is emitted by an event which I can subscribe too. The underlying system is based on polling.

But I also want to add pollers that write (using...

Read the entire recipe Recipe added 4 hours, 48 minutes ago

Using Node.js to connect to a REST API

Is it sensible to use Node.js to write a stand alone app that will connect two REST API's?

One end will be a POS - Point of sale - system

The other will be a hosted eCommerce platform

There will be a minimal interface for configuration of the...

Read the entire recipe Recipe added 5 hours, 54 minutes ago

How to correct the "connection.readyState" of mongoose on test cases from "connecting" to "connected"?

I have created a model of users(registration) in mongoose. This model is accessed from test case created in mocha as well as register form from front end. The new user can be saved from register form through front end, but the test case written in...

Read the entire recipe Recipe added 6 hours, 53 minutes ago

Cannot find module child-process

"child-process" should be a built in node library. However, when I type "require('child-process') in the node shell, I get the error: "Cannot find module 'child-process'". Any ideas why this might be happening?

Read the entire recipe Recipe added 7 hours, 48 minutes ago

What's the right way to create error messages that get returned in an Express request?

I have a function called a that accepts a callback, which is invoked with an error if there is one.

a is invoked in an Express route request. If there is an error, the error should be the response of the request.

function a(cb) {

Read the entire recipe Recipe added 8 hours, 54 minutes ago

How to send response to a client from node.js custom server

I am using Node-Soap library to call a external web-serivce from my node.js server, code is as shown below:

var http = require("http");
var soap = require("soap");
var url = '';
var args =...

Read the entire recipe Recipe added 9 hours, 49 minutes ago

How to run a callback when all running in parallel function done their job?

I got stack with the question: "How to run a callback after all async functions done their job"

Here an example:

function doTasks(**callback**) {
   doTask1(function() {

   doTask2(function() {

I do not want to run...

Read the entire recipe Recipe added 10 hours, 51 minutes ago

node-amqp cannot send message to RabbitMQ

I'm tring rabbitmq-tutorials, ruby version works fine, but node.js version cannot send message. I do not know what is wrong.

var amqp       = require('amqp');
var amqp_hacks = require('./amqp-hacks');

var connection = amqp.createConnection({host:...

Read the entire recipe Recipe added 11 hours, 47 minutes ago

Mocha tests with extra options or parameters

I am writing test cases for my Node.js application using Mocha. The test cases need an API key as an extra input option or parameter. The API key is private, so I don't want to include it directly in the test files as everyone then can see it on...

Read the entire recipe Recipe added 12 hours, 48 minutes ago

Do i need to install crypto module from npm?

I am making use of crypto module in my app. It seems like there is crypto module distributed in nodejs so do i need to do npm install crypto? what is the difference from and nodejs...

Read the entire recipe Recipe added 13 hours, 48 minutes ago

Regular expression for float

I am checking flaot value using this regular expression

var re = /^\d{1,5}\.\d{1}$/;

But it currently checks value which have only decimal and not allowing interger, can i modify this expression tho accept both integer and float


Read the entire recipe Recipe added 14 hours, 53 minutes ago

Websocket proxy using nginx does not work with tomcat.

I am trying to proxy websocket to port 80 using nginx. We have a tomcat application running on port 8080 and the node application running on port 8888. I have been trying to proxy them to port 80 using nginx but for some reason the connection isn't...

Read the entire recipe Recipe added 15 hours, 55 minutes ago

node.js + express: `sendfile` to Ajax request giving a 404

Node noob here. :) I'm making an Ajax request with the code

var path = "/path/to/file.html";

$.get(path, function(data) {

and on the server side, responding with

app.use( +...

Read the entire recipe Recipe added 16 hours, 50 minutes ago

Not allowed to load local resource using expressjs

I am trying to load an image file from a string (the filename) inside of a text file:

var rs = fs.createReadStream(path.resolve(thisItem));

rs.on("data", function(data) {
if (data) {
lines +=...

Read the entire recipe Recipe added 17 hours, 48 minutes ago

How to configure express.js's `app.use(express.static(...)`?

I'm using express.js's app.use(express.static(...)) to serve my files. I'd like to configure some restricted files and make routings (such as redirecting requests ending in .png to a specific folder). Is this possible?

Read the entire recipe Recipe added 18 hours, 51 minutes ago

Serving static files from Node.js

I'm trying to serve static files from Node.js the only problem I'm having, is if I keep going into sub paths, like so:


Then I have to step up the same amount of times, like...

Read the entire recipe Recipe added 19 hours, 52 minutes ago

Configure file missing for node.js v.0.8

I just fetched node with wget from

I ran sudo tar -zxf node-v0.8.11-linux-x86.tar.gz and then cd'ed into node-v0.8.11-linux-x86. However the Configure file is not there, so when I run...

Read the entire recipe Recipe added 20 hours, 47 minutes ago

How to convert a CSS selector to XPath in Javascript?

I'm looking for the equivalent of Nokogiri::CSS.xpath_for().

I found css2xpath however the result from Nokogiri actually works, while css2xpath returns a selector that doesn't.

The result I'm looking for would be something like this: = ["//div[@id =...

Read the entire recipe Recipe added 21 hours, 54 minutes ago

How to specify credentials username/password for elasticjs client?

Where can we specify username and password for the elasticjs ( client?

Read the entire recipe Recipe added 22 hours, 54 minutes ago

Javascript - functions on functions?

I've recently used a nice library for node.js called Kue.
I wanted to get some better understanding of what's going so I started reading the code...

I stumbled on to a piece of code and my mind went "WTF!!?!@$@!$"...
This is the code:


Read the entire recipe Recipe added 23 hours, 54 minutes ago

MongoDB merge one field into existing collection with Map/Reduce

I have a MongoDB database with 2 collections:

  • groups: { group_slug, members }
  • users: { id, display name, groups }

All changes to groups are done by changing the members array of the group to include the users ids.

I want to sync these changes...

Read the entire recipe Recipe added 1 day ago