Latest Node.js Recipes

What's different between connect framework and socket.io?

I'm new to node.js, so i have some questions about connect framework and socket.io:

  • What's different? i'm confused about it.
  • Should i use connect fw with socket.io or just use socket.io?

Read the entire recipe Recipe added 48 minutes ago

Why during $save() it generates a new entry in the mongoDB with a string _id?

MEAN stack newbie here. Probably asking a silly question.

As an exercise, I have been trying to implement a prototype SPA which shows a series of task cards on the screen (kinda like Trello).

For now, each card has 4 fields:

  • _id:...

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

Find socket with parameter

I have a question: How to find a socket with parameter.

For example, when client connects I add to socket some parameters:

socket.name = 'John';
socket.country = 'USA';
socket.age = 25;


And how to search sockets which have a country China for...

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

How to use middleware for a specific route in krakenjs?

In the deploying middleware example, middleware is used with kraken like the following

// index.js
...
app.requestBeforeRoute = function requestBeforeRoute(server) {
  server.use(millionsServed());    
...
};

But this way, the middleware is applied...

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

Rights of node.js installation

What are the right necessities which we do have for the installation of the node.js on a server there? And what is the installation will be made for every user (session on the server) or global ? In the first one there is configuration to be made? thx

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

Node js middleware for async request to mongo

now i am working about my nodejs application. But i have some problem.

So all that i need add avatar field to post objects.

It look something like this.

In mongodb there are 2 model user and post. Post have userId field for one-to-many...

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

npm "error network getaddrinfo ENOTFOUND"

I am trying to install different modules through npm.

c:\>npm install -g express

But I am getting following error message:

0 info it worked if it ends with ok
1 verbose cli [ 'D:\\FH Kiel\\WS 13\\Advanced Javascript\\nodejs\\\\node.exe',
1...

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

SailsJS and Forever doesn't work with CoffeeScript

I have a SailsJS app, with much of it written in CoffeeScript. When running it in Prod mode using "sails lift" all is good.

Running it with forever doesn't work. If I examine the logs, the problem seems to be with node running app.js

...

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

Sailsjs update model json

Let's say there is a a user model defined like this.

...
attributes: {
    properties: {
        type: 'json',
        required: true,
        defaultsTo: {
            canEdit: {
                owned: false,
                other: false
           ...

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

Error handling on request piping

I wrote simple proxy on nodejs and it looks like

var request = require( 'request' );
app.all( '/proxy/*', function( req, res ){
    req.pipe( request({
        url: config.backendUrl + req.params[0],
        qs: req.query,
        method: req.method
...

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

Saving user in sails.js

In sails.js 0.9.7, how can I debug model.create() if done() function never called ?

I have a form like that;

<form action="/user/create" method="post">

And in my UserController;

create: function (req, res, next) {

   ...

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

Find the Last Index of a Non-Zero Digit using Javascript

How can you find the last occurrence of a non-zero digit in a number/string in Javascript? With that, we will be able to split a zero-padded number into the actual number and its zero padding. Any JS/Node library can be used.

Tried using...

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

Listening channels redis in node.js

There is such a simple code wiretapping channels radishes.

redisClient = redis.createClient();
redisDummyPublishClient = redis.createClient();
//redisClient.auth("25c9721b4e579fc5af961f944e23f46f");


//look for connection errors and...

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

Passport deserialize calls twice per each request

When I open any url in my node js + passport app I have 2 request for database (deserialze method call probably).

My log:

NEW QUERY____________________
SELECT * FROM users WHERE id=$1
[ '1' ]
GET / 200 248ms - 829b
NEW...

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

NodeJS testing Database with Mocha and should.js

I'm testing my NodeJS application with mocha and should. While the first test runs smoothly the second fails (error equals null). In both tests if got a valid user within the callback (both have the same id in mongoose). The tests obviously don't wait...

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

How can I share an object between my modules?

So I have a helper module H, which I require from my main script M:

M.js:

var o = {foo: 'bar'};
require('H.js').doFunc();

H.js:

module.exports = {doFunc: function(){ /* how can I set X to o.foo in M's scope? */ return X; }};

Thus one can expose...

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

node.js + mysql Query from url

I am new to this node.js. I am using mysql in my node.js. From the url i am constructing sql query. With 1 parameter its working fine.

The URL:

http://ipaddress:3002/users/Kappalur

By using the following code i extracted the Kappalur and its...

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

Authentication and cross domain error from a Node - Express application

I am developing an application using ember.js which is running over node.

Now, I have to call some external webservices and construct my home page accordingly (based on the webservice response).

  • These webservices are running in some external...

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

node.js non blocking code example failure

Following this link http://greenash.net.au/thoughts/2012/11/nodejs-itself-is-blocking-only-its-io-is-non-blocking/ I'm trying to code two non-blocking functions:

blocking code:

function LongBucle() {
    for (x=0;x<=10000;x++) {
       ...

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

Simple web socket server, using nodeJS and &quot;net&quot;

Maybe someone have an example of a web-socket server using just nodejs "net" package, without "ws" lib or socket.io. I tried to use net.createServer, but it seems i missing something, and i can't find any examples without the dependencies.

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

node.js - mocking modules with jasmine

I am trying to write some unit tests for my server side logic that is written using node.js framework. I wanted to use jasmine library for unit testing and mocking because I am a bit familiar with it.

Now, I tried something like this to mock file...

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

How to perform Insert statement by decoding Base64 in express

How to decode the param values received which were received as Base64 encoded form and insert into database ?

This is what i have tried.

  • According to this i am getting one value recieved from the client as param value and inserting into server ( I...

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

Express routing conflicting with AngularJS routing.

I have routing code of the following nature in Express :

app.get("/profile/:param", function (req, res) 

This is coinciding with the path routing provided by AngularJS. For instance, when an Angular view of the nature /profile/someparam#view1 is...

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

Requests bigger than 8 kb

I want to evaluate round trip time between client and server. Here the user can choose how big the request/response size of the message (body) should be. At client side I used Ajax-Post method to send 100 messages in an interval of 100 ms to the...

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

Node js async.series not working with Express app --- response happening too soon

I have a Node js Express app where I am setting cookies from many different places (the server, Twitter, another database, etc). These all need to happen in series. To avoid a callback nightmare, I am trying to use Async.js. But, the response keeps...

Read the entire recipe Recipe added 1 day ago