Latest Node.js Recipes

How to expose all module classes through index.js in Node

I have a directory structure like this:

node_modules/mymodule/index.js :

module.exports = require('./lib/mymodule');


var A = require('./a'),

function MyModule(){
    var self = this;
    self.version =...

Read the entire recipe Recipe added 28 minutes ago

OS X editor (or IDE) that is really good for "node.js" development?

I'm an old Emacs user - I've used it for about 10years now. When I switched to Mac I started to use Aquamacs, which is great in many ways.

But now most my development work involves Node.js/Express.js (with JavaScript, Jade and Stylus). Unfortunately,...

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

Returned object is undefined, using dynamicHelpers

I've created an external file that's handling the dynamic helpers, which includes a bunch of functions that I want to be able to use from all my views.

In on of the functions I'm running a query and fetch tags from the database, which I want to use...

Read the entire recipe Recipe added 2 hours, 24 minutes ago doesn't set CORS header(s)

I know this question has been asked a couple of times.
However, I can't get any those solutions to work.
I'm running a standard install of node.js and (From yum on Amazon EC2)
The problem is that Chrome is falling back to xhr polling, and...

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

NodeJs get size of variable in bytes

I have a variable 'img' which is an image file that has been loaded via:

var img = fs.readFileSync('./tmp.png');

How do I determine how many bytes the 'img' variable is?

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

Node.js for() loop returning the same values at each loop

I'm making this really simple application to help me explore nodejs and I have a particular handler that generates HTML code based on the top10 messages in my database. The snippet I'm having problem with loops through the messages and call the...

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

How to handle sending out multiple http request in Node?

I have the standard code for sending out http request. Using http.globalAgent.

I set my maxSockets be 2500.

And then when I send out multiple requests at once, I get this error:


However, if I sent out the request after...

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

Node.js - concurrency writing and reading objects

Well, I've been looking for this topic but don't find it, so I'll ask you:

I need to write and read on an array on the server with frequency, so I decided to not using database, but I don't know what the best practice? It will be a lot of data, could...

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

Node.js project layout for build/test vs. Deployment

I'm working on my first Cloud Foundry project (...and first Node.js project, and first MongoDB project, and first "express" project, etc. etc...)

On day one I found this question, and used the answer as a jumping off point for the organization of my...

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

Exec : display stdout "live"

I have this simple script :

var exec = require('child_process').exec;

exec('coffee -cw', function(error, stdout, stderr) {

where I simply execute a command to compile a coffee-script file. But stdout...

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

Why are images not fully shown with my streaming app?

I've written a simple Node.js app that streams content (primarily for videos, but other stuff works too). It seems to work fine except with some jpegs, where the bottom of the image is not always displayed.

Here's an example, with the bottom portion...

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

How to read from a child_process line by line in Node.js?

I am trying to make a Node.js script to analyse disk usage. For this, I shell out to du, but I am having trouble figuring out how to read the output from the child process line by line. Here's what I've tried so far:

var spawn =...

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

Write to a CSV in Node.js

I am struggling to find a way to write data to a CSV in Node.js.

There are several CSV plugins available however they only 'write' to stdout. Ideally I want to write on a row-by-row basis using a loop.

Thanks in advance.

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

New line in node.js mailer template

I'm using node.js mailer module to send email from node server. I used template file for that but I got all spaces trimmed when the message was sent. I tried to add '\n' at the end line of the template but it doesn't work also. Here is an example of...

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

Building contextify under Windows 7 x64 (for NodeJS jQuery)

I try to get node-jquery working. contextify is one of the dependencies (required for jsdom).

contextify needs to be built somehow using Python. But this does not seem to work on Windows 7 x64. At least one my computer :)

After some readings (#10, ...

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

Check if a file is binary or ASCII with Node.js?

I'm wondering what would be the best way to check if a file is binary or ASCII with Node.js?

There appears to be two ways not specific to node.js:

  1. Checking the MIME type: How to Check if File is ASCII or Binary in PHP - however this has it's...

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

How can I get sharejs running with nodejs?

I'm having trouble with nodejs and sharejs. I am trying to use sharejs and have installed via npm. I can't seem to get it to load however. In my code all I have is the following:

var client = require('share').client;

when i call node...

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

Is sending HTTP POSTs to Django Web API via node.js efficient?

I've built a JSON API in Django. I'd like to send real-time updates from an external service to Django to upsert a model.

I am really looking for insight on the best way to design the system with current/upcoming/active frameworks and tools. My...

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

MongoDB findAndModify() adds query to update clause

I'm creating an application in Node that has some CRUD components. On one of my data objects, I have a save() method that is meant to update a record if the object has an id that is found in the collection, or upsert a new document if not....

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

using partials with express in node.js

I am trying to render partials using node.js. Here is my code.


  var express = require('express')
  , routes = require('./routes');

var app = module.exports = express.createServer();

// Configuration


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

Implementing a simple proxy server using node.js

I'm trying to create a simple node.js proxy server for experimental purposes and I came up with this simple script:

var url = require("url");
var http = require("http");
var https = require("https");

http.createServer(function (request, response) {

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

Use process.on('uncaughtException to show a 500 error page

I'm developing an express app.

I currently have the following in my server.js

process.on('uncaughtException', function (err) {
    console.log( "UNCAUGHT EXCEPTION " );
    console.log( "[Inside 'uncaughtException' event] " + err.stack ||...

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

Handling or prevent errors from crashing my whole node.js app on Heroku

I've got a node.js app hosted on Heroku

Whenever my app encounters an error, the whole server crashes, making it unavailable for anyone.

Is there any way to return an error page instead, and keep the server alive?

I read this, Node.JS with forever...

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

ExpressJS Get resulting source from view instead of rendering it

I'm intending to use some ejs templates to generate HTML for sending out emails.

I'd like to pass in a model to my view, and get back the resulting HTML So, instead of render() - i want to 'get' the html into a variable before it's passed back to the...

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

Accessing nodejs functions inside expressJs static HTML

I'm a Javascript and Nodejs newb and I'm not sure how to best organize things. I'm writing a web interface for a C++ application by using Nodejs and V8 convert to wrap a C++ API. The question I have is, is there some way I can use Express to serve...

Read the entire recipe Recipe added 1 day ago