Questions tagged [node.js]

Node.js is an event-based, non-blocking, asynchronous I/O runtime that uses Google's V8 JavaScript engine and libuv library. It is used for developing applications that make heavy use of the ability to run JavaScript both on the client as well as on the server side and therefore benefit from the re-usability of code and the lack of context switching.

Node.js is an event-based, non-blocking, asynchronous I/O (input/output) runtime that uses Google's V8 JavaScript Engine.

, commonly just called Node, is often used for developing applications that rely on the ability to run both on the client and server side. Running the same language on both the client and the server benefits from improved code reusability and less context switching.

A notable feature of is that it is non-blocking – if one task stalls or pauses for an I/O operation, another can take over while idle. This allows for high efficiency as the program as a whole never has to idle and wait for one task to finish. Libraries such as async take advantage of this capability. More information can be found here.

It's also possible to use mature JavaScript frameworks like YUI and jQuery for server-side DOM manipulation in .

To ease the development of complex JavaScript further, Node.js supports the CommonJS standard that allows for modularized development and the distribution of software in packages via the Node Package Manager (NPM).

Download node.js:

Applications that can be written using Node.js include, but are not limited to:

  • Static file servers
  • Web Application frameworks
  • Messaging middleware
  • Servers for HTML5 multi player games, or streaming audio/video
  • Real time applications
  • Cross-platform programs

When asking questions about Node.js, you should:

  1. Make sure to check the official API documentation before asking, your question might be trivial.
  2. Isolate the problem and reproduce it with as little code as possible.
  3. If the question has nothing to do with anything that's specific, please consider asking it as a question instead.
  4. Mention which version of Node.js you are running. When in doubt, use node -v or node --version.
  5. Make sure to only use the tag, since is ambiguous.

Interesting Questions and Answers

Useful Links

Tutorials, Guides and Books

Talks, Presentations, and Podcasts on Node.js

Free Node.js Books and Resources

Chat Room & Mailing list

Logging

  • pino - Extremely fast logger inspired by Bunyan.
  • winston - Multi-transport async logging library.
  • console-log-level - The most simple logger imaginable with support for - log levels and custom prefixes.
  • storyboard - End-to-end, hierarchical, real-time, colorful logs and stories.
  • signale - Hackable console logger with beautiful output.

Official logo

Official logo

Node.js is copyrighted by the openJS Foundation

466830 questions
87
votes
3 answers

Node.js: inspect what's left in the event loop that's preventing the script from exiting naturally

Node.js script won't exit if there's callbacks left in the main event loop. While one could forcefully terminate the script by calling process.exit() or throwing exceptions, it is recommended to let the script terminate "naturally", by always doing…
KFL
  • 17,162
  • 17
  • 65
  • 89
87
votes
9 answers

npm install gives error "can't find a package.json file"

npm install / npm install -g command is not working in Windows 7 Node.js is installed properly, node.js version is v0.10.28 Couldn't read dependencies ENOENT, open '"filepath"\package.json' This is most likely not a problem with npm itself. …
Subhajit Panja
  • 1,230
  • 1
  • 9
  • 22
87
votes
4 answers

node-mysql multiple statements in one query

I'm using nodejs 10.26 + express 3.5 + node-mysql 2.1.1 + MySQL-Server Version: 5.6.16. I got 4 DELETE's and want only 1 Database Request, so i connected the DELETE commands with a ";"... but it fails always. var sql_string = "DELETE FROM…
L.rp
  • 893
  • 1
  • 7
  • 11
87
votes
9 answers

Could someone explain what "process.argv" means in node.js please?

I'm currently learning node.js, and I was just curious what that meant, I am learning and could you tell me why this code does what it does: var result = 0; for (var i = 2; i < process.argv.length; i++){ result += Number(process.argv[i]); } …
Justin R.
  • 895
  • 1
  • 6
  • 4
87
votes
3 answers

Keeping open a MongoDB database connection

In so many introductory examples of using MongoDB, you see code like this: var MongoClient = require('mongodb').MongoClient; MongoClient.connect("mongodb://localhost:port/adatabase", function(err, db) { /* Some operation... CRUD, etc. */ …
Lew
  • 1,431
  • 1
  • 16
  • 22
87
votes
13 answers

Installing and Running MongoDB on OSX

If someone can provide some insights here I would GREATLY appreciate it. I had a express/node.js app running on MongoDB locally successfully, but upon restarting my computer, I attempted to restart the Mongo server and it began giving errors and…
user2517788
  • 911
  • 1
  • 7
  • 8
87
votes
7 answers

How to npm install global not as root?

I'm on a unix box where I don't have root access. I changed my .npmrc file (in my user's root directory) to: prefix=~/global_npm Now when I do "npm install -g packagename" it installs inside my global_npm directory. Which is good. And then I gave…
Shai UI
  • 50,568
  • 73
  • 204
  • 309
87
votes
2 answers

How to test nodejs backend code with Karma (testacular)

How do I setup Karma to run my backend unit tests (written with Mocha)? If I add my backend test script to the files = [], it fails stating that require is undefined.
Sylvain
  • 19,099
  • 23
  • 96
  • 145
87
votes
3 answers

nodejs - http.createServer seems to call twice

If I write the following program in node: http.createServer(function (req, res) { if( req.method == 'GET' ) { var body = ''; req.on('data', function(data) { body += data }); req.on('end', function() { console.log('request…
Will
  • 5,370
  • 9
  • 35
  • 48
87
votes
8 answers

Express.js routing: optional splat param?

I have a route that looks like this: app.all('/path/:namedParam/*splat?',function(req,res,next){ if(!req.params.length){ // do something when there is no splat } else { // do something with splat } }); however, this doesn't work - if…
Jesse
  • 10,370
  • 10
  • 62
  • 81
86
votes
1 answer

Get the node.js version at runtime

I'm having some compatibility issues with old versions of node.js. Is there any way to get the node.js version at runtime?
Peter
  • 5,138
  • 5
  • 29
  • 38
86
votes
2 answers

Node.js "require" function and parameters

When I do: lib = require('lib.js')(app) is app actually geting passed in? in lib.js: exports = module.exports = function(app){} Seems like no, since when I try to do more than just (app) and instead do: lib = require('lib.js')(app,…
user885355
  • 3,369
  • 4
  • 19
  • 10
86
votes
7 answers

Is there a way to compile node.js source files?

Is there a way to compile a node.js application?
Mark
  • 67,098
  • 47
  • 117
  • 162
86
votes
5 answers

How do I query for distinct values in Mongoose?

I have a problem where I want to be able to get all the unique cities for a collection, and my code looks something like this: var mongoose = require("mongoose"), Schema = mongoose.Schema; var PersonSchema = new Schema({ name: String, …
Kit Sunde
  • 35,972
  • 25
  • 125
  • 179
86
votes
4 answers

Write formatted JSON in Node.js

I'm using Node.js to POST JSON to PostBin but the data is being wrongly formated (as you can see here: http://www.postbin.org/1cpndqw). This is the code I'm using for tesT: var http = require('http'); var options = { host: 'www.postbin.org', …
donald
  • 23,587
  • 42
  • 142
  • 223
1 2 3
99
100