Latest Node.js Recipes

Cross server MySQL connection and requests

I'm going to be using Nodejs to process some CPU intense loop operations with sending emails to registered users as PHP was using too much during the time it runs and freezes the site.

One thing is that Nodejs will be on different server and do a...

Read the entire recipe Recipe added 18 minutes ago

Node.js node-apn module for Apple Push Notification stopped working after moving to Amazon EC2 instance running Ubuntu 12.04

I am using node-apn module to avail of APNS (Apple Push Notification Service) to push notification to multiple devices. The local environment is Mac OS X Lion 10.7 and the code works perfectly fine when run at local server.Here's the snippet:

var...

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

Using async with asynchronous functions

I know this sounds stupid, but I can't understand how to use async to handle existing asynchronous functions.

For example, consider some asynchronous function foo(arg1, arg2, ..., argN, callback) defined in some node module. Say I want to use this in...

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

Application using Node js, express js and mongo db

Anybody working example using node js, express js and mongo db? I have tried many links and most of them are raising errors.

The application must involve insert, update, delete, select operations of database.

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

How to enumerate all the sessions in nodejs + express?

I am trying to write a simple nodejs server with sessions and user authentication. Here is the code:

var express = require('express'),
    app = express(),
    fs = require('fs'),
    passport = require('passport'),
    jade = require('jade'),
   ...

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

Is this the optimal way to perform operations to MongoDB through a node.js?

I've writen this code where I start a connection to my MongoDB server and inside such connection I perform the web services code.

Is this an optimal or safe way? What would be better ways to implement this?

var express = require("express");
var...

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

Node.js and MongoDB Use results from one query in another

I have created a node.js module that can already query MongoDB for a set of documents using a find and output those results to JSON. My question is, knowing that node.js is asynchronous, how can I use the results from this query (items) to create a...

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

Going session-less with NodeJS

I've been doing a lot of research lately and it appears to me that going stateless serverside brings benefits to both performance & scalability.

I am although trying to figure out how to achieve session-less-ness on Node.JS. It seems to me that...

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

Node JS with Twitter Oauth

I am a beginner with Node JS and I am trying to connect on twitter using it. I am having a js file in E:/ directory but I don't know if I should create a module folder or what with the following code

    var express = require('express');
var sys =...

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

Node.js + Angular = Uncaught ReferenceError: require is not defined

I'm creating an Express.js API on a Node.js server. The API is used to access data stored on the server. I also keep a log of who's accessing the API in a database.

I'm trying to create an admin section that will use Angular.js to display the admin...

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

$all mongodb node js

I am implementing a search by keywords with mongodb and node JS, but I see that there is the operator $all in Mongo that selects the documents where the field holds an array and contains all elements.

Here is my source code with node JS

exports.find...

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

Watch and recompile individual templates with grunt

I have a directory with a bunch of jade templates, and a grunt task that compiles all of them to individual html files.

I'd like to have a watch task that recompiles a template when it changes, but right now my task recompiles every template when any...

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

How to call $addToSet if an array exists if it doesnt then call $set in one query?

Hey so I am trying to set a new array that does not exist in the mongodb docs, but I want to be able to throw additional documents into the array without constantly replacing the values.

for example:

users {
    id: 'value1',
    name: {value2},
   ...

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

While loop with javascript

I am exploring the node.js async library to implement cursoring (https://dev.twitter.com/docs/misc/cursoring) in node.js.

whilst looks like the function that I am looking for but my case is a little more different. Each time I make a GET request I...

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

JavaScript DOM selection from HTML string in node.js

I have been working on a single-page JavaScript application where I became dissatisfied with the templating options available, I decided to take a leap and start my own. I did this to not only fulfill my need and to learn, but if someone ends up using...

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

NVM and Module version mismatch

I installed NVM to manage Nodejs versions. I have checked out a software which needs 0.8.18, so I installed it through NVM and used it (nvm use 0.8.18). Now, I recompiled all the modules, but I keep receiving the message Error: Module version...

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

how to sent current directory path(Space in the path) into terminal via xcode application

I have to run a script from Objective C code. my script server.js is located at the path

/Users/SS/Desktop/iPhone App/Appium.app/Contents/Resources/node_modules/appium/server.js

In objective c code, I set the path as

[self.serverTask...

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

Mongoose update document Fail with findByIdAndUpdate

Trying to update MongoDB document using findByIdAndUpdate:

var landmarkModel = mongoose.model('landmark', landmarkSchema, 'landmarks');  
var lm = new landmarkModel();

//adding data to schema here, like: lm.name =...

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

waiting for data to appear/change in DB

I am writing REST api which has to provide kind of real-time communication between users. Lets say I have db.orders collection. And I have api GET /order/{id}. This api should wait for some change in order document. For example it should return some...

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

Toggle active link Bootstrap navbar

I've read a lot of posts on the subject, found almost always the same solution but it does not work for me...

My problem is as follows : I want to use Twitter Bootstrap 2.3.2 and its navbar, so I include the css and js files. Just before that, I also...

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

JavaScript OOP in NodeJS: how?

I am used to the classical OOP as in Java.

What are the best practices to do OOP in JavaScript using NodeJS?

Each Class is a file with module.export?

How to create Classes?

this.Class = function() {
    //constructor?
    var privateField = ""
  ...

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

Specify or in regular expression in node.js

This is the code:

// Only gzip javascript files:
gzip.staticGzip(__dirname + '/public', { matchType: /javascript/ })

This is the node.js module: https://github.com/nateps/connect-gzip

It signifies compression only for javascript files. How can I...

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

Send data from server(nodejs) to client(ajax request)

How do I send data from server to the client using nodejs?

So basically I call this function by clicking a button

javascript

function createStuff(tid) {
    $.ajax({
        type: "POST",
        url: '/create/',
        data: {tid: tid}
       ...

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

Node.js unit testing (in 2013)

I saw in StackOverflow that two years ago Expresso, Vows and Mocha were good options for unit testing in node.js, but what about now? I haven't found more recent questions.

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

Is there a way to check size of the packet sent/received in Socket.io?

Just as in title. I am trying to check the size of the packets sent and received by Node.js server using Socket.io.

Read the entire recipe Recipe added 1 day ago