Latest Node.js Recipes

How to post a form from HTML into Node.js file

I've a HTML file named index.html, and a Node.js files named server.js and logic.js.

server.js is reponsible for creating the server and loading index.html file. The HTML file displays a form asking for any action(ex: username), then it posts this...

Read the entire recipe Recipe added 35 minutes ago

How to send a request to another domain attaching audio file using node.js?

Here's the flow that I am trying to achieve:

1) User uploads an audio file to server1
2) Server1 receives that audio file and sends it to server2 in different domain
3) Server2 converts audio file to text
4) Server2 responds back to server1 with...

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

nodejs filtering inputs

In PHP to filter inputs data I use functions htmlspecialchars and mysql_real_escape_string. Is there any functions like this in nodejs?

I need to check all inputs in my rounter functions to prevent hacker attacks like xss. Thanks!

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

How to update node.js and CoffeeScript version via terminal on mac?

My system node.js version is v0.6.1 but the current stable version is v0.6.7. My system CoffeeScript version is v1.1.2 but the current stable version is v1.2.0

How could I update the node.js and CoffeeScript via terminal on mac( using mac )? I am...

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

Node.js buffer.copy() api looks very strange and not similar to memcpy in C

I am kind of confused by the Buffer.copy api in node.js in the meaning of the buffer indexes. I was expecting it to be similar to memcpy in C/Unix but it does not seem to be the case

As per the API doc and an example provided in ...

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

jsdom form submission?

I'm trying to use the Node.js packages request and jsdom to scrape web pages, and I want to know how I can submit forms and get their responses. I'm not sure if this is possible with jsdom or another module, but I do know that request supports...

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

Can I use server-side Javascript to code views in Razor?

I've recently partnered up with a front-end developer with no C# experience, who is going to be coding the views for an ASP.NET MVC3 application I am building.

Since most web developers know Javascript, I thought it would be awesome to have him do...

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

NodeJS + http-proxy - Object has no method 'resume'

The strange thing about this problem is that I had a working example (albeit with no data being transferred post-handshake) before I went away from my desk, and now I can't seem to get this working properly, despite reverting the few minor changes I...

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

How do I get a snapshot still of a video in nodejs?

I am trying to write a nodejs server that will take a time input (possibly part of url path) and then provide a still of the video frame at that time index as a jpeg picture.

I can do this easily in plain Javascript, but I cant see a way to do this...

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

Mercurial HG library for Node.js for local repositories

I am looking for library written for Node.js which I will be able to use to manage from the web application my local repositories created in Mercurial HG.

Anyone implemented something like that?

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

How to scale node apps on heroku?

What is the best practice to scale a node app on Heroku?

When should I increase dynos, when workers?

The Heroku website says

Crank your web dynos to increase HTTP performance.
Crank your worker dynos to empty the queue faster.

I am not quite sure...

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

Upload file with connect-form

I tried to upload file with connect-form, but if i want to upload i must disable bodyParser() in app.js, if i keep bodyParser() it will have error : loading forever
This is my app.js:

    app.configure(function(){
app.set('views', __dirname +...

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

NodeJS and MongoDB: Is there a way to listen to a collection and have an callback be called when a collection has new document?

Is there a way to listen to a MongoDB collection and have a callback gets triggered when a collection has a new document?

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

Is /data/data/ a reliable assumption for installation path?

I am messing around with node.js on Android through this project, and I need a way to deploy js files to a private directory (to hide the source code, and prevent users from tampering) which also physically exists on the filesystem (an apparent...

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

Socket.io - slow connection

I use node.js and socket.io.

I am using the latest version socket.io.

I have a problem with connection in socket.io.

In Internet Explorer and Opera connection lasts seven seconds.

In firefox and chrome connection is good.

I use transports:...

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

Volume slider control with socket.io - Too much data

I am trying to create a volume control with the help of a range input field (jQuery) and socket.io.

I am using this code to set the volume on all listening devices.

socket.on("setVolume", function (data) {
 ...

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

Can't emit from method defined outside of socket connection

I'm trying to use a custom object's method to emit to a socket connection. The object is defined outside of the socket connection, but then instantiated inside of it. Code and error follows.

app.js

...
io.sockets.on('connection', function (socket)...

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

Mongodb, NodeJs and Mongoose: Get inner object where inner Object value='search value'

Example first:

{ "_id" : ObjectId("4f086809bf28fd7bb56e6059"), "admins" : [ "4ef8e785b2694c3649000001" ], "pages" : [
    {
        "pagename" : "home",
        "title" : "homepage",
        "default" : true
    },
    {
        "pagename" :...

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

How to make jsdom more resource efficient

I am using my node.js and jsdom based getratings.js script from the getratings github project to scrape user reviews from sites like NewEgg, BestBuy etc.

The script is hosted on an EC2 micro instance. It works fine until more than around 12...

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

How do I write javascript web socket code that will run in chrome and in node.js?

The answer to this question boils down to two things: 1) Will it be simpler to use BOSH or web sockets, given the limitations of node.js, and 2) How can I structure code so the same javascript file runs equally well in the browser as it does in Chrome...

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

Node.js: ECONNREFUSED on Port 80

I've written a web-server using Node.js. When I tried to test my server with the tester I've written for it, I succeed only if the port I'm using for the server is not 80. I've checked on netstat, and no other application is using port 80. The error...

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

layouts in expressjs

I want to use 2 layouts for main page and admin page
What should i configure my code to do that?
here is my current code configure

app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine',...

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

List of connected clients username using socket io

I've made a chat client with different chat rooms in NodeJS, socketIO and Express. I am trying to display an updated list over connected users for each room.

Is there a way to connect a username to an object so I could see all the usernames when I...

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

Nodejs Modules Implementation

How to implement a module say 'test' which exposes two functions getter and setter to get and set its member data in nodejs?

The trick is data set via setter from a module say 'a' over 'test' should be accessible to module 'b' via getter of...

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

Is there any documentation on the package.json file?

Here's an instance of the package.json file that express.js generates

{
    "name": "packagename",
    "version": "0.0.1",
    "private": true,
    "dependencies": {
        "express": "2.5.5",
        "stylus": "0.22.2"
    }
}

It's fairly obvious...

Read the entire recipe Recipe added 1 day ago