Latest Node.js Recipes

Nodejs Event Loop

Are there internally two event loops in nodejs architecture?

  • libev/libuv
  • v8 javascript event loop

On an I/O request does node queue the request to libeio which in turn notifies the availability of data via events using libev and finally those...

Read the entire recipe Recipe added 20 minutes ago

How to render redis records in express.js?

I am new to node.js and express.js. I know this is a little bit silly, but I really don't know how to solve this problem. Hope there is someone can help me.

I have some information stored in Redis.

redis> hgetall "store1"

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

Differences between 'extends' in coffeescript and 'util.inherits' in node.js

I am learning Node.js recently. I have a question about the function util.inherits in Node.js. Can I use extends in coffeescript to replace it? If not, what are the differences between them?

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

how do i debug a node.js app using heroku foreman?

i am new to heroku and node.js. i have a small node.js app which i can start and run successfully on my local machine using FOREMAN from the heroku toolbelt. i do not understand how to best debug the app, though.

i see that there is an eclipse...

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

Saving node.js stream to mongodb - how to properly connect?

The script I am working with is here:

I want to modify some code to store a streaming, parsed message from a node.js app to a mongodb collection for later access. So far I am working with tutorial code and am confused...

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

Why doesn't my Node.js server reply with data?

I'm doing the tutorial here. I got everything working up until this point:

var http = require('http');

var server = http.createServer(function(req, res) {
  res.end('Hello Http'); 


When I run the...

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

Stop node.js process exiting when using process.on to listen for messages

The following trivial script exits immediately:

process.on('message', function () { });

What is the correct way to keep a node.js process running while listening for messages?

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

What is the point of using a proxy server such as node-http-proxy for a node app with a single app on one port?

I'm exploring using the node-http-proxy proxy server so that I can have our proxy server on port 80 forward requests to our app server on port 8000. However, I'm a little confused as to why this is a good idea, and what exactly this set up would...

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

Listen for changes in Redis?

I want to be able to run a callback when any change is made in my redis collection. The callback would take the key and value as inputs. Is something like this possible?


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

node.js runs concurrently, or does it?

Boys and girls,

i've been messing around with node.js today and I can't seem to reproduce this concurrent magic.

i wrote this rather small server:

var http = require("http");

var server = http.createServer(function(req, res) {


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

Return value from a mongodb call from nodejs

How do I return an array from a mongojs query. I have the below query executed with nodejs, into a locally running mongodb database. Mongojs is handling the transaction. My question is; how can I return an array from the below function call.


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

How to compare two fileStat.mtime in nodejs?

See the code:

var fs = require('fs');

var file = "e:/myfile.txt";

fs.stat(file, function(err, stat1) {
  fs.stat(file, function(err, stat2) {
    console.log(stat1.mtime == stat2.mtime);

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

Socket.IO on subdomains with Express.js vhost

I have two Express.js apps running on my server.

A plain vanilla app called "main-app" and another that uses Socket.IO called "socket-app".

I have "main-app" running at "" & "socket-app" running on a subdomain at ""


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

Package manager NPM and node.js Integrity

I have just created a new package on NPM (which was surprisingly easy) and I am interested in how the integrity of packages is maintained. Can anybody publish a new version of a package, or is this restricted to just my user account?

If anyone can...

Read the entire recipe Recipe added 13 hours, 16 minutes ago Identify User for Socket

I write some code example that identifi connected users via So now I must write a code on index page to comunicate with users.

The code is below and HOW to send a message to user[1] "Welcome" and for user[2] "HI men" and also limit...

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

Can I use node.js as a REPL shell?

This is a noob question.

I am trying to use node.js as a JavaScript REPL (read-evaluate-print loop) shell to work with JavaScript interactively. Unfortunately I can define neither variables nor functions.

 var x = 'abc'
 function f()...

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

Node.js shrinkwrapped package.json causes npm install to update new versions regardless

I've got a npm-shrinkwrap.json and a package.json in a git branch called "deployment".

On my servers, I fetch and merge this deployment branch from github. This ensures that my servers have the latest deployment version.

Because the node_modules...

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

What's the commonly accepted pattern for representing state in Node.js

For example in classic object oriented programming I might have a class School which has an array of String representing students (not the ideal data structure but for illustration purposes only). It might look something like this

class School {

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

Sending an array from websocket to clients

I'm having an issue sending an array from the backend js to the client side.

I've tried the following on the server side:

for (var i=0; i < clients.length; i++) {

for (var i=0; i < clients.length; i++) {

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

Why using $self in EventEmitter.prototype.once in node...?

I am looking at the implementation of once() in event.js:

EventEmitter.prototype.once = function(type, listener) {
  if ('function' !== typeof listener) {
    throw new Error('.once only takes instances of Function');

  var self = this;

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

Uploading a file programmatically, from node.js, to another web server

I need to push a file from a node.js app, to a web server running elsewhere, which accepts files via the typical upload mechanism. For instance, say the receiving server has a page with a form like this:

<form enctype="multipart/form-data"...

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

Node.js, restify and proper routing

I'm still wrapping my head around Node, but I have a very simple question. I see a lot of node examples where people are declaring their routes and all their logic in a single app.js file (or sometimes splitting them off into subfiles).

My question...

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

NodeJS everyauth get access token

I am trying to get the access_token for a user using the FB API + everyauth module for NodeJS, and then I will make serverside graph API requests using the Facebook_Graph_API module to actually make the requests (which requires an access...

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

How does Google Analytics avoid Spoofing?

So I'm stuck trying to figure out how Google Analytics avoids spoofing. Sure, when you sign up for an account, they make you verify that you own the domain by uploading a file. But you are also given some script tags with a unique public code...

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

Saving Images to S3 from External URL with Node.js and MongoDB

I'm trying to save the images from a third-party API to my own S3 bucket using Node.js and MongoDB. The API provides a URL to the image on the third-party servers. I've never done this before but I'm assuming I have to download the image to my own...

Read the entire recipe Recipe added 1 day ago