Latest Node.js Recipes

Weird node.js' require behavior

I've been using node.js for about a year, and I always did that kind of stuff. But for some reason (maybe it's related to 0.8.x) now when I do it, it doesn't work anymore.

Here's some code:

Let's say I have test.js:

var test = {
    datFunction:...

Read the entire recipe Recipe added 21 seconds ago

Commander.js : script not waiting for user input

I am just starting to use node.js and commander.js so it might be a stupid question...

So I am trying to make a command line tool where I need to ask some info to the user. I am trying to use commander.js as it seems simple. The problem is that when...

Read the entire recipe Recipe added 57 minutes ago

node-expat compiled on windows but module not found

https://github.com/TooTallNate/node-expat/tree/gyp and node-gyp were used to compile it. node_expat.node was generated. I get the follow error when reference in code:

module.js:485
  process.dlopen(filename, module.exports);
          ^
Error: The...

Read the entire recipe Recipe added 2 hours, 1 minute ago

Nodejs asynchronous confusion

I can't seem to grasp how to maintain async control flow with NodeJs. All of the nesting makes the code very hard to read in my opinion. I'm a novice, so I'm probably missing the big picture.

What is wrong with simply coding something like...

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

How to call a function in main v8 loop from a different thread

I am trying to implement an audio module for nodejs which involves a neural network.

This neural network has 2 types of nodes

  1. Pure C++
  2. C++ based on JAVASCRIPT ( which involves calling a javascript function )

As far as i know its not possible...

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

how to use exsl:node-set from nodejs/node_xslt?

I am trying to use EXSLT node-set function from nodejs via node_xslt module. This is a simple wrapper around the libxslt library that has support for EXSLT as I could get it. Yet any reference to exsl:node-set produces Thi is how I use it.

   ...

Read the entire recipe Recipe added 5 hours ago

Node.js for a backbone.js application?

I will be making an javascript application using either backbonejs or canjs for the frontend and need a server-side language to connect to the database. Would node.js work fine for this?

I cant find any docs on someone trying to use node.js as the...

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

What javascript parser sould I use to re-implement jsCoverage in JavaScript for node?

I really like code-coverage reports for my code in node.js. I've already created a node.js module that can inject instrumented code (and mock our require statements) called requiremock

I'm using that in my other module nodecoverage together with the...

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

split() issues in node.js + express

When I try to split a string in node I get the following error...

TypeError: Object #<Object> has no method 'split'

Here is the split code I am using...

var query = req.query;

query.split(",");

I am using express to create my server, it seems...

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

Serving HTTP/1.0 responses with Node.JS (unknown content length, chunked transfer encoding)

The Problem

I am serving a resource of unknown length via Node.JS. Because of this, the Content-Length header cannot be set. For HTTP 1.1, it is required that chunked encoding is used for resources of this nature. Node.JS knows this and sends my...

Read the entire recipe Recipe added 9 hours, 1 minute ago

Is measuring js execution time a way to tell how quickly the app is responding to requests?

I have something like a microtime() function at the very start of my node.js / express app.

function microtime (get_as_float) {
    // Returns either a string or a float containing the current time in seconds and microseconds  
    // 
    //...

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

Is it possible to call a function from another function, using an external variable?

I've created a function that creates a session ID

sessionId = ot.create_session(location, function(sessionId){
    console.log('The session ID is: ' + sessionId + '++++++++');
    return sessionId;
});

I can print out the session ID from within the...

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

Callback recall itself

I have a function that inserts into a database a random number in a column that is the primary key.

I have a problem when the number is already in the database I want to call the process again to change the number and try to insert again but I am a...

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

Fasted way to increment a persistent counter from a node.js app?

I have a search engine written in node.js/express that is currently not logging any statistics, and I'd like to start keeping track of # of queries per day. So I just need a persistent counter that I can increment each time a query is submitted. (I'll...

Read the entire recipe Recipe added 13 hours, 1 minute ago

node.js buffering tcp data and delimiters

I'm trying to write a quick and dirty tcp server and have trouble with delimiters. Per this question I'm buffering incoming data and looking for delimiters (in this case '\r\n'. However, when I telnet in and send a message

foo\r\nbar

The below...

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

Node.js spawn vlc child process not working in express

I'm using node.js and express to create a controller of sorts for my home media centre that can be operated through a browser.

I'm having a lot of trouble spawning the VLC process, but strangely only it works when executed from the node prompt, just...

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

Sending command line arguments to npm script

The scripts portion of my package.json currently looks like this:

"scripts": {
    "start": "node ./script.js server"
}

...which means I can run npm start to start the server. So far so good.

However, I would like to be able to run something...

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

Migrating Express.js 2 to 3, specifically app.dynamicHelpers() to app.locals.use?

Updated Express.js from version 2 to 3, and the following call to app.dynamicHelpers({..}) broke as it is no longer present in V3:

app.dynamicHelpers({

    request: function(req){
      return req
    },
    ...etc.
});

There's a migration guide...

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

Expressjs doesn't destroy session

I have an Backbone View which sends an Ajax call to the server to remove a session.

On the server following event is triggered:

app.delete('/session', function(req, res) {
    if (req.session) {
        req.session.destroy(function() {
           ...

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

CoffeeScript compiler without node.js?

I'd like to use CoffeeScript(CS) and the CS Compiler but without having to install Node.js.

I saw that the core compiler of CS is in JavaScript, so there's no need for Node.js to be installed, but I can't find any compiler written in Python/Java or...

Read the entire recipe Recipe added 19 hours ago

Calling node-mongodb-native inside node-csv-parser: RangeError: Maximum call stack size exceeded

I'm using node-csv-parser to read in csv data and store it in mongodb using mongoose. However I'm trying to speed up the import, and I want to evaluate using the native save method exposed by node-mongodb-native, accessed in mongoose using...

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

What is the best way to query this in mongoose?

I have 2 model users and user_verifications. user have username and email, and so does user_verification.

Before I insert data to user, I insert the data in user_verification first. So, I want to know if username or email is already...

Read the entire recipe Recipe added 21 hours ago

putting node on heroku- Getting started

I am a begineer with Node and Heroku.

Was going through this link https://devcenter.heroku.com/articles/nodejs wherein they have a section "Declare Dependencies With NPM".

{
  "name": "node-example",
  "version": "0.0.1",
  "dependencies": {
   ...

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

What is destroying the process memory?

2012-07-20T03:04:50+00:00 heroku[web.1]: Process running mem=546M(106.8%)
2012-07-20T03:04:50+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
2012-07-20T03:05:11+00:00 heroku[web.1]: Process running mem=583M(113.9%)
2012-07-20T03:05:11+00:00...

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

res.redirect from POST

For some reason I cant redirect to /blog once my login is completed. In my login controller I have the following.

module.exports = {

    post: function(req, res) {
         var login = req.body['login'];                      

         if (login &&...

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