Latest Node.js Recipes

How to use browser libraries such as jquery, three.js and processing.js on browserify?

Is it possible to use libraries such as jquery.js, processing.js and three.js on browserify, so I can completely stop using HTML to require my client libs?

Read the entire recipe Recipe added 37 minutes ago

Is there any online exercises on Node.js

I'm new at Node.js and i need some practice on it, so is there any online exercises same as for node.js?

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

Render array passed from Express with Jade

Most of the questions pertaining to this all seem to be about passing the server-side JS object into a client-side JS object. Maybe I'm missing something, but all I want to do is render HTML using the server-side JS object.

On the server:


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

Redirecting output to a log file using node.js

I have a child process that I am using as follows in node.js. Instead of redirecting the output to the console I would like to put the output in a log file located somewhere on the machine this is running on (and should work for both windows and...

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

Try to get image from wikipedia and serve it in node.js

I am trying to make a webserver in node.js that downloads an image from Wikipedia and servers it on a page. I cant get it to work. I pasted my code in an online sandbox:

Heres my code:

var http =...

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

Passing arguments to a Nodejs Module using a C++ wrapper?

I am trying to develop a better understanding of the technology required to develop Nodejs modules that use a C++ wrapper. I am working through as much information I can find, for example Nodejs Documentation. To push my understanding I set the...

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

Inside Express/EJS templates, what is cleanest way to loop through an array?

I have an Express.js app set up using EJS templates. I successfully looped through an array with classic JS syntax:

<% for (var i = 0; i < myArray.length; i++) { 
    this = myArray[i];
    // display properties of this
} %>

But I'm wondering, is...

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

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 7 hours, 41 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 8 hours, 40 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 9 hours, 37 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 10 hours, 36 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 11 hours, 35 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 12 hours, 42 minutes ago

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

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 13 hours, 40 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 14 hours, 36 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 15 hours, 41 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 16 hours, 37 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 17 hours, 38 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 18 hours, 34 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 19 hours, 35 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 20 hours, 35 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 21 hours, 40 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 22 hours, 42 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 23 hours, 38 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 1 day ago