Latest Node.js Recipes

KML generator/formatter for nodejs

I am storing GeoJSON data in mongodb through a nodejs endpoint. I would like to create an endpoint to transform the GeoJSON data into KML. I did a quick google and also checked the npm registry for a KML module but could not find one.

Anyone know...

Read the entire recipe Recipe added 11 minutes ago

Socket.IO not working in Chrome and Firefox on Windows

I have made a Facebook like chat server and client using node.js (0.10.10), (0.9.16) and Express (3.2.6). It works perfectly fine in all browsers including all versions of Internet Explorer, but Firefox (21.0) and Chrome (27.0.1453.116) on...

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

How synchronize get and save in crawler

This is shortcut code of web-crawler that runs on Crawler and it's work well. The problem is that the crawler returns 20 strings for half of a second and they are storing in MySQL much slower than the new comes. How properly synchronize this both...

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

Node.js fs.unlink deletes locked file when it becomes unlocked on Windows

If I use fs.unlink to delete a locked file on Windows then the callback is called with an error, as expected. When I subsequently terminate node the file is deleted. I am at a loss as to how this might be happening and would prefer that locked files...

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

Trouble with starting Node.js from a Cygwin console

I have no trouble running node.exe from a regular command prompt:

C:\>node --interactive
> console.log("Works fine");
Works fine

But when I try to do the same thing from a Cygwin console, I run into this:

Olli@Olli-MBRr /cygdrive/c

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

Dispatcher with Node JS

I'm trying to do a simple server answering to url /page1 and /page2; this is the module dispatcher.js:

var HttpDispatcher = function() {

this.listeners = { get: [ ], post: [ ] }; 
  this.errorListener = function() { } 

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

Backbone User Model with multiple update paths

I have built a simple user model in Backbone

], function(_, Backbone) {

   var UserModel = Backbone.Model.extend({
      urlRoot: '/api/user',
      idAttribute: '_id',
      defaults: {
         userName: '',

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

Is there a way to register new CoffeeScript extensions for require?

I'm currently calling my test files something like for unit tests... (which produces the output test.spec.unit)

However, when calling require "" node interprets the file as javascript and it fails to evaluate. I've...

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

--Solved-- Node.js / / Mysql to print as JSON

SOLVED: Answer is: socket.on('clients', function(data) { document.write(JSON.stringify(data)); });

I want to get ouput like this (only the part in bold) on the screen as JSON:

debug - websocket writing...

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

Avoid extra query with Mongo and Express in PUT

I'm updating a record in Mongo with Mongoose/Express:

app.put('/loggedIn/:id', function(req, res) {
  if (req.user._id == {
      _id: req.user._id
    }, {
      $set: {
        interests: req.body.interests

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

When to reject/resolve a promise

I am thinking about when exactly I need to reject a promise. I found a couple of questions regarding this topic, but could not find a proper answer. When should I reject a promise?

This article ...

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

Using arbitrary mySQL Query with JugglingDB?

I am currently using juggling db with NodeJS for ORM. I now need to do some reporting, which involves joining data from several tables using arbitrary SQL with SUM and GROUP BY too. How would I do this using the jugglingdb framework, and get a list of...

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

Node js slow performance on 60 connections

I'm using NodeJS to put flag in memcache.

This is code:

var app = require('express')()
  , server = require('http').createServer(app)
  , io = require('').listen(server);

var memcache = require('memcache');

var client = new...

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

Get Device Token List for APNS Service

Is there any APNS endpoint by which I can get a list of all the device tokens on which my app is installed?
I know there is a feedback service which gives a status of devices to whom messages are being sent. But I guess that is after the messages are...

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

Node function finishing before Mongoose db find method

Why could the example below be returning the node middle-ware function before my mongoose db lookup function finishes? I am sure this is a async issue but I am a bit lost on why.

Middle-ware js file

var mongoose = require('mongoose'),
    Schema =...

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

multi subdocument update in Mongo subdocument arrays

I am trying to update multiple subdocuments within a Mongo collection, where there may be multiple matches within the same collection. Unfortunately, it is only updating the first subdocument within each document that has a match.

Here is the...

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

Need proper reporter for karma jasmine

I have a fairly simple karma.config.js file

basePath = '../';

files = [

autoWatch = true;
browsers =...

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

Mongodb push to array but keep the array with a max of 3 items

Is there an easy way to push to an array in mongodb such that the array has no more than 3 items. If there are 3 items the push should throw out the first item in the array. I'm looking for a safe way to do this.

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

How do I store a mongojs query result to a variable

All i get from this code:

var views = db.books.find({"number":1}, {"views":1, _id:0}); console.log(views);

is this response:

{ _readableState:
  { highWaterMark: 16384,
    buffer: [],
    length: 0,
    pipes: null,
    pipesCount: 0,

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

MongoDb : How to insert additional object into object collection?

I have a document "owner" that can have "n" number of camps and camps have "instructors" and instructors have "classes". Earlier I tried accomplishing this with nested arrays (see link to my post below), however I learned that the positional operator...

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

Mongoose save working in app but not in Mocha

I'm trying to write some basic unit tests for a project I'm working on as a learning experience and have run into something that has me stumped.

Basically, I can run the code below in a standalone node application and the code creates the new DB and...

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

ID mismatch using Passport in Express

So I have a bit of a problem, also just getting into Node so be gentle!

I have the following (using Passport):

User.findOne({}, '_id username interests', {
    _id: req.user._id
}, function(err, user) {
    if (err) return;

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

Date timezone conversion

I'm writing a chat program using node.js and When a user sends a message, I'd like the time at which they sent it to be emitted. Instead of the Date data being in the timezone of the person who sent it, however, I'd like it to be converted...

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

how to wait the end of the execution of a function

I have a main in nodejs for my program where I need to use my result calculated in a module, but my I don't have the right result.

var myJSONClient = {
    "nombre" : "<nombre_cliente>",
    "intervalo" : [0,0]

var intervalo =...

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

Changing --max-stack-size for grunt task

I'm running into the following error in my GruntJS script:

Maximum call stack size exceeded"

What's the proper syntax for invoking the node flag --max-stack-size= in my grunt command so I can set aside a larger amount of memory for the stack?

Read the entire recipe Recipe added 1 day ago