Latest Node.js Recipes

Is it possible to import a script from an URL using node.js?

I'm currently trying to import one of my scripts from an URL, but the require function doesn't appear to be working in this case.

var functionChecker = require("http://javascript-modules.googlecode.com/svn/functionChecker.js");

This is an excerpt of...

Read the entire recipe Recipe added 58 minutes ago

Load Nodejs Module into A Web Worker

I'm intending to use web worker inside my Node.js application for some concurrent tasks. However since the 'webworker-threads' module follows the implementation of HTML5 web worker, requiring Nodejs modules like require("fs") inside web worker does...

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

Node.js TCP socket sessions

I have multiple clients connecting to a Node.js TCP socket server from an app. I would like to know a secure way of managing their session.

Username + password is passed over the socket to the server. The server confirms this is correct.

I believe...

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

do any mongodb ORMs allow you to alias fields?

I just watched this: http://blog.mongodb.org/post/38467892360/mongodb-schema-design-insights-and-tradeoffs-from

One suggestion that came out of the talk: in docs that will be replicated many times, try to make the field names as small as possible:

...

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

Yeoman inside ExpressJS

I'd still like to try to get an example running w/ Yeoman and Express.

I tried the following and it worked "okay", but I'm stuck merging the routes. (over simplified for readability)

mkdir test
cd test
express
mkdir app
cd app
mkdir js
cd js
yeoman...

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

Mongodb (mongolab) Node.js finding nothing on a collection

I'm a big Node.js and Mongo newbie, so please be gentle.

So here's my Node.js app:

var mongo = require('mongodb');
var Server = mongo.Server;
var Db = mongo.Db;

var server = new Server('hostname.mongolab.com', 666, {auto_reconnect : true}, {w:0,...

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

Combine Yeoman Server and Node Supervisor

I'm using Yeoman to develop the frontend html app (backbone and bootstrap) and would like to use the same folder for backend development for the api (node, express, mongodb).

What I would like to do is to have the browser refreshed no matter what...

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

Grouping registering users into metro areas

I have to group all users registering to my site into metro areas. A metro area is defined a proximity to one of the world's 100 most populous cities.

In my proposed solution the user will be presented with 2 dropdowns. One for country and one for...

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

node.js Synchronous version of http.get

I want to write a tester that will test a http server I wrote for class. and I need a synchronous version of http.get/http.post

I wanted to make an object with a "test" method that will return true or false if the test passed but found no way to get...

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

Reduction of CPU utilization on a nodejs server

I am looking into interesting ways to reduce CPU utilization on a NodeJS server.

During my research I have found the following article: http://engineering.linkedin.com/nodejs/blazing-fast-nodejs-10-performance-tips-linkedin-mobile

These are all...

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

Mongoose: Get full list of users

I have tried to use Mongoose to send the list of all users as follows:

server.get('/usersList', function(req, res) {
    var users = {};

    User.find({}, function (err, user) {
        users[user._id] = user;
    });

    res.send(users);
});

Of...

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

Script served by Typescript and ExpressJs is not run

I would like to translate my minimalistic server from Coffeescript to Typescript. Here's the original code:

express = require("express")
app=express()
app.use(express.static(__dirname))
app.set("views", __dirname + "/views")
app.set("view engine",...

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

What would be the equivalent of Pythons "pickle" in nodejs

One of Python's features is the pickle function, that allows you to store any arbitrary anything, and restore it exactly to its original form. One common usage is to take a fully instantiated object and pickle it for later use. In my case I have an...

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

Can't install js-bson

I am using Windows 7 64bit, trying to install bson as a dependencie of mongodb. I get this error:

npm WARN package.json Wochenplaner@0.0.1 No README.md file found!
npm http GET https://registry.npmjs.org/bson
npm http 304...

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

most visited in mongo

how to get the most visited pages / entries per day / week / month with mongodb

This solution is good for stats, but no for list of most visited entries MongoDB Approaches for storing large amounts of metrics / analytics data

map/reduce is too...

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

Node.js TCP Socket Server on AppFog

Given the following simple TCP socket server running on AppFog that echoes back whatever the client sends.

var net = require('net');

var server = net.createServer(function (socket) {
  socket.write('Echo server\r\n');
  socket.pipe(socket);
});

var...

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

Is it possible to share data between the client and the server using node.js?

Is there any way to share data (including objects) between the client and the server in node.js? I used to rely on a module called now.js that was designed for this purpose, but the project has been discontinued, and I'm trying to find a replacement....

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

How to link to JavaScript file in node_modules?

I want to link to /node_modules/jade/runtime.min.js client-side -- how do I make it publicly accessible?

Do I create a app.get for it somehow?

app.get('/js/jade-runtime.js',<what goes here?>)

Or can I modify the static thing to allow it to be...

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

how can i restrict the access to only ajax requests?

i load inicio.jade with ajax req

$.ajax(
{
    url:'/inicio',
    cache: false,
    type: 'GET',
}).done(function(web)
{
    $('#contenido_nav_principal').fadeOut(600,function()
    {
        $('#contenido_nav_principal').empty();
       ...

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

Does Meteor have a REPL?

Does the Meteor framework come with a REPL or console of some kind? If not, any idea how to use the Node.js REPL in a way that bootstraps the Meteor environment?

I'm essentially looking for something like the rails console, or the javascript console...

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

Building a javascript app shared across node.js and client side

I am used to cross platform dev. On the C/C++ side it's simple, but I'm stuck with a problem when using javascript. I want to be able to reuse code from my web-service on the client-side. Currently node.js requires me to write my program in a most...

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

node.js only passing filled out values to mongodb

I'm working on a project in node.js, mongodb, and express that has to deal with transactions. I can hard code the variables to be put into mongodb, but if not all the fields are being filled out (not all are required) then I'm just putting empty data...

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

Parse stream to object in Nodejs

I am trying Get an object from Amazon S3 storage in Node.Js.

And this perfectly works when I am saving it to a file.

amazon.getObject = function () {

    var options = {
        BucketName : 'mybucket',
        ObjectName : 'path/to/my.json',
     ...

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

Node.js application throwing error on registring module

I am following Steven Sanderson's videos here to get started with NodeJS. I have installed EJS and ejs-middleware modules. The server.js is like following:

var express=require('express'),
app = express(),
ejsMiddleware =...

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

403/Forbidden error custom page with Express 3 / Node

How can I create a route that will handle 403 errors from Express? I have default routes to catch 404/500 but it seems to stop before ever going to the router. Just stack dumps to screen.

Read the entire recipe Recipe added 1 day ago