Latest Node.js Recipes

passing variables to a view in expressjs

i am quite new to expressjs/nodejs and trying to pass multiple values from a route to a view so that i am able to show user specific input on the page. This is what i have in my route:

// Dashboard for site after the login

Read the entire recipe Recipe added 38 minutes ago

Implementing API keys for my API

I have created and api and i want to have some control over who use it, how often etc. I want to have a API key strategy so that the users must provide the key in order to use the API. However i don't know how to implement it. The users are registered...

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

Running node-phantom in mocha

I have a simple test here I expected to work. The idea is to get phantom working in mocha's tdd. (by the way I have tried both node-phantom and phantomjs-node with no success.)

nodephantom = require 'node-phantom'
assert    =...

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

How does node.js take part at mobile?

Now-days I'm aiming to start learning to develop with node.js.

I hope my question is clearly - when you are talking about node.js and mobile, what do you mean? to web application which is developed by node.js and the users come via the simple...

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

Jade checkbox checked attribute unchecked based on conditional (if)

How do I get jade to render the checked attribute of a checkbox based on a conditional? Like these two versions of the HTML checkbox tag:

This seems to be the ONLY valid version of unchecked:

>  <input type="checkbox" name="vehicle"...

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

How can I buffer a http response using the request module?

I would to convert a incoming http response which is a stream and store the data in a variable. I don't much about node streams and I am struggling to do this properly.

var request = require('request');


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

nodejs regex - why do we need &quot;?&quot; in the following regex

I have a question regarding the following regex:

match = /^([^[]+?)(\[.*\])?$/.exec(path);

I don't understand the behavior of the "?" in the first expression:


I mean, if this expression was an independent regex, and path was...

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

Javascript JSONArray issue with push() and for loop

I've made a simple program to store locally an array using two for loops, but something strange took place...

There's my code:

var imagesdata = data[0];
var preferences = data[1];

for (var i = preferences.length - 1; i >= 0; i--) {

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

Jade conditional (if/else) to add class to div inline

Is there a way to do this inline in a jade template?

if(typeof fromEdit != 'undefined')

Would like to do this conditional check "inline" and the result would add the .in to the end of the div if...

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

how to get the browser's size in node.js?

how would I get the browser size in node.js? I want to send it to a jade template so it can place a unknown amount of divs on the page spaced equally. if getting the users screen size is not the best way of doing it please let me know a different...

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

Struggling with node.js concept on sync vs async

I come from a PHP background and have started using node.js. Most things I am doing okay on but there are some thing thats I am having a hard time wrapping my head around when it comes to sync vs async and scope.

Here is a pretty simple...

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

Node.js EventEmitter error

I have an error when trying to inherit EvenEmitter

/* Consumer.js */
var EventEmitter = require('events').EventEmitter;
var util = require('util');

var Consumer = function() {};

Consumer.prototype = {
  // ... functions ...
  findById: function(id)...

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

nodejs regex - need help to understand code

Can you please explain what this code does (from Blair Mitchelmore jquery.query-2.1.6.js)?

    var parse = function(path) {
      var m, rx = /\[([^[]*)\]/g, match = /^([^[]+?)(\[.*\])?$/.exec(path), base = match[1], tokens = [];
      while (m =...

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

Passing an array to jade file

so this is my problem:

I have this render function somewhere in my express code:

    function renderWithData(arrayOfEvents, res) {
    res.render("index", {
        locals: {
            pageTitle: "Wochenplaner",
            events: arrayOfEvents

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

Test a webservice on a different port locally without JSONP

I'm currently writing a webservice (with node.js) for an AngularJS frontend which is hosted with node.js

It will later be available through a proxy under and therefore I don't need JSONP.

For local testing purposes i have my AngularJS...

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

nodeJS zeroMQ: why cant send message if sock.send not in setInterval

I was using zeroMQ in nodeJS. But it seems that while sending the data from producer to worker, if I do not put it in setInterval, then it does not send the data to the worker. My example code is as follows:

===========     ...

Read the entire recipe Recipe added 15 hours, 37 minutes ago check for inactivity apart from heartbeat from client

I have a PHP application that has a chat functionality using nodejs and What I now need to do is to log the user out if the user is dormant for more than 15 minutes.

The sessions are shared between the PHP application and Nodejs server. So...

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

Twitter Streaming API Multiple Stream vs Custom Filter

I'm building a node.js application that opens up a connection to the Twitter Streaming API (v1.1)

I would like to filter multiple keywords (hashtags & words) as separate queries. My original idea was to have multiple public streams.

However, I...

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

I'm getting following error while using node.js with socketstream.&quot;throw new Error(&quot;Cannot find module '&quot; + x + &quot;'&quot;)&quot;

I'm using node.js with socketstream..I'm getting following error while running my

"appln.Cannot find module '/entry' [Break On This Error]

throw new Error("Cannot find module '" + x + "'")


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

Node js and new when using require

I've been trying to sort out the include of other js files within node.js.

I've read all about the require function and other alternatives and decided to go with the require function (as the code will only ever be used on node.js, not in a...

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

Bytes sent/received for Node.js HTTP request

Once an HTTP request has been served, I would like to log the number of bytes sent/received.

A simple source for this data is req.connection.bytesRead/.bytesWritten. However, this is problematic for HTTP 1.1 keep-alive connections, as the same...

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

Why does downloading a file produce an EADDRNOTAVAIL error?

I'm trying to download a file using node.js using the following script:

var http = require('http');
var fs = require('fs');

var file = fs.createWriteStream("google.html");
var request = http.get("", function(response) {

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

Getting notifications on database changes: is it possible to watch entries in riak?

I'm looking for an efficient way to subscribe to events in riak from node. I would like to be able to be notified of changes on an entry from riak.

For example when one node.js server updates an entry, another server using and watching that entry...

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

NodeJS UDP Multicast How to

I'm trying to send a UDP Multicast Packet to: so everyone subscribed will receive. A bit stuck. I believe it's broadcasting correctly, but can't seem to pick anything up with any client.


var news = [
   "Borussia Dortmund...

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

Session variable not storing in node.js

I searched and found a lot of similar problems with session variable being set to undefined, but none of the answers I found seemed applicable.

I have this function in my router file:

exports.loginHandler = function(req, res){
    username =...

Read the entire recipe Recipe added 1 day ago