Latest Node.js Recipes

Sort in MongooseJS 3.3.1 in ascending and descending order

I have REST based API in NodeJS and MongooseJS ODM. To GET the list of departments URL is http://localhost:25718/Department?SortBy=Name&SortType=asc(desc-for descending). And sorting code is

 var Query = Department.find();
 if(req.query.SortBy) {
   ...

Read the entire recipe Recipe added 51 minutes ago

NodeJS: process.nextTick vs Instant Callbacking

I write lots of modules which look like this:

function get(index, callback) {
    if (cache[index] === null) {
        request(index, callback); // Queries database to get data.
    } else {
        callback(cache[index]);
    }
}

Note: it's a bit...

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

insert some data after response on node.js

I wrote a website tracker for internal use, since Google Analytic don't meet the requirement.

I use node.js with Express to develop that tracking system. Everything works well so far. But I want to confirm is, if there is some problem behind if I...

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

Two way communication with server side objects for web-application development

Background

My background is high scale object oriented middleware and Applications development for embedded devices and desktops with C++. Now we need to create a high scale web-app for our startup.


Question

Request-response based and...

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

Set content length of request based on content in node

How to set the content length of the request based on the content?

For example:

POST /Display HTTP/1.0
Content-Type: application/json
Content-Length: 125

{"QueryReq":
  {
    "Tid": "Tid-123456",
    "SessionId" : "1350711351232058820" 
  }
}

On...

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

js Function queue

So essentially what I'm trying to do is have a queue of functions that I can add to. These functions are suppose to be drawing things to a canvas like in an requestAnimationFrame.

What I've tried:

var drawQueue = [];
function animate() {
    while...

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

node.js passing variables

I am looking for some direction here from some seasoned node.js programmers. The biggest issue I am running into is passing around variables into separate modules. For example in my server.js I have the following:

var db =...

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

How to implement jQuery direct upload to Cloudinary on node.js

I'm trying to implement direct uploads to Cloudinary via their jQuery plugin to a Node.js application, and am wondering if anyone can help me close some gaps in their examples.

Here's the blog post that explains how to do it:

...

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

Mongoose.js Error saving document with unusual but seemingly acceptable string value

I'm getting an error saving a document to mongoose.js from Node.js. This code has worked fine for a while but it's now causing a problem with Javascript objects with key values that seem fine otherwise.

What's being saved is a document where one...

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

how to generate video thumbnail in node.js?

am building a app with node.js, i successfully uploaded the video but i need to generate a video thumbnail for it, currently i use node exec to excute a system command of ffmpeg to make the thumbnail

   exec("C:/ffmpeg/bin/ffmpeg -i Video/" + Name  +...

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

Node.js scraping, converting image src -> full URL

I'm using Cheerio (https://github.com/MatthewMueller/cheerio) to scrape websites and get images for a project I'm working on. I'm wondering if there's an easy way with Node.js (or another package) to convert the $(img).attr('src') to a fully...

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

Error running node app in WebMatrix

I installed WebMatrix and followed these instructions to install IIS 7 on my Windows 7 machine.

When I click 'Run' to run my express node app, the browser pops up and tells me

The iisnode module is unable to start the node.exe process. Make sure...

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

Nodejs: iterate over req.files properties

I'm quite new to nodejs and sometimes I come across difficulties :) So for example. I'm sending an image file via AJAX and recieve it successfully in my app.

console.log(req.files) prints:

{
    img_1351078491675: {
        size: 354683,
       ...

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

Mongoose populate embedded

I use Mongoose.js and cannot solve problem with 3 level hierarchy document.

There 2 ways to do it.

First - without refs.

C = new Schema({
    'title': String,
});

B = new Schema({
    'title': String,
    'c': [C]
});

A = new Schema({
   ...

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

Rollback on node.js install on Windows 7 x64 PC

I've been trying to get node.js installed on my home PC for a while now with no luck. I've tried different versions for the past couple months and no matter what I try it starts rolling back the install at "Creating shortcuts" and it fails to install....

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

Meteor blocking clarification

According to the meteor docs, inserts block:

On the server, if you don't provide a callback, then insert blocks until the database acknowledges the write, or throws an exception if something went wrong. If you do provide a callback, insert...

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

Node+MongoDB: find in collection

I just don't know why it's not working(( val.instruments is undefinded.

function getInstruments(callback) {
    db.collection("settings", function(error, settings) {
        settings.find({ "settings" : "settings" }, function (err, val) {
           ...

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

Running arbitrary MongoDB scripts through Node.js driver

I have a combination of complex MongoDB scripts that runs from the command line as follows:

$ mongo mydb config.js task.js

Since I can't run shell scripts in my server environment and need to schedule the above task, I figured I could simply...

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

Express + Socket.IO + RabbitMQ (node-amqp)

I'm having a hard time putting all these three together, probably because I'm not getting properly the concept of routing with Express.

I have a RabbitMQ queue with event updates. We can recognize these events by their id. So I want to get on a given...

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

How to make a node.js server with rooms scalable

I have designed a Node.JS server that allows users to log in, join a room and exchange data with other users in this room using websockets. However I am now looking for a way to make this setup scalable.

I spend all afternoon researching various...

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

Handling assets in node.js with express

ok so what I am trying to do is manually handle my assets when using express. What I mean is that I do not what to have to have every stylesheet/javascript file on every page. So I wanted to be able to specify in each route whether I wanted to use...

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

Prompt a csv file to download as pop up using node.js and node-csv-parser (node module)

Recently I have started working with node.js. While going through a requirement in one of my projects I am facing an issue where I should be able to write some data to a csv file dynamically and let it prompt as a popup to download for user (with save...

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

FileReader.readAsDataURL upload to express.js

I have the following code to upload to my Node.js/Express.js backend.

var reader = new FileReader();
reader.readAsDataURL(file);

reader.onload = function (e) {
  var result = http.post('/files', e.target.result);
  result.success(function () { 
   ...

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

nodejs middleware delaying requests

I'm writing a middleware which will perform a sequence of actions. After the sequence is done, I want the middleware to call next(). from this point on the middleware is redundant. I've written the following code: (here the sequence of actions is...

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

Testing Errors passed back with Callbacks with mocha and should

UPDATE 2-July-2013

Using the last approach with the wrapped anonymous function can introduce some strange testing behavior. If you expect a thrown error, but there is an error in the actual execution the test will pass, but will pass on any error...

Read the entire recipe Recipe added 1 day ago