Latest Node.js Recipes

Full Text Search in MongoDB/Node.js-mongoose-text-search

I am trying to perform full text search on MongoDB and Node.js using the mongoose-text-search plugin. I am following the example code from https://github.com/aheckmann/mongoose-text-search and my code is shown below. I keep getting an error stating:...

Read the entire recipe Recipe added 18 minutes ago

connecting to node.js http server on linux machine from windows machine

I'm trying to write my first node http server. I have got it running on my linux box. If I type the url in the browser. I see the hello world webpage.

 myLinuxHostName:1227/

I'm now trying to connect to this linux node server from my windows...

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

Does node.js have equivalent to window object in browser

What I mean is does node.js have object that are global function methods of. Like this in browser:

function myGlobalFunction() {
    console.log(this === window);
}
myGlobalFunction();

=> true

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

Why isn't this javascript while loop running in node?

I'm trying to make it so the program repeatedly accepts input and repeats it back until "exit" is inputted. Right now the loop doesn't run, and I don't know why since the exit variable is set to false. Here's my code:

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

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

Storing JSON data from Node.js to MongoDB

I'm pulling weather data in JSON format from Wundground through their API with no problems. I'm trying to store that data in MongoDB for later use. I actually get the data and am able to write it to a collection in Mongo. However, when I do a...

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

How to format Mongoose debug output - pretty print

How can I make Mongoose debug output look pretty in console? Currently the output is displayed on one line.

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

yeoman/grunt-usemin not updating index.html after new js has been added

I am using yeoman with the angular generator for a web app on windows7. After running yo angular I run grunt to build the app for deployment. My index.html file in the dist folder is changed accordingly with the css and js files that was concatenated...

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

WAMP.ws : How to manage security and privacy?

I'm using WAMP.ws specifications to design public/private user chatrooms on my website.

My problem comes when I try to keep a list of all connected users. What I could do :

  1. All users subscribe to "/contacts/connections" topic.
  2. When an user connects...

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

How to test equality of an Array containing undefined elements?

I encountered some weird behavior in the assert module of node.js. I'm not sure if this is a bug or intended behavior.

When I create an array, and then initialize a value for example on the 3nd element, the first two elements are undefined. Testing...

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

Node.js - pipe() to a http response results in slow response time on ubuntu

I noticed serious performance issue when piping a response from a service B to a client through server A. I found out this issue while investigation performance one one of our node server that mainly does proxying. We are using http-proxy for...

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

Passing a Mongo connection to JQuery code via socket.io?

I am trying to create a global MongoDB connection in my node.js web app like this:

var MongoClient = require('mongodb').MongoClient;
var mconn = null;

MongoClient.connect('mongodb://myHost:27017/users', function(err, udb) {     //open connection to...

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

Creating a chat with nodejs ws (einaros)

Yesterday I started using this module. I'm trying to make a chat for do something with websockets.

I have the problem, that I don't know how to pass the message that sends a client to the server for then show it for all users. In the server side I...

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

Node.js as gateway

I am thinking of using node.js as a gateway. I want to implement several frontends (browser, apps etc.) which get served by node.js with data over websockets. Node.js cannot fetch this data directly from a database but node.js should get it from a...

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

Tracking down stack overflow in meteor/node fiber

I'm seeing this crash now and am not familiar enough with the node fiber infrastructure to know where to begin interpreting the error or instrumenting the code...

Meteor server running on: http://localhost:3000/
W202407-10:06:05.740(-8)? (STDERR)...

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

How to use ICU with UTF-16?

I'm looking into using ICU for Unicode string processing in a native Node.js module because it seems to me that v8::String (according to these docs) doesn't have a C++ API for this purpose.

To my knowledge V8 expects UTF-16 in ExternalStringResource...

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

Reading a file in javascript via Apache Pig UDF

I have some (very simplified) nodejs code here:

var fs = require('fs');

var derpfile = String(fs.readFileSync( './derp.txt', 'utf-8' ));
var derps    = derpfile.split( '\n' );
for (var i = 0; i < derps.length; ++i) {
    // do something with my...

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

Nodejs Socket io on regexp match

Im trying out Node and Socket IO, and im trying to match routes in similar way node does it e.g

app.get("controller/action/somevar", callback);

however using regex in socket event matching seems not to work. Is there a way to match regex event, or...

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

passing json object from php to javascript

In PHP, I have a JSON object like so (even here not sure if its correctly formatted and if I'm passing it correctly):

$someJSONObject = '{token:"randomtoken",signature:"signature"};

and encode it before passing the response:

$response['code'] =...

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

Killing msnodesql connection when socket disconnects?

I have a socket (socket.io) that connects to a MS SQL db on socket connection like this:

io.sockets.on('connection', function (socket) {
    var intervalID;
    sql.open(connStr, function(err,conn){       //open connection to MS SQL db
       ...

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

Appending files in node.js on heroku

I tired below code in local works, but not in heroku, anyone know the reason?

var mob = req.body.phone + " \n";
fs.appendFile("phone.txt", mob, function(err){
    if (err) throw err;
});

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

How to clear a readable stream while uploading image in node.js

I am trying to upload multiple images with the help of multiparty module. I want to upload only a particular kind of images, say whose names are 'image.jpg'. But it's not working when the image does not meet the criteria and I don't get any response....

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

Socket.io : Get Client sessionID at any point

I know how to retrieve the client sessionID when the user connects.

But I'd like to retrieve it at any time, for example when the client clicks on something, I would like to be able to know who clicked, what their sessionID was.

socket.sessionID...

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

NodeJS &gt; req.query is returning incorrect data

I am sending a JSON (from Client-Side) to a NodeJS Server like this:

$.ajax({

  type: "POST",
  dataType: "jsonp",
  url: "www.xyz.com/save",
  data: {

    designation: "Software Developer",

    skills: [

      "",
      "ASP.NET",
      "PHP",
 ...

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

Node.js formatted console output

Is there a simple built-in way to output formatted data to console in Node.js?

Indent, align field to left or right, add leading zeros?

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

Nodeunit not detecting done()

Trying to get up to speed with node.js and nodeunit but am finding an issue with nodeunit where it's not seeing the call to test.done() in one of the tests.

The code:

// Added for clarity.
var client = require("restify").createJsonClient({
   ...

Read the entire recipe Recipe added 1 day ago