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
1704
votes
42 answers

How do I debug Node.js applications?

How do I debug a Node.js server application? Right now I'm mostly using alert debugging with print statements like this: sys.puts(sys.inspect(someVariable)); There must be a better way to debug. I know that Google Chrome has a command-line…
Fabian Jakobs
  • 28,815
  • 8
  • 42
  • 39
1577
votes
31 answers

How do you get a list of the names of all files present in a directory in Node.js?

I'm trying to get a list of the names of all the files present in a directory using Node.js. I want output that is an array of filenames. How can I do this?
resopollution
  • 19,600
  • 10
  • 40
  • 49
1560
votes
26 answers

How to get GET (query string) variables in Express.js on Node.js?

Can we get the variables in the query string in Node.js just like we get them in $_GET in PHP? I know that in Node.js we can get the URL in the request. Is there a method to get the query string parameters?
XMen
  • 29,384
  • 41
  • 99
  • 151
1555
votes
13 answers

What is the purpose of Node.js module.exports and how do you use it?

What is the purpose of Node.js module.exports and how do you use it? I can't seem to find any information on this, but it appears to be a rather important part of Node.js as I often see it in source code. According to the Node.js…
mrwooster
  • 23,789
  • 12
  • 38
  • 48
1532
votes
9 answers

Read environment variables in Node.js

Is there a way to read environment variables in Node.js code? Like for example Python's os.environ['HOME'].
Jayesh
  • 51,787
  • 22
  • 76
  • 99
1486
votes
18 answers

Check synchronously if file/directory exists in Node.js

How can I synchronously check, using node.js, if a file or directory exists?
user196106
1485
votes
39 answers

How to fix npm throwing error without sudo

I just installed node and npm through the package on nodejs.org, and whenever I try to search or install something with npm, it throws the following error unless I sudo the command. I have a feeling this is a permissions issue? I am already the…
Chad
  • 18,076
  • 8
  • 31
  • 41
1456
votes
23 answers

Where does npm install packages?

Can someone tell me where can I find the Node.js modules, which I installed using npm?
trnc
  • 20,581
  • 21
  • 60
  • 98
1448
votes
27 answers

How can the default node version be set using NVM?

I have installed nvm (ubuntu with zsh shell) with two node version: v6.11.5 and v9.0.0 and the default version in nvm is the v9.0.0 Every time I need to change the node version $ nvm list v6.11.5 -> v9.0.0 system default ->…
Pablo Ezequiel Inchausti
  • 16,623
  • 7
  • 28
  • 42
1441
votes
19 answers

How can I get the full object in Node.js's console.log(), rather than '[Object]'?

I have this object: const myObject = { "a":"a", "b":{ "c":"c", "d":{ "e":"e", "f":{ "g":"g", "h":{ "i":"i" } } } } }; But when I try to show it…
user1372449
1399
votes
23 answers

How can I uninstall npm modules in Node.js?

As commonly known, any npm module can be installed by running a simple command: npm install . I have installed a few modules that I do not use any more and I just want to get them off. I have a few questions regarding this: Do we have…
Manish Kumar
  • 15,269
  • 5
  • 18
  • 27
1378
votes
23 answers

Sending command line arguments to npm script

The scripts portion of my package.json currently looks like this: "scripts": { "start": "node ./script.js server" } ...which means I can run npm start to start the server. So far so good. However, I would like to be able to run something like…
arnemart
  • 14,180
  • 3
  • 17
  • 11
1300
votes
11 answers

Using Node.js require vs. ES6 import/export

In a project I am collaborating on, we have two choices on which module system we can use: Importing modules using require, and exporting using module.exports and exports.foo. Importing modules using ES6 import, and exporting using ES6 export Are…
kpimov
  • 13,632
  • 3
  • 12
  • 18
1292
votes
15 answers

How do I get the path to the current script with Node.js?

How would I get the path to the script in Node.js? I know there's process.cwd, but that only refers to the directory where the script was called, not of the script itself. For instance, say I'm in /home/kyle/ and I run the following command: node…
Kyle Slattery
  • 33,318
  • 9
  • 32
  • 36
1274
votes
33 answers

Using Node.js as a simple web server

I want to run a very simple HTTP server. Every GET request to example.com should get index.html served to it but as a regular HTML page (i.e., same experience as when you read normal web pages). Using the code below, I can read the content of…
idophir
  • 14,451
  • 5
  • 24
  • 21