Latest Node.js Recipes

How do I deep copy in javascript?

I have a situation similar to what you see below. The variable id is set to '03' before the first asynchronous callback is returned. Is there a way to deep copy, or "close" around the variable like you can with blocks in Objective-C? Is there a best...

Read the entire recipe Recipe added 47 minutes ago

Creating facebook app with callback url

I am creating a facebook app. And I want to let users to login to my website using it(Using passportjs).

But to do that, I need to give callback url(my website url). But I couldn't find that field in the facebook app creating page.

Am I missing...

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

Sessions on AppFog with ExpressJS

I get a problem with sessions on my ExpressJS App. In local it works perfectly but when I host my App on AppFog I get some issues with the sessions, they are lost sometimes... In my admin panel.

I don't know why but, when the page is refreshed, the...

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

Express router conflicting with Backbone pushstate

An Express / route serves my Backbone's app index.html.

I'm using pushstate in Backbone but the routes that Backbone should handled are being handled by express, giving 404 responses.

How can I setup Express to serve the index.html but to delegate...

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

NODEJS writeStream error

var http = require('http');
var fs = require('fs').createWriteStream('file1');;

http.createServer(function(req, res) {
  // This opens up the writeable stream to `output`


  // This pipes the POST data to the file
  req.pipe(fs);

  // After all the...

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

Jade templating, variable scope in includes

I am using Jade (without Express, just for static HTML templating) - which I understood as able to create partials, meaning scope is not an issue, but this doesn't seem to be the case and I can find no reference to this use-case.

master.jade

!!!...

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

Updating a node module doesn't affect the program

I'm experiencing something weird.

I have a node project that uses an external module imported with npm into the node_modules directory.

Now I am making a change in the node module code and when I run my app the change doesn't kick in (I know because...

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

Mongodb / MongoHQ connection from Nodejitsu

I seem to be having trouble connecting to MongoHQ (via MongoSkin) on jitsu. I can connect from localhost though, and all I'm doing is changing my env var and jitsu deploying. It's just strange that it works locally but not deployed. I had talked with...

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

Error with Express on AppFog but not in local

I get an error when I host my app on AppFog. Line 50, when I call JSDOM... The issue doesn't appear in local, I don't understand why it doesn't work in remote...

My code (works in local):

exports.index = function(req, res) {
   ...

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

Mongoose: Get max id from table before inserting new row

When I post a request to my node server to create a new item I need to get the max item id from the item table.

I.E. I am using an itemId as a one up sequence in that table.

var Item = new Schema({
  itemId: {type: Number, required: true}
 ...

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

Not able to connect to databse using nodejs

I am very new to nodejs and am not able to figure out what exactly is going on here- i have a basic login page, in which as the user types in the values, i go to the home page, before which i check up on the database if that username exists or not....

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

ExpressJS and MongooseJS: can I query array values in a subdocument?

I've got a web api written using expressjs and mongoosejs.

The main schema in the app contains a subdocument, permissions, which contains array fields. Those arrays contain ids of users who can perform an action on that document.

I'm trying to...

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

Can I scan my local network for specific open ports quickly?

I would like to know if there's a way to scan through my local network's IP range for open ports of a specific number.

Essentially I'm looking for nodejs to find clients of a specific type without knowing their IP addresses. In this case, RFID...

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

How come my views are not returned when exported from a file in my routes directory?

I'm just experimenting with basic routing in ExpressJS and so far I have two routes:

app.get('/', function(req,res) {
  res.render('index');
});

app.get('/pics', function(req,res) {
  res.render('pics');
});

When defined like this, in my app.js,...

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

Node Express markdown loop

How do I loop over an object and output markdown as part of the loop in my jade template?

Here is my template file

block content
  section.content
    h1= title
    p Welcome to #{title}
    ul
      each post in posts
        li!= :markdown
       ...

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

Using sparse: true still getting MongoError: E11000 duplicate key error

Schema (../models/add.js)

var addSchema = new Schema({
    name: {type: String, unique: true, sparse: true},
    phone: Number,
    email: String,
    country: Number
});

module.exports = mongoose.model('Contact', addSchema);

add-manager.js

var...

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

form(method='get') works for node.js, but status: pending in dev-tools

I am making a webpage that uses forms to submit user votes to a mongo database using node. While the code below sucessfully modifies the db, it causes a pending status operation in chrome dev-tools. This prevents all js from running, and after a few...

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

Forever.js: Using one instance for multiple users

I've got Forever.js running, but what I'm trying now is to let more than one user use the same Forever.js instance.

If I start a file with Forever.js right now, I cannot see/stop/restart it with another user. If I do Forever.js list there, it shows...

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

Browser websocket fallback and support

Simple question: I saw on the site of socket.io several fallbacks for websockets (http://socket.io/#browser-support)

But I can not find (even after a long google session) which browsers use which fallback. The reason I'm asking is that I want to...

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

Heroku Node.js Remote Mysql Database IP Address

I have a remote Mysql database that I am connecting to through Node.js on Heroku. My MySql host (bluehost) wants me to input IP Adresses of all remote MySql connections.

Heroku doesn't have a dedicated IP for my app, so how can I connect to it?...

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

Raspberry Pi, Arduino, Node.js and serial port

Im trying to talk to my arduino from a node.js server script.

Here's my code:

var app = require('express')()
, server = require('http').createServer(app)
, io = require('socket.io').listen(server)
, SerialPort  =...

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

How do I use Gently to stub a method of an object that is not immediately exposed by a module?

I'm using the AWS SDK for NodeJS.

I've got a module (moduleFoo) set up like this:

if (global.GENTLY) { require = GENTLY.hijack(require); }

var aws = require("aws-sdk"),
    ec2;

exports.initEC2Client = function () {
    ec2 = new...

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

Unable to connect socket.io in node.js with tls

I have googled and search in stackoverflow, any thread related to socket.io+tls, or node.js+tls, or ssl, an so on... but I cannot find any way of building what I need:

A node.js server connected to the client through socket.io and using tls (only...

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

Response encoding with node.js "request" module

I am trying to get data from the Bing search API, and since the existing libraries seem to be based on old discontinued APIs I though I'd try myself using the request library, which appears to be the most common library for this. My code looks...

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

Derby.js TypeError: Object function (files)

Everytime I try to run the basic server.js that comes with a new project I ge the following errors:

node server.js

Master pid 5078
   info  - socket.io started
5079 listening. Go to:...

Read the entire recipe Recipe added 1 day ago