Latest Node.js Recipes

Node.js + restify cant upload file

Im having problems uploading files to a node.js application using restify.

This is my upload code https://gist.github.com/maumercado/7ab5cbbfd27c6b825044

Apparently the events are not being triggered, but I dont really know the reason, also the...

Read the entire recipe Recipe added 58 minutes ago

How to remove unwanted keys and key values


Here is the original JSON object I am retrieving from my CouchDB database:

 {
  "total_rows": 3,
  "offset": 0,
  "rows": [
    {
      "id": "1e8fe199d4e761b71bb8920eb3003db2",
      "key": null,
      "value": {
        "_id":...

Read the entire recipe Recipe added 2 hours ago

binding values while looping in constructor CoffeeScript

I have decided to use CoffeeScript and i have been trying to convert Node.js module of mine to CoffeeScript. So, here is the code in JS:

function Domain(obj){
    var self = this;
    for (var key in obj){
        this[key] = obj[key]; //merge...

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

Removing named callbacks that are wrapped in an anonymous functions?

Is there a way to remove the listeners on a passed in named callback function that are wrapped in an anonymous function?

UPDATE. More complete code examples below.

Here are the details. I've a function that gets passed in a named...

Read the entire recipe Recipe added 4 hours ago

Bail suite on mocha (sub)suite error but continue next?

I'm using mocha in node.js with have bdd-style specs.

Is it possible to bail a sub-suite after the first error but continue it's parent/sibling suites?

Say I test different routes to access an api, then I want to abort a specific route if it's...

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

How do I receive an http request with a Node.js server and then pass that request along to another server?

There's a lot going on here so I'll simplify this into a pseudo example. Forget about security and whatnot for a minute here. The point is to understand the functionality.

Let's say I'm running a local web server with node.js to dev a website. In the...

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

how to use populate and aggregate in same statement?

this is my appointment collection

{ _id: ObjectId("518ee0bc9be1909012000002"), date: ISODate("2013-05-13T22:00:00Z"), patient:ObjectId("518ee0bc9be1909012000002") }

{ _id: ObjectId("518ee0bc9be1909012000002"), date: ISODate("2013-05-13T22:00:00Z"),...

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

Basic AI in Node.js/Socket.IO

I'm creating a small game in Node.js/Socket.IO and need some advice on creating the AI. The code I have below is a real quick example I came up with but it's so fast the player doesn't even see the enemy move on the client-side. Am I on the right...

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

Developing a real time collaborative drawing system

I am interested in making a realtime collaborative drawing system similar to http://flockdraw.com/ . However I would like to only use open source tools (flockdraw uses flash and also limits the number of users) and also I will host it myself.

I...

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

Why mongoose.model.create's Callback Isn't Executed from within Express 3.x HTTP Request Handler (connect-mongodb is the cause, actually)

To put the problem stright in code:

expressApp.get('/', function requestHandler(req, res) {
  userMongooseModel.create(userPropertiesDict, NEVER_CALLED_CALLBACK);
  console.log('This is printed just fine but browser awaits response...

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

Installing Appium server on Windows -- how to get past grunt errors?

I'm using this guide:

https://github.com/appium/appium/blob/master/docs/running-on-windows.md

And on this step:

grunt configAndroidBootstrap

I can't get it to run. I've tried:

  1. Running it inside node.
  2. GitHub\appium\node_modules\.bin\grunt.cmd...

Read the entire recipe Recipe added 11 hours ago

Technical aspects of running Node.js and apache in parallel

Earlier today, I asked a question on the Programmers StackExchange: Is it bad practice to run Node.js and apache in parallel?

My end application can be considered a social network in which I want to have a chat feature and a normal status update...

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

Is events.EventEmitter.call(this) required when creating a custom EventEmitter?

There are a lot of example not using events.EventEmitter.call(this) in custom event emitter constructors, while other are using it (official documentation):

var events = require('events')
  , util   = require('util');

var MyEmitter = function () {
 ...

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

How do I deploy an Angular.js app?

This may be a stupid question, but I'm wondering what platform I should use to deploy my Angular.js app? I tried using Heroku but got a "no Cedar-supported app detected" error. Any thoughts?

UPDATE

I'm trying to serve this to heorku as a Node.js...

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

Mongoose Schema - Requiring one to be unique but not both

I want to store an email string and password where only 1 needs to be unique. So someone can use the same email address with 2 different passwords (or 100) and have 100 accounts but all the passwords must be different however someone should still be...

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

Does nodejs/V8 store compiled machine code anywhere on disk?

Edit: as @dystroy notes below, node uses machine code directly, not bytecode.

I do a lot of Python coding, and there's always bytecode lying around in .pyc files.

I was wondering if node stores its machine code in similar files, eg it would make...

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

How can you stream a JSON file in Node.js and interpret it as JSON?

I have a JSON file that I want to use in a Node.js script. I want to pass the json and then the script to parse it. I tried using fs.readFileSync(filename), but that returns a buffer. How can I convert that back to JSON so that I can parse it?

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

Async fluent javascript (node) interface (using deferreds)

What is the best way to build fluent interface in Javascript (node.js) with

obj.function1().function2().function3();

where functions are asynchronous methods?

There is a module called chainsaw, but if it is possilble to do with deferreds and...

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

Mongoose date format

Currently having an issue retrieving dates from mongoose. This is my schema:

var ActivitySchema = new Schema({
    activityName      : String
  , acitivtyParticipant  : String
  , activityType  : String
  , activityDate      : { type: Date, default:...

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

Best node.js module for finding location?

I had found couple of node.js modules for finding the information about client location and network using ip address.

Requirements:

  1. Location - country, city, state, latitude, longitude etc.

  2. Network - Internet service Provider, Internet connection...

Read the entire recipe Recipe added 20 hours ago

grunt-contrib-concat: how to use option "process"

I am writing build system using Grunt for a Javascript library (Widget) that would concatenate, minify and package the files for distribution.

In the concatenation step I wanted to insert current date into one of the JS files with process option of ...

Read the entire recipe Recipe added 21 hours ago

TypeError on static method of mongoose model

I'm using node.js along with the MongoDb driver Mongoose 3.6.1. This is my schema definition:

models/user.js

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

var userSchema = new Schema({
            ...
});

module.exports = {
   ...

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

JSON stringify conversion of float to int

I am using Node.js and the built-in JSON object to stringify a JSON object. In the object is

{ 
    weight : 1.0
}

However when I stringify and write to a file the output is weight : 1.

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

node.js sending POST requests not working

I'm trying to send a post request but It is not sending. I dont get output in the console log of the browser.

My node server.js is running in x.x.x.x:8000 then I connect it with my client.html. x.x.x.x:8000/client.html

Here is my node.js...

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

multiple async mongo request in nodejs

How to write multiple queries in a row?

Like a

Space.findOne({ _id: id }, function(err, space) {
    User.findOne({ user_id: userid }, function(err, user) {
        res.json({ space: space, user: user});
    });
});

does not look good with more...

Read the entire recipe Recipe added 1 day ago