Latest Node.js Recipes

Unable to return JSON from REST API with RESTIFY

I'm new to Node.js. I'm trying to create a web server that will 1) serve up static html web pages and 2) provide a basic JSON / REST API. I've been told by my management that I must use RESTIFY (I don't know why). Currently, I have the...

Read the entire recipe Recipe added 4 minutes ago

Swig template, testing condition

how can i do something like this with swig-template?

var remId = $(this).attr('remId');
if (remId) {
    var end ='_');
    var underscore = remId.slice(end, end + 1); 
    var Id = remId.slice(end + 1, remId.length);

for example,...

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

Background process shows as "not responding" on OS X

I'm attempting to resolve this weird problem with our OS X application.

As part of it's normal operation, it starts a long running background process — specifically a Web server, written in node.js.

After some time running, the background process...

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

How in Javascript (or in Node), the function's arguments are recognized?

I was learning Node.js (even though I am not an expert in Javascript but I understand and write code on it). Now, trying to play with Node.js, I just got stuck in this code:

var fs = require('fs');
fs.readFile('/etc/passwd', function (err, data) {

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

node.js webserver does not reload

I'm using this script for my node.js webserver (ubunt):

var util = require('util'),
    http = require('http'),
    fs = require('fs');

fs.readFile('htdocs/index.html', function (err, html) {
    if (err) {
        throw err; 

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

Populate an array of Model objects with mongoose

This is the schema that I use. As you can see survey_codes model path consists of an Array of ObjectIds.

var Schema = mongoose.Schema;
var Email = mongoose.SchemaTypes.Email;
var ObjectId = mongoose.SchemaTypes.ObjectId;

var RestaurantSchema =...

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

Using PCRE library in native node modules

I'm trying to use the PCRE library in native C++ nodejs modules. I added #include "pcre\pcrecpp.h" in my cpp file, but I'm getting

e:\nativenode\pcre\pcrecpp.h(334): fatal error C1083: Cannot open include file:
 'pcre.h': No such file or directory...

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

CLI: implement something like git commit (open a text editor and get value)

I am making a command line app. I want to allow the user, when they are adding values for things in the terminal, to be able to add the value with their text editor. How does git achieve this?

I want to open their default editor, allow them to enter...

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

How to convert Markdown to HTML in Node.js / Express / MongoDB app

I have this snippet of code which works just fine; however, is this good design? I'm concerned about the res.send() executing before the for loop has had a chance to finish.

  app.get('/api/ideas', function(req, res) {
    var query = Idea.find({...

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

Three on node.js with JSONLoader

I need to use three.js on my node.js server to control positions and collisions on players (I try to make a video game).

To use three on nodejs, I have install with "npm install three", and it's works.

But when I want call JSONLoader, I can't.

I my...

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

Webserver after closing the terminal

I've a linux server (ubuntu) and installed node.js.

My script: webserver.js:

var http = require('http');
http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});

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

How to remove 'Object has no method 'forEach' error in node.js'?

My code is as follows:-

var generateTypos = function(keywords, options) {
 // Adding a function to the String Prototype that allows to
// change characters at a certain index.
// Needed, since "string"[n] is...

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

How to share common client-side javascript across NodeJS projects?

I'm a Node n00b starting a couple web app projects using Express, and I've got some common client-side libraries I'd like to share between the two projects. This seems like a very common problem, so there must be several solutions available...

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

Node/Express/mysql How to make get SQL results within jade page?

I have a node/express app that I use to monitor a MySQL db of mine. My page goes like this :

Node :

app.get('/banners', function(req,res){
    connection.query("SELECT * FROM banner_store_idx WHERE id_type='1' ORDER BY id_banner ASC", function...

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

Generating PBKDF2 keys in C# and NodeJS

I'm trying to encrypt a byte array in C# using AES192 and a PBKDF2 password/salt based key and decrypt the same data in NodeJS. However my key generation produces different results in both NodeJS and C#.

The C# code is as follows:

    private void...

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

how to use the redis publish/subscribe

Currently I am using node.js and redis to build a app, the reason I use redis is because of the publish/subscribe feature. The app is simply to notify the manager when user comes into the user or out of room.

function publishMsg( channel , mssage){

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

NodeJS streams - a leaky pipe?

I'm doing a lot of work with NodeJS streams at the moment.

One thing I find myself needing is a 'leaky pipe'.

Like stream.PassThrough, but which just drops data if (and only if) it has no where to send it.

Does such a thing already exist?


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

Node server application invoking client callback ignored

I'm trying to run an external command from node on a server and have the output of that command sent back to the client line by line. That is, I want to send the output as it is produced, not when the command has finished.

The server side code works...

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

Install Node.js to install n to install Node.js?

I have a problem understanding the use of n. Basically, it is clear that it is a version manager for Node.js such as nvm.

But in contrast to nvm, which is basically a shell script, according to the documentation you are encouraged to use npm to...

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

confusion between Jade and Handlebar

Trying out backbone+express with Jade as default templating.

Following a tutorial here(Great tutorial)


Many tutorials about backbone uses underscore template or handlebar to compile and render view.

I was using Jade as default template...

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

How to set Meteor WebSocket port for clients?

How can I set the port WebSocket will be listening on? I'm trying to deploy Meteor on OpenShift, but there they have a nodejs-proxy server that listen on port 8000 instead 80, and redirect to my Meteor daemon. It is working since a manually created...

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

Asset Managers with minify & grouping options for standard HTML sites

I mainly work with the CakePHP framework, with the use of the very cool added plugin that minify and groups selected assets into one whole file, therefore making only one HTTP request for the whole site.

I am now working with designers, who although...

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

Wrapping NodeJS's net.createServer into a producer of customised sockets

I'm trying to make a function which behaves like net.createServer, except that it returns objects which are wrappers around sockets, instead of sockets.

(The point of these will be to do automatic data conversion.)

My latest attempt looks...

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

Mongoose hook "pre/post save" not working for findOneAndUpdate

I'm using nodejs + express + mongoose.

I add "pre/post save" hook for a module, it works fine with save function. But when I use findOneAndUpdate (create if it not exist), the hook is not called.

It seemed the only way I can do is separate...

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

How to query NodeJS stream 'meta data'?

I have a program with several long pipes with several transforms.



What is the best way of adding/reading meta data to/from the pipe?

For example: ta accumulates and breaks packets...

Read the entire recipe Recipe added 1 day ago