Latest Node.js Recipes

Initializing server for displaying hello using node.js cannot resolve

I am trying node.js as a possible technology as oppose to traditional php server for my school project, I am trying to initiate a server that prints hello, but for some reason my localhost won't display that, it only waits for localhost for a long...

Read the entire recipe Recipe added 20 minutes ago

Is it possible to get the model from the document in mongoose?

var UserSchema = new Schema({...}); // Schema
var User = mongoose.Model('User', UserSchema); // Model
var user = new User({...}); // Document

given just the document (user in this case), is there an easy way to get the model (User in this case)...

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

GridFS: Clean out all unreferenced files

I have just moved towards storing things in my GridFS in MongoDB. During testing, I noticed many files are being created but not deleted properly. I have a collection users, which has a field avatar. It contains the ObjectId of the file.

Now I'd like...

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

Coffeescript + Express: unexpected ,

I'm learning to make an app on Express.js using Coffeescript. I have uploaded my code at: https://github.com/findjashua/contactlist

When I try to run the app, I get the following error:

app.coffee:11:24: error: unexpected ,
res.send 'Hello World'
  ...

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

How to perform SQL Joins and Relations in Sails.js and Waterline?

Can anyone guide me on how to setup relational schema & performs joins in sails.js?

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

Accessing mongodb(mongoose) and then do something with it

So I have a collection foo. I use ajax to access it. In the success portion I have a for loop

function(data){
  for(var i in data){
    var project = data[i]
  }
}

So now the collection is connected to project. How do I access project to get the...

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

How to write a simple jasmine test for a MVC Controller function (sails.js)

I wanna do a TDD. However, I am going to write test on my controller function for my sails.js project

/*---------------------
    :: Gamble
    -> controller
---------------------*/
var GambleController = {

  index: function(req, res) {
     ...

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

Node/Express server-side include equivalent for static files

Express has no equivalent to server-side includes for static client-side content.

Can someone recommend a good solution for robustly replicating this functionality (for web age headers and footers mostly), but without resorting to a full-scale HAML...

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

Release required module from Node.js

How can one release a Node.js module during runtime in order to save memory or improve the overall performance.

My application dynamically loads modules in Node.js during runtime, but does not unload any of them. I'm looking for such functionality...

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

Nodejs mysql module not connecting to database

I'm trying to do a simple test query to get the node mysql module working but it's not connecting to the database. Here's my code in app.js:

var http    = require('http'),
io      = require('socket.io'),
sys     = require('sys'),
express =...

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

How to delay and consolidate pub/sub with Redis/Node/Rails

I got a RubyOnRails application that uses a Node.js/Socket.io server to push out trading information to all clients connected. Whenever a trade is executed the client screens get updated with the information of the last trade.

As the trading...

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

How to extract an array of fields from an array of JSON documents?

I have 2 mongodb collections, stu_creds and stu_profile. I first want to retrieve all the student records from stu_creds where stu_pref_contact is the email and then for those stu_ids I want to retrieve the complete profile from stu_profile. The...

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

Coffeescript + Express.js : cannot call method 'sliced' of undefined

I'm making my first app in express.js and coffeescript. The code is at: https://github.com/findjashua/contactlist

When I try to run it, I get the following error:

/Users/jashua/local/lib/node_modules/coffee-script/lib/coffee-script/helpers.js:216
 ...

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

node.js sendgrid how to attach a pdf

Im using sendgrid to send email in my node.js application. Every combination I try to attach a pdf ends up with my attached pdf being unreadable.

i've tried:

fs.readFile('public_html/img/Report.pdf',function(err,data){
        var base64data = new...

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

REST API measuring server-side response times (performance).

I developed some rest APIs based nodejs, I want to test the performance of the APIs. Is any tool can easily count the time of each API call?

Or how to implement measuring of time required for REST API to response on requests.

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

Asynchrony in a database query

I have a problem when working with node.js. All have tried to describe in comments to the code.

The first thing I need to build an array of dialogs with some information about the interlocutors and the last meggase.

IM = {
    iUserId: false,
   ...

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

Documentation or examples for ''newSession'' and 'resumeSession' events in TLS module for node.js

I am having a hard time finding documentation and examples for the 'newSession' and 'resumeSession' events for the TLS module in node.js.
Any links or help in this direction is appreciated. I need to know more about these events in order to implement...

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

github Oauth for node.js/express application private email

I am using passport-github strategy for my express application. This works fine when the user has set a public email address, but does not work if there is no email!

if process.env.GITHUB_ID? and process.env.GITHUB_SEC?   
  passport.use(new...

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

Getting Fatal error: spawn ENOENT

I want to create window installer but facing some problem from last 4 days on exectuion of common.js facing this error.

What i analyzed:

child = child_process.spawn(cmd, args, opts);
children.push(child); 

..is not executing properly. Can someone...

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

Time taken to resize the image in imagemacik,imagemacik-native and graphicsmagick?

I need to resize the image.So in the below three libraries how to find which one is taking less time to resize the image.

https://github.com/rsms/node-imagemagick

https://github.com/mash/node-imagemagick-native

https://github.com/aheckmann/gm

...

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

Execution of a node package command not working on Ubuntu 12.04 RTS

I have created a npm package, Here is the package.json:

{
  "name": "docxgen",
  "version": "1.0.5",
  "author": "Hans Thunam <hans.thunam@gmail.com>",
  "description": "A docX Generator",
  "contributors": [ 
    {
      "name": "",
      "email":...

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

Convert String to Array of JSON Objects (Node.js)

I'm using Node.js and express (3.x). I have to provide an API for a mac client and from a post request I extract the correct fields. (The use of request.param is mandatory) But the fields should be composed back together to JSON, instead of...

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

Android constant connection website

I'm looking for options for communication between an Android device - running a native app - and a website.

In basics, the Android device is just a sensor for movement, while the website is the receiving end and will process the sensor data. The...

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

mongodb - concept of batches

I am using MongoDB with Node.js and have got stuck at a particular scenario.

Let's say I have a document store called samples which I use to collect some time stamps from the client machine.

I want to introduce the concept of batches

More...

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

One npm module for different instruction set

I have a project developed on node.js. Development takes place on two different machines: one bit x32, on the other - x64. The problem is that some npm-modules have conflicts if they run in different environments.

For example, dNode. I installed it...

Read the entire recipe Recipe added 1 day ago