Latest Node.js Recipes

Streaming's public stream with node js

I'm new to this streaming/http long living connection stuff.

This is what I got so far:

var accessToken = require('./config.js').accessToken
  , https = require('https')

var req = https.request({
      host: '',

Read the entire recipe Recipe added 13 minutes ago

Nodejs Server Hostname

Ok, so it seems pretty easy in Node.js to get the hostname of the request being made to my server:

app.get('/', function(req,res){

Is there an easy way to determine the hostname of my actual http server? For...

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

Node.js: Running example of Chat?

Trying to setup an example for node.js chat on Windows x64.

Command line:

D:\Websites\dev\chat>node server.js
Server at

Now when server part runs, trying http://dev/chat/index.html

After submitting Name, it gives me "error...

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

is there anything like nodemon that will restart a node app when .ejs file changes?

is there anything like nodemon that works on .ejs file changes?

nodemon will detect changes in .js or .coffee files and restart your node app. But it won't detect changes to view files. I've emailed author, but they are unresponsive.

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

Stylus, NodeJS and Nodemon

im using stylus to my nodejs application (not express, just plain node). Im also using nodemon to monitor changes and apply them without restarting my app. I have a little sh script that runs my app:


if [ -f style/*styl ]; then

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

how to recover from duplicate key in mongoose + express

I've created a signup form using mongoose and express 3

Its possible the user already exists with that username, in which case I get an err.code 11000 (duplicate key). How should I handle existing users?

This is what I'm doing now....but I'm not...

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

Should I be using for my nodejs application?

I am learning HTML5 and doing so by building a simple chatroom using Express, PassportJS, Mongoose/MongoDB, connect-mongoose, NowJS.

Everything works perfectly, except for one big problem: I am having trouble authenticating NowJS.

The usual way of...

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

in node.js, how to forward all events of module to another

Say I am creating my own module, which sits on top of the 'net' module. My module has its own events, but also allows clients to listen on network events emitted by the tcp connection:

mymod.on('myevent',...); // my event
mymod.on('connect',...); //...

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

nodejs request.header dosnt exists

Saw lot ot tutorials, articles and stackoverflow questions about getting the client IP address from NodeJS. Almost all of them use this request.header('x-forwarded-for') My NodeJS v0.8.7 doesnt have that request.header function.

typeof request.header...

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

How can I handle async calls when validating with Backbone.js (uniqueness specifically)

This is relevant for either client or server side apps using backbone. I am attempting to create a validation function with uniqueness checks to MongoDB or some REST call (depending on environment). Both of these calls are async by nature; however, I...

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

Distributed pub/sub with single consumer per message type

I have no clue if it's better to ask this here, or over on Programmers.SE, so if I have this wrong, please migrate.

First, a bit about what I'm trying to implement. I have a node.js application that takes messages from one source (a

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

Phantomjs does not execute function in page.evaluate function

I'm scraping a Facebook page with the PhantomJS node module (, but when I try evaluating the page, it does not evaluate the function I pass to it. Executing it in a standalone script and running it with the...

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

Node.JS notifications on my PHP based website

I am developing a website in PHP. Now, I would like to simply add a notification system. Imagine it like Facebook friendships: when I get a friend request, I get a notification too.

I of course know a bit of Node.JS and Socket.IO, but the tricky part...

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

return values with async function in nodejs

I have this function:

exports.readPartial = function(html, values, response) {
  fs.readFile(__dirname + "/../html/partials/" + html, function(error, file) {
  if(error) { this.loadError(response, error); }
  else {
   console.log("\t--> partial...

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

Invoking async.series inside async.series produces unpredictable output

Using caolan's async library for node.js, I've been trying to call a function that uses async.series inside another function that uses async.series, but I still can't get the functions to run in the correct order, as detailed below:

The terminal...

Read the entire recipe Recipe added 14 hours, 7 minutes ago on method callback


socket.on('adduser', username, successcallback){


} else {

    socket.username = username;

    users[username] = { name: username };

    socket.emit('updatechat', 'SERVER', 'you have connected');


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

node.js code protection - how to cause a node.js deployment to be recoverable only in V8 assembler

Let's suppose that for some particular reason, I want a robust node.js code protection, i.e. to force a node.js deployment with javascript source code to only be analyzable via v8 assembler language entirely, making it painfully difficult / almost...

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

Testing asynchronous mongodb calls in nodejs with jasmine-node

I am using jasmine-node to run tests against my nodejs functions. Being new to nodejs and mongodb, the first thing i ran into was testing some database calls, and I immediately got stuck, due to the asynchronous nature of nodejs.

What I want to do...

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

WebStorm: HTTP server options locally and cross platform

I have just downloaded WebStorm 5.0 for testing with AngularJS, and I have a problem. I can't seem to figure out how to configure or add a server for my HTTP files.

I am currently using a Windows 7 PC but I am also using a Mac.

I would like to know...

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

Cross-domain Update from Sencha Touch 2 to external server

Trying to create a Sencha-Touch-2 app syncing to a Node.js server; code below. The server uses another port on the same IP, so this is cross-domain. (The server uses Mongoose to talk to a MongoDB back-end (not shown))

  • Using a JSONP Proxy as shown...

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

Are databases attached to dynos in heroku?

I want to try out heroku, but am not quite sure if I understand all terms correctly.

I have an app with node.js and redis & my main focus is scaling and speed.

In a traditional environment I would have two servers in front of a load balancer; both...

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

console.log not working with nodejs project?

This is regarding the following small demo project:

Has a console.log in it (line 32 of chat.js) that I can never trigger. I also cannot get any other console.log to output...

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

NodeJS: unwatching a file and specifying a listener

I am using fs.watchfile(); in NodeJS somewhat like the documentation example:

fs.watchFile('message.text', function (curr, prev) {});

When I use a listener:

fs.watchFile('message.text', function (curr, prev) {}, listener);

And unwatch the...

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

ExpressJS 3.0 How to pass res.locals to a jade view?

I want to display a flash message after a user fails to sign in but I just can't get the variables to show up in my Jade views.

I have some pieces, I know I have to use this in my app.configure():

    app.use (req, res, next) ->

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

Passing messages between servers with nodejs

I'm researching ways to pass messages between node.js server.

I was thinking about using But is now dead. What are some alternatives to Preferably the alternatives would be in node userland to keep things simple.


Read the entire recipe Recipe added 1 day ago