Latest Node.js Recipes

Node.js doesn't have a good ORM for managing MySQL schema/migrations...so can I use SQLAlchemy to manage it?

I need to use Node.js, but it doesn't have a good ORM for MySQL. So I'm planning on using SQLAlchemy to define my schema. And then use node-mysql to do low-level queries (of course, I wouldn't be able to use SQLAlchemy's query language coz it's in...

Read the entire recipe Recipe added 35 minutes ago

Do these two node.js modules do the same thing?

https://github.com/caolan/async

https://github.com/maxtaco/tamejs

These are two modules. To me, it seems like the same thing, right?

Or...are they used in different situations?

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

Detect enter in keypress event node.js rawmode

I am writing a simple commandline tool to allow commandline input to a node.js server. I am trying to make a buffer, so the user can press up and see the last command. To do that I have set

require('tty').setRawMode(true);

And detects all keypress...

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

NodeJS response.write inside callback

I'm using a route to process a url. The functions fire as expected. What I'm trying to do is use the response.write() inside of a call back. I understand this isn't working because the call back doesn't have access to the same variables as the...

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

lots of simultaneous connections

I'm working on chat application. The underlying server uses Node.js and the client/server communication goes via WebSockets.

So the question is: how many simultaneous connections can such a server handle (without visible lags)? Of course...

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

Using uglifyjs with nodejs in windows

I installed nodejs from nodejs.org on my windows box.

The path to node is C:\Program Files (x86)\nodejs\node.exe

I can run node in command prompt correctly, my question is...I cloned uglifyjs to C:\gitrepos\uglifyjs\

Now I am trying to figure out...

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

Require() in REPL does not seem to work properly

Problem: I just started out in node.js and when using REPL to require a module, its function keeps showing undefined. Where did it go wrong?

Also, why does the var s = require('./simple'); line result in an undefined response? I am using node...

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

Error: parser error, 0 of 4344 bytes parsed (Node.js)

I am trying to use an upload program to upload my files. The code that I use is

app.post('/photos',loadUser, function(req, res) {
  var post = new Post();
  req.form.complete(function(err, fields, files) {
    if(err) {
      console.log(err);
     ...

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

what does -I or "unshift a path mean" in expresso?

I'm not sure I understand what "unshifting a path" with -I means in expresso. Does that mean if I run expresso with the switch as such

expresso -I myCode test/*

That when I normally use require statements in my tests in my test folder such...

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

Cleaner way to perform several redis queries within node.js

I did some node.js code to retrieve data within a redis DB but I'm not really happy and I'd like to improve it...
Basically, I have a record "people" in my redis db. From "people" I get a list of "person:i" (i being an integer) and, for each...

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

In Node.js, why can't I handle request in request.addListener's callback?

In my node.js server listener callback(http.createServer(cb(response, request)), I write those code:

if(request.url == "/upload") {
  request.addListener("end", function(){
    console.log("UPLOAD");
    var form = new formidable.IncomingForm();
   ...

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

File upload in node.js just keeps uploading indefinitely?

I'm following this tutorial: http://vimeo.com/17442755. It teaches you how to upload files using node.js.

This is the full code in app.js:

var express = require('express');
var multipart = require('./multipart');
var fs = require('fs');

var app =...

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

Understanding v8/Node.js profiling report

I'm trying to use --prof option with Node.js. So I get the following report after linux-tick-processor:

 [Shared libraries]:
   ticks  total  nonlib   name
  20736   94.8%    0.0%  b78a5000-b78a6000
    574    2.6%    0.0% ...

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

How can I get the URL of an <a href="http://www.mysite.com"> in JavaScript?

I'm processing some text in JavaScript (using Node, so please no jQuery). I want to extract all URL's that are in <a> tags on the page. How can I do this in JavaScript?

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

mongodb installation Fail

I needed to learn node.js and mongodb which requires me to use my mac osx, so I am new to the shell command line interface.

Problem: When I followed the instructs on mongodb website and installed mongodb and tried to run, I get the following error...

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

Is it a bad idea to use port 443 for Socket.IO?

According to the following post, some networks only allow a connection to port 80 and 443: Socket IO fails to connect within corporate networks

Edit: For clarification, the issue is when the end user is using a browser at work behind a corporate...

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

mongoose updating a field in a MongoDB not working

I have this code

var UserSchema = new Schema({
    Username: {type: String, index: true},
    Password: String,
    Email: String,
    Points: {type: Number, default: 0}
});

[...]

    var User = db.model('User');
   /*
    * Function to save the...

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

node.js websocket send custom data

I found a great websocket tutorial. If the server get a message, then the server decodes it, and writes to the console, and after that the server sends it back to the client.

  var firstByte = data[0],  
      secondByte = data[1];

  if(!(firstByte...

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

Security in NowJS

I found NowJS and at the first sight, it looked very cool. I played around with the tutorials and it worked well.

Now I'm asking myself: How safe is this? Isn't it possible to inject XSS? The security issue is the biggest obstacle to use it in my...

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

Getting Time-Out Error While Posting Data

js.I am trying to create a file upload using node.js and mongodb.I am getting timeout error in posting data.The code that i use is:

app.post('/photos/new', function(req, res) {
  var photo = new Photo();
  req.form.complete(function(err, fields,...

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

How to return status code from function in Node.js

I have such function:

function getStatusCode(site){
    var options = {
        host: "127.0.0.1",
        port: 8000,
        path: site,
        headers: {
                    Host: site
            }
        };

    var status;

   ...

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

MongoDB, indexing arrays of ids?

Using MongoDB...

If I have an array of ids in one field, can I quickly query it for containing id_x?

If so how would I insure and index on it so it is as fast as possible?

Thanks!

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

Call function by (string) name on node.js

At the client side you do it via window["functionName"](arguments);. How it would be possible in node.js server-side code?

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

node.js send more datas

I'm working on a project, where the server send a string to the client, between binary datas

socket.write('\u0000', 'binary');
socket.write('welcome', 'utf8');
socket.write('\uffff', 'binary');

It works, but it sends one after another. It is...

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

Remove a value from an array in CoffeeScript

I have an array:

array = [..., "Hello", "World", "Again", ...]

How could I check if "World" is in the array? Then remove it if it exists? And have a reference to "World"?

Sometimes maybe I wanna match a word with a regexp and in that case I won't...

Read the entire recipe Recipe added 1 day ago