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
834
votes
33 answers

How do I resolve "Cannot find module" error using Node.js?

After pulling down a module from GitHub and following the instructions to build it, I try pulling it into an existing project using: > npm install ../faye This appears to do the trick: > npm list /home/dave/src/server └─┬ faye@0.7.1 ├──…
Dave Causey
  • 13,098
  • 7
  • 30
  • 26
826
votes
11 answers

Node.js Best Practice Exception Handling

I just started trying out node.js a few days ago. I've realized that the Node is terminated whenever I have an unhandled exception in my program. This is different than the normal server container that I have been exposed to where only the Worker…
momo
  • 21,233
  • 8
  • 39
  • 38
826
votes
57 answers

Node / Express: EADDRINUSE, Address already in use - Kill server

I have a simple server running in node.js using connect: var server = require('connect').createServer(); //actions... server.listen(3000); In my code I have actual handlers, but thats the basic idea. The problem I keep getting is EADDRINUSE,…
Skawful
  • 9,087
  • 4
  • 20
  • 19
825
votes
48 answers

Babel 6 regeneratorRuntime is not defined

I'm trying to use async/await from scratch on Babel 6, but I'm getting regeneratorRuntime is not defined. .babelrc file { "presets": [ "es2015", "stage-0" ] } package.json file "devDependencies": { "babel-core": "^6.0.20", …
BrunoLM
  • 97,872
  • 84
  • 296
  • 452
825
votes
20 answers

npm check and update package if needed

We need to integrate Karma test runner into TeamCity and for that I'd like to give sys-engineers small script (powershell or whatever) that would: pick up desired version number from some config file (I guess I can put it as a comment right in the…
iLemming
  • 34,477
  • 60
  • 195
  • 309
823
votes
12 answers

Execute a command line binary with Node.js

I am in the process of porting a CLI library from Ruby over to Node.js. In my code I execute several third party binaries when necessary. I am not sure how best to accomplish this in Node. Here's an example in Ruby where I call PrinceXML to convert…
Dave Thompson
  • 8,453
  • 3
  • 16
  • 11
817
votes
34 answers

How do I test a single file using Jest?

I am able to test multiple files using Jest, but I cannot figure out how to test a single file. I have: Run npm install jest-cli --save-dev Updated package.json: `{ ... "scripts": { "test": "jest" } ... } Written a number of tests. Running npm…
Musket
  • 8,585
  • 2
  • 16
  • 9
813
votes
52 answers

Uncaught Error: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function but got: object

I am getting this error: Uncaught Error: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. This is my code: var React = require('react') var…
Pankaj Thakur
  • 9,481
  • 3
  • 23
  • 27
802
votes
29 answers

nvm keeps "forgetting" node in new terminal session

Upon using a new terminal session in OS X, nvm forgets the node version and defaults to nothing: $ nvm ls: .nvm v0.11.12 v0.11.13 I have to keep hitting nvm use v.0.11.13 in every session: .nvm v0.11.12 -> …
frhd
  • 9,396
  • 5
  • 24
  • 41
798
votes
24 answers

node.js remove file

How do I delete a file with node.js? http://nodejs.org/api/fs.html#fs_fs_rename_oldpath_newpath_callback I don't see a remove command?
Mark
  • 32,293
  • 33
  • 107
  • 137
776
votes
31 answers

Error: request entity too large

I'm receiving the following error with express: Error: request entity too large at module.exports (/Users/michaeljames/Documents/Projects/Proj/mean/node_modules/express/node_modules/connect/node_modules/raw-body/index.js:16:15) at json…
mike james
  • 8,840
  • 3
  • 18
  • 21
761
votes
36 answers

Why doesn't adding CORS headers to an OPTIONS route allow browsers to access my API?

I am trying to support CORS in my Node.js application that uses the Express.js web framework. I have read a Google group discussion about how to handle this, and read a few articles about how CORS works. First, I did this (code is written in…
mikong
  • 8,270
  • 3
  • 16
  • 15
754
votes
18 answers

How to append to a file in Node?

I am trying to append a string to a log file. However writeFile will erase the content each time before writing the string. fs.writeFile('log.txt', 'Hello Node', function (err) { if (err) throw err; console.log('It\'s saved!'); }); // =>…
supercobra
  • 15,810
  • 9
  • 45
  • 51
753
votes
30 answers

How to process POST data in Node.js?

How do you extract form data (form[method="post"]) and file uploads sent from the HTTP POST method in Node.js? I've read the documentation, googled and found nothing. function (request, response) { //request.post???? } Is there a library or a…
Ming-Tang
  • 17,410
  • 8
  • 38
  • 76
749
votes
30 answers

Read a file one line at a time in node.js?

I am trying to read a large file one line at a time. I found a question on Quora that dealt with the subject but I'm missing some connections to make the whole thing fit together. var Lazy=require("lazy"); new Lazy(process.stdin) .lines …
Alex C
  • 16,624
  • 18
  • 66
  • 98