Latest Node.js Recipes

Using curl with node.js to download an image and convert it to base64

I need to download an image from an external server and push it to my clients dynamically.

The external server is using SSL and basic authentication. After spending hours trying to use the 'request' and 'restler' modules, I gave up and settled for...

Read the entire recipe Recipe added 4 minutes ago

Throwing exceptions: Node.js vs Gevent

Someone at a meetup yesterday told me that if a callback throws an exception in Node.js, it will crash the entire process. But if a greenlet throws an uncaught exception in Gevent, it only crashes the greenlet.

I don't have experience with Gevent,...

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

Can we monitor with Node.js whether MySQL replication has been successful?

We are building a Node.js application that is connected to a MySQL database. The main purpose of this application is to manage a sport event; manage the entries, draw, results, etc. We host this application at a hosting provider(the global instance),...

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

nodejs/express and binary data in POST

I'm trying to send binary data to an express app. It works fine, as long as my values are smaller than 0x80. If a single value is 0x80 or greater, it messes up the whole buffer.

Express Handler:

binary = require('binary');

exports.api =...

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

NodeJS throw new TypeError

When i try to run my JS file i get this error:

    throw new TypeError('first argument must be a string or Buffer');

I was following this tutorial which didn't seem to mention the problem Tutorial Link

My JS file has:

var http =...

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

Traverse '__dirname' in Node.js Application

I'm trying to get the parent of the current __dirname in my node application.

Here is my current line of code:

 mu.root = __dirname + '/theme';

Yet, I want to reach out of the current directory and into another one of it's sibilings.

Here is my...

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

HAProxy + Node.js & Express not forwarding IP address

I'm trying to get HAProxy to pass the user's IP address by using:

option forwardfor 

In my haproxy.cnf

But for some reason my express returns no IP address. This is the code I'm using in Node.js:

    var usrIP = "0";

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

Is it possible to break into interactive mode in Node.js?

If you run node you get into interactive mode, you can inspect, execute functions etc. But once you run a function from interactive mode or from the OS shell, can you pause execution and go to interactive mode deliberately?

In browser you can use...

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

Update: USER ERROR - TYPO !! grunt-contrib-coffee error finding file & writing to destination

In my Gruntfile.js I have the coffee task configured as so and one file exists in the src/ directory:

coffee: {
    dist: {
        files: [{
            /* FIX: exapand: true, */
            expand: true,
            cwd: 'src/',

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

I need a Nodejs scheduler that allows for tasks at different intervals

I am looking for a node job schedule that will allow me to schedule a number of tasks at different intervals. For instance,

  • call function A every 30 seconds
  • call function B every 60 seconds
  • call function C every 7 days

I also want to be able to...

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

Caching a prototype function doesn't cache the object it belongs to

In Javascript I'm trying to make an array of functions to be executed by Async.series.


function Field(name, height, width) { = name;
   this.height = height;
   this.width = width;

Field.prototype.doSomething =...

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

Unable to Add Android Platform - ETIMEDOUT error while downloading Template

I am getting ETIMEDOUT error while adding a platform android to an existing cordova project.

I have NPM HTTP and HTTPS proxy configured correct (I installed cordova that way).

But when doing cordova platform add android I am getting ETIMEDOUT...

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

unit testing node modules with mocha, module variables acting strange

ill get right to business with some code:

var from = require('fromjs'),
    fs = require('fs');

var defaultBasePath = 'lib/hangman/wordlists';
var filePaths = [];

function init(basePath) {
    basePath = basePath ||...

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

Send Json to nodejs server

I develop an app with a REST nodejs server and a JavaScript / Zepto client.

I'm trying to send an json string from my client to my server

here is the client code:

    type: 'POST',
    url: 'http://localhost:3000/request',

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

Rules for Require in Nodejs

Recently im working on new Nodejs project and find some codes like this :

function a(){
   var http = require('http');
   var fs = require('fs');

function b(){
   var path = require('path');
   var http = require('http');

function c(){
  var fs...

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

Node js + PhantomJs: send data to page.evaluate

How can I send variable from server to page.evaluate ?

var test = 'Lorem Ipsum';

phantom = require('phantom')
        ph.createPage(function(page) {
  "", function(status) {

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

Setting TTL/Expires on object using Mongoose/Node.js


Actually after further investigation it seems that MogoDB is only holding the most recent 7 records, is this to do with the way i am sending the objects to mongoose, is it overwriting them?

I removed all reference to TTL/Timeout and i only...

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

express3-handlebars and 18next-node - internationalisation based on page?

my first question here - please go easy. I'm using express, express3-handlebars and i18next-node with node.js

The plan is to work with a different translation namespace depending on which view (i.e. which handlebars file) is currently being served....

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

Node RESTful API testing

I have a RESTful API server running as a back-end to my system and I was wondering what was the best way to test it. The solution I'm looking for is a set-up where tests would interface with the real database populated via fixtures (as opposed to...

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

How to config.get() a project variable into a task's initConfig in Grunt?

In Grunt, I have a custom multitask that extracts paths from an HTML file and uses grunt.config.set() to add those found paths to an array on the config called "pathsfound".

I want to use grunt.config.get() to access those paths so that I can use...

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

Stop the auto migration of the schema in the sails.js

In sails.js, how can we stop the automigration of the schema into the database. Sometimes,it gives error due to the migration. Is there a way that we can make the migration run only when the application is deployed?

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

Using jQuery as a dev tool

I have a lot of static pages that I want to edit in some uniform manner, rename or adding classes for example. Now, jQuery allows me to do such operations in a manner that I'm very familiar with, but on the client side. Now I would like to do this in...

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

Cannot install npm package anymore

I'm a bit desperate right now. I started using npm as well as grunt to improve my development workflow. Everything worked well until today. Suddenly it is no longer possible to install npm-packages. I always got the following error message:

0 info it...

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

Efficient and async way to check if at least one element of an array is also an element of another array

I want to determine if one array has at least one element that is also contained in another array.

For instantce:

arr0 = [0]
arr1 = [1,2,3]
arr2 = [2,3,4]
arr3 = [1,5,3]

arrCompare(arr0, arr1) // false
arrCompare(arr1, arr2) //...

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

How can one connect to an abstract namespace unix family address in nodejs?

Has anybody tried to connect to an abstract namespace path (which starts with a null character) on unix family addresses in nodejs? The problem seems to be that node internally sets the encoding of the path to ascii and consequently converts '\0' to...

Read the entire recipe Recipe added 1 day ago