Latest Node.js Recipes

jQuery.ajax sending both OPTIONS and POST, how to handle with Express.js (Node.js)

Whenever my application sends an ajax request to the server:

    url: config.api.url + '/1/register', 
    type: 'POST', 
    contentType: 'application/json',
    data: /* some JSON data here */,

    /* Success and error functions...

Read the entire recipe Recipe added 33 minutes ago

express.static + middlware = 404

This works:

app.use('/private',express.static(path.join(__dirname, 'private')));

However as soon as I add middleware, the page can't be found.

var secure = function(req,res,next) {
    console.log('in here'...

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

NodeJS - Is Mongoose faster than MongoJS?

I've got an application that runs on NodeJS, and uses MongoDB as a database for information.

Currently I hook into MongoDB via the MongoJS module, which aims to "emulate the official mongodb API as much as possible".

The application gets about...

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

Debugging nodejs with node-inspector

I am trying to use node-inspector to debug my nodejs app and I am having problems. I can attach and bring up the app in chrome. I can also navigate to my scripts and set breakpoints. When I execute my code it will hit breakpoints but I cannot step...

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

NPM Install Error - Msnodesql

I'm running npm to install msnodesql, an npm library for sql server drivers. I am installing this on a Windows Server 2012 box.

I have installed Visual C++ 2010, node-gyp and Python 2.7.x.x as dependencies, and all of these installs were...

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

javascript node.js in a stand-alone script, block/wait on a promise

I have a simple program in node.js, such as:

// CODE1
var o = step3();

this program is meant to be run in a stand-alone script (not in a web browser), and it is a sequential program where order of...

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

node server crashes on object with over 1000 items

I have a collection with over 1000 items (Under 1000 items is ok.) which causes the following error and crash when requested via ajax call: (node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use...

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

How do I get my helper functions to load first? (Meteor, Node framework)

In my Meteor projects I have several helper functions of the sort


var tagStr = function () { return this.tags.join(', '); };


Template.articles.tags = tagStr;


Template.listing.tags = tagStr;

Now, I can...

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

Node.js - res.end and res.write can accept a callback function

When creating a basic HTTP server with Node.js, I noticed that the res.write and res.end methods of the 'http.ServerResponse' object can both accept a callback function like so:

require('http').createServer(function (req, res) {

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

Best session storage in ExpressJS - NodeJS

I'm building my first (and rather big) NodeJS application. I need excellent performance since it's a big all AJAX (AngularJS) interface with a lot of requests from a lot of users.

I'm building the login system, and I need to choose which storage...

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

Convert a 64bit little endian integer to number

first of all I'm sorry for the dumb question but I'm new with nodejs. I read from a socket a 64bit little endian signed integer, and put it on a Buffer, so let's say i have the number 256 represented as:

<Buffer 00 01 00 00 00 00 00 00>

Since the...

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

Initializing server for displaying hello using node.js cannot resolve

I am trying node.js as a possible technology as oppose to traditional php server for my school project, I am trying to initiate a server that prints hello, but for some reason my localhost won't display that, it only waits for localhost for a long...

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

Is it possible to get the model from the document in mongoose?

var UserSchema = new Schema({...}); // Schema
var User = mongoose.Model('User', UserSchema); // Model
var user = new User({...}); // Document

given just the document (user in this case), is there an easy way to get the model (User in this case)...

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

GridFS: Clean out all unreferenced files

I have just moved towards storing things in my GridFS in MongoDB. During testing, I noticed many files are being created but not deleted properly. I have a collection users, which has a field avatar. It contains the ObjectId of the file.

Now I'd like...

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

Coffeescript + Express: unexpected ,

I'm learning to make an app on Express.js using Coffeescript. I have uploaded my code at:

When I try to run the app, I get the following error: error: unexpected ,
res.send 'Hello World'

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

How to perform SQL Joins and Relations in Sails.js and Waterline?

Can anyone guide me on how to setup relational schema & performs joins in sails.js?

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

Accessing mongodb(mongoose) and then do something with it

So I have a collection foo. I use ajax to access it. In the success portion I have a for loop

  for(var i in data){
    var project = data[i]

So now the collection is connected to project. How do I access project to get the...

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

How to write a simple jasmine test for a MVC Controller function (sails.js)

I wanna do a TDD. However, I am going to write test on my controller function for my sails.js project

    :: Gamble
    -> controller
var GambleController = {

  index: function(req, res) {

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

Node/Express server-side include equivalent for static files

Express has no equivalent to server-side includes for static client-side content.

Can someone recommend a good solution for robustly replicating this functionality (for web age headers and footers mostly), but without resorting to a full-scale HAML...

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

Release required module from Node.js

How can one release a Node.js module during runtime in order to save memory or improve the overall performance.

My application dynamically loads modules in Node.js during runtime, but does not unload any of them. I'm looking for such functionality...

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

Nodejs mysql module not connecting to database

I'm trying to do a simple test query to get the node mysql module working but it's not connecting to the database. Here's my code in app.js:

var http    = require('http'),
io      = require(''),
sys     = require('sys'),
express =...

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

How to delay and consolidate pub/sub with Redis/Node/Rails

I got a RubyOnRails application that uses a Node.js/ server to push out trading information to all clients connected. Whenever a trade is executed the client screens get updated with the information of the last trade.

As the trading...

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

How to extract an array of fields from an array of JSON documents?

I have 2 mongodb collections, stu_creds and stu_profile. I first want to retrieve all the student records from stu_creds where stu_pref_contact is the email and then for those stu_ids I want to retrieve the complete profile from stu_profile. The...

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

Coffeescript + Express.js : cannot call method 'sliced' of undefined

I'm making my first app in express.js and coffeescript. The code is at:

When I try to run it, I get the following error:


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

node.js sendgrid how to attach a pdf

Im using sendgrid to send email in my node.js application. Every combination I try to attach a pdf ends up with my attached pdf being unreadable.

i've tried:

        var base64data = new...

Read the entire recipe Recipe added 1 day ago