Latest Node.js Recipes

How do I, in nodejs, set up a Mongo viewer (like Mongo-Express) on the same port as my main app?

I'm new to just about everything with regards to nodejs and Mongodb but I managed to get a simple app up and running and now I want a database viewer. I found Mongo-Express and installed it on my localhost where it works fine. The viewer is configured...

Read the entire recipe Recipe added 22 minutes ago

How come Q deferreds are so slow on Node.js?

So I created this simple test server in Node.js
Whenever I do a direct response, I get 2200 requests/second (fast!). When I only wrap a simple Q deferred around it, it drops to 580 requests/second (4 times slower!). Can anybody explain that huge...

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

Update multiple docs with different values

Don't think this is at all possible but wanted to check.

If I have the following documents:

doc1 : {
  _id: 1,
  name: 'John Smith',
  age: 20
}

doc2 : {
  _id: 2,
  name: 'Jane Smith',
  age: 22
}

I want the client to be able to pass me both...

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

Trying to turn JSONP data from AJAX response into HTML

The response is coming through to the browser in the developer tools, but I'm having trouble getting the data from the response that I want into workable form.

app.js

res.jsonp({
                pollName: loadedPoll.pollName,
               ...

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

How to remove module after "require" in node.js?

Let say, after I require a module and do something as below:

var b = require('./b.js');
--- do something with b ---

Then I want to take away module b (i.e. clean up the cache). how I can do it?

The reason is that I want to dynamically load/...

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

Writing a simple automation test in node.js but having trouble with sync calls

I am trying to write an automation script to test some of my api calls here is a simple example:

async.series([
    function(callback){
       func.clean_database()
       callback(null);     
    },
    function(callback){
      ...

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

How do I use external routes.js so I don't have to define my routes in app.js?

I'd like to do a simple link in express. I put into the index.jade

a(href='/test', title='View test page') Test

created in /routes a test.js

/*
* GET test page.
*/

exports.test = function(req, res){
res.render('test', { title: 'Genious test'...

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

Command line output when running application as Windows service

In a Windows 2008 R2 environment, I have a socket.io chat application that I'm currently starting from command line:

node app.js

This outputs different information about the app's state on the screen, which I can of course see in the command line...

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

Connection-route of node.js taking wrong parameters informations

I've a problem with my node.js application. I'm using the packages connection, connection-route, socket.io and ejs.

My application provides informations to the html page (connected via socket.io), these informations are managed by an ejs...

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

Create string key to a complicated json path

I need to access and conduct a series of operations on a big json object. Some things I need to read and alter are very deep into the tree with paths such...

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

Run node.js with different file extension

Is is possible to run node.js with a different extension than .js like: node server.type instead of node server.js?

I have tried require.extensions

require.extensions['.type'] = require.extensions['.js'];

but I get this error:

Error:...

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

Can I set npm to use a .pac file?

I am trying to set a private registry for npm (nodejs) but I don't want to replicate the entire public database. I have seen posts about how to do this, however, I have another problem even if I follow this approach. My workstation is behind a VPN, so...

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

node.js asynchronous sending of email

I'm new to node.js and am building out services using restify, mongoose and mongodb. One of the services I'm building requires an email to be sent and does not require the consumer of the service to be informed of the send status of the email. I...

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

Building A Backbone.js User Model, Collection and View For A RESTful JSON API

So I just finished making a fully RESTful JSON API for a User in node. When you visit http://localhost:8080/user/create you get what you would normally expect- a new User which is then stored in a database, in my case mongoDB.

{
  "createdAt":...

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

XAMPP + PHP to Node.js

I'm planning on converting a small PHP codebase (less than 1000 lines) to Node.js. It's a web app that contains about 50k lines of JS, so I figured I'd move it to Node.js. (Plus, PHP sucks donkey balls.) There's a few static files (CSS, HTML, etc.)...

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

Get all files required in node.js program

Is there some way to get list of files there where required (with require("...")) by node process?

UPD, solution: module object itself contains links to all required children modules.

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

SyntaxError: Failed to parse JSON body: Unexpected token o

I have a Node.js Heroku app on Facebook, and I keep on finding the following error in the logs (while getting a generic Application Error when I actually try to access my app):

2013-03-27T12:58:54+00:00 heroku[web.1]: Starting process with command...

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

ZMQ Nodejs binding - ZMQ_POLLIN/POLLOUT values

I'm inspecting these values to understand when I can shut down a socket (that is, when the socket is not polling/sending anything, thus I'm not loosing messages).

I'm using a sender (zmq.socket('push');) and a receiver (zmq.socket('pull');), but...

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

brunch config: javascript files exclude *.min.js files

I understand how brunch handles javascript files, combining them into individual output files:

  files:
    javascripts:
      joinTo:
        'javascripts/app.js': /^app/
        'javascripts/vendor.js': /^vendor/
        'test/javascripts/test.js':...

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

Angular.js Tutorial using the Node.js webserver

I am trying to go through the Angular.js Tutrorial_00 and cannot seem to work out how to get the node.js web server to run the demo app?

Has anyone done this tutorial or know how correctly use this step to get the server working?

  1. For node.js users:...

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

Urturn API ur: command not found

I am trying to install urturn api and write my own expression for urturn.com following http://webdoc.github.com/urturn-expression-api/#!guides/start

After:

npm install urturn-toolbelt -g

I am trying to run sandbox with:

ur sandbox

and got...

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

q.js: can I stop a function from executing until a promise is fulfilled?

As an example:

if(foo) {
    async_call(); // returns a Q promise object
}
// do this immediately if foo was false 
// or after the promise is resolved if foo was true

Is this even possible?

The alternatives I can see are either always calling the...

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

grunt-init not creating any file(s)

I probably missed something here. I'm using Node 0.10.1 on Win7/64bit and installed grunt 0.4.1 with

npm install grunt
npm install -g grunt-cli
npm install -g grunt-init

Then I tried to install a template while in folder %USERPROFILE%

git clone...

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

Google authentication: failed to serialize user into session

I'm trying to get some basic Google authentication going with PassportJS. The amount of information on the web seems rather limited and I keep hitting issues so thought I would try here.

I am using the code from ...

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

Node.js Best way to load JS variable synchronously

I want to load some data in server.js file that is stored in /data/projects.js (or .json depending on the answer of the question).

I see two possibilities:

  1. using readFileSync:

    function readJsonFileSync() {
        var file = fs.readFileSync(__dirname...

Read the entire recipe Recipe added 1 day ago