Latest Node.js Recipes

Emitting event in Node.js

I'm trying to teach myself both javascript and nodejs at the same time here and have not been able to get custom event emitting working. I am not receiving any errors, just not seeing the event being emitted. Is someone able to point out my (likely...

Read the entire recipe Recipe added 44 minutes ago

is posible different language on web socket?

i have the problem when i want to try web socket technology on my application. but i want to ask about requiretment of web socket.

1) is posible i'm using Server with javascript language ex is socket.io

var io =...

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

sequelize for NodeJS: are these features supported?

Here are some questions about features supported by sequelize (sequelize project site) that I would like to clear up before deciding whether or not to use it:

  1. Chaining (efficiency): when chaining multiple queries, are these collected into one...

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

NodeJS: Uploading a remote file to S3 with request and knox

I'm trying to devise a way to upload a file from a url to s3 using request and knox. Currently, my code looks like this:

request(item.productImage, function(err, res, body) {
  if (!err && res.statusCode == 200) {
    fs.writeFile('/tmp/' + filename,...

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

How can I properly parse an email address with name?

I'm reading email headers (in Node.js, for those keeping score) and they are VARY varied. E-mail addresses in the to field look like:

"Jake Smart" <jake@smart.com>, jack@smart.com, "Development, Business" <bizdev@smart.com>

and a variety of other...

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

Testing Node with Superagent and Mocha

when I run this code below, the user is logged in and the browser is redirected to a new route home. How do I structure the test below to validate that /home is being redirected to.

The application is working fine, I am just trying to get my test...

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

How does require() in node.js work?

I tried this:

// mod.js
var a = 1;
this.b = 2;
exports.c = 3;

// test.js
var mod = require('./mod.js');
console.log(mod.a);    // undefined
console.log(mod.b);    // 2
console.log(mod.c);    // 3, so this === exports?

So I image that require() may...

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

Routing with express.js - Cannot GET Error

Working with express.js for the first time, and I am stuck on adding my first route.

My route is defined in app.js like so:

app.get('/user/:id/photos', function(req,res){
    res.send('user' + req.params.id);
});

However curling to...

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

In Express or connect with Node.js, is there a way to call another route internally?

So, I have the setup like this (in Express):

app.get('/mycall1', function(req,res) { res.send('Good'); });
app.get('/mycall2', function(req,res) { res.send('Good2'); });

What if I want make an aggregate function to call /mycall1 and /mycall2...

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

node.js application deployment in Windows Azure

I have built my application using node.js, mongodb, redis, express, socket.io and planning to deploy it in azure. I have seen that azure has a good support for node.js and it also supports mongo. But I am not very sure if it supports redis as well....

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

NodeJS npm - Using Contextify on windows

I'm able to build contextify 0.1.1 using node-gyp on Windows, but I don't know how to get npm to recognize/use this version when resolving other modules' dependencies. 'npm install' fails with the same (expected) 'node-waf was unexpected at this...

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

practical solution for dynamodb's max item length (64k) and no-sql's lack of table joins

First, some background context that I think may be very relevant:

I'm proofing dynanodb as a viable solution for an upcoming app. This is a learning experiment to familiarize myself with the dynamodb offering. My platform is amazon EC2 (Linux),...

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

Node.js restify on Windows

I want to start developing a REST API with Node.js. My development environment is a Windows 7 machine.

I read that the restify is a good choice for start a REST API, but this module depends from dtrace-provider, and dtrace-provider is not compatible...

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

node.js vs apache as http backend for multiplayer game

I have a multiplayer game with a gateway and multiple servers based on node.js and websockets.

Now it of course has a client which all consists of static files (html, js, resources).

Currently I am serving them with node (express framework)...

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

Using async module to fire a callback once all files are read

I'm using caolan's 'async' module to open an array of filenames (in this case, template file names).

Per the documentation, I'm using async.forEach(),so I can fire a callback once all operations have completed.

A simple test case is:

var async =...

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

nodejs with mongoose adding numbers

My model:

var CategorySchema = new mongoose.Schema({
...
...
...
, sortId: Number
...
})

my code:

var ca = 0
Category.findOne({orgId: user.orgId}).desc('sortId').run(function(err, cat){
 if(cat != null){
  ca = cat.sortId + 1
...

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

nodejs - npm install canvas error in windows

I've installed nodejs on windows and tried adding the canvas module using the following command...

npm install canvas

I get the following error message...

'node-waf' is not regonized as an internal or external command, operable program or batch...

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

Node.js/Express Caching

I'm pretty new to Node.js/Express, but I think I'm slowly getting the hang of it. I've added this code, which from what I can tell seems to be pretty standard:

app.configure('production', function() {
    var oneYear = 31557600000;
   ...

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

Node/Express.js - Overriding where to look for the 'Views' folder for each request

In my Node/Express.js project I can set the views folder globally like so:

app.configure(function() {
    app.set('views', __dirname + '/views');
    .... snip ....
});

...and all my view templates go into the views folder.

Is it possible to...

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

express-resource custom mapping

I can't find any decent documentation on this that contains any depth when requiring with app.resource.

The only information that I can find is creating the variable within the current file. Here

The current code that I have is below:

var favs =...

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

Error 330 when Gzipping a response from nodejs server

I want to gzip a file hold it in memory and whenever a request comes from the client, i want to output the gzipped data. However I get a error 330 message on my browser (i am using the latest version of chrome)

The code below looks straight forward...

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

Node coffeescript class files and inheritance

I have 2 class files:

foo.coffee: class Foo

bar.coffee: class Bar extends Foo

How do I define these classes so they are globally available? I get the error in Bar that Foo is not defined.

I have an index.js file that I call node on to run the...

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

Why do I to have prefix all my route handlers

I'm creating an application using Expressjs running on node under IISNode (i.e on windows).

I start by setting things up very much like all the expressjs examples I've seen:

  backend.configure(function() {
    backend.register('html', {
     ...

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

fetch specific attribute from model in backbone.js

i am fetching data using following code

 _.each(cardIds, function(id){        
                   var mdc = new MdlCard({cardId: parseInt(id)});                                
                  mdc.fetch({data:{cardId: parseInt(id)}});
             ...

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

Cannot find module 'connect', when attempting to use require('connect').utils.parseCookie with nodejs

I am relatively new to nodejs etc. Anyway I have a program that I am attempting to write that uses a session/authentication system based on this one here: http://iamtherockstar.com/blog/2012/02/14/nodejs-and-socketio-authentication-all-way-down/ Which...

Read the entire recipe Recipe added 1 day ago