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
88
votes
4 answers

How to add items to array in nodejs

How do I iterate through an existing array and add the items to a new array. var array = []; forEach( calendars, function (item, index) { array[] = item.id }, done ); function done(){ console.log(array); } The above code would normally…
Ben Scarberry
  • 943
  • 2
  • 8
  • 11
88
votes
11 answers

Environment detection: node.js or browser

I'm developping a JS-app that needs to work both on the client side and the server side (in Javascript on a browser and in Node.js), and I would like to be able to reuse the parts of the code that are used for both sides. I have found out that…
edi9999
  • 19,701
  • 13
  • 88
  • 127
88
votes
3 answers

AWS S3 node.js SDK uploaded file and folder permissions

I'm uploading file to S3 using aws-sdk package: fs.readFile(sourceFile, function (err, data) { if (err) { throw err; } s3.client.putObject({ Bucket: bucketName, Key: 'Folder/image.jpg', Body: data }, function…
WHITECOLOR
  • 24,996
  • 37
  • 121
  • 181
88
votes
3 answers

node.js vs. meteor.js what's the difference?

So I've been hearing/reading alot about meteor.js. The tutorials make it seem very sporty as a framework, but I'm still a bit of a novice when it comes to web programming. I've been trying over the last month and half to really learn node.js and…
ZacAttack
  • 2,005
  • 5
  • 21
  • 34
87
votes
11 answers

execute some code and then go into interactive node

Is there a way to execute some code (in a file or from a string, doesn't really matter) before dropping into interactive mode in node.js? For example, if I create a script __preamble__.js which contains: console.log("preamble executed! poor…
user961528
87
votes
8 answers

Basic static file server in NodeJS

I'm trying to create a static file server in nodejs more as an exercise to understand node than as a perfect server. I'm well aware of projects like Connect and node-static and fully intend to use those libraries for more production-ready code, but…
slapthelownote
  • 4,249
  • 1
  • 23
  • 27
87
votes
6 answers

NestJS - How to use .env variables in main app module file for database connection

I am working on my first NestJS application, which was working fine with hardcoded database connecting string in app.module.ts. But then as per our requirements, I had to pick the database config values from environment files. For that, I followed…
Mohit Bhardwaj
  • 9,650
  • 3
  • 37
  • 64
87
votes
5 answers

How to assert data type with Jest

I'm using Jest to test my Node application. Is it possible for me to expect/assert a value to be a Date Object? expect(typeof result).toEqual(typeof Date()) Was my attempt, but naturally returns [Object]. And so this would pass too {}. Thanks!
Jack.c
  • 1,035
  • 1
  • 11
  • 14
87
votes
5 answers

UnhandledPromiseRejectionWarning: This error originated either by throwing inside of an async function without a catch block

I am getting following error in my Node-Express App UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was…
Alwaysblue
  • 9,948
  • 38
  • 121
  • 210
87
votes
8 answers

How to check for only high vulnerabilities when using "npm audit"?

When you I execute npm install using new npm 6 i got a messages that tell me I have some vulnerabilities : [!] 75 vulnerabilities found [4867 packages audited] Severity: 66 Low | 4 Moderate | 5 High Run npm audit for more detail I ran npm audit…
Wajih
  • 4,227
  • 2
  • 25
  • 40
87
votes
13 answers

How to use MongoDB with promises in Node.js?

I've been trying to discover how to use MongoDB with Node.js and in the docs it seems the suggested way is to use callbacks. Now, I know that it is just a matter of preference, but I really prefer using promises. The problem is that I didn't find…
user1620696
  • 10,825
  • 13
  • 60
  • 81
87
votes
12 answers

Error: Couldn't find preset "es2015" relative to directory "/Users/username"

I get the following error when trying to use gulp-babel: Error: Couldn't find preset "es2015" relative to directory "/Users/username" I have the es2015 preset installed globally and locally so can't see why this would be an issue. Below is my…
Brian Douglas
  • 984
  • 1
  • 6
  • 8
87
votes
1 answer

Node.js Streams vs. Observables

After learning about Observables, I find them quite similar to Node.js streams. Both have a mechanism of notifying the consumer whenever new data arrives, an error occurs or there is no more data (EOF). I would love to learn about the…
urish
  • 8,943
  • 8
  • 54
  • 75
87
votes
5 answers

How to tell eslint that you prefer single quotes around your strings

I'm new to eslint and it's spewing out a ton of errors telling me to use doublequotes: error Strings must use doublequote That's not my preference. I've got an .eslintrc file set up with the basics: { "env": { "node": 1 } } I'd like to…
Antonius Bloch
  • 2,311
  • 2
  • 14
  • 14
87
votes
10 answers

Upload a file to Amazon S3 with NodeJS

I ran into a problem while trying to upload a file to my S3 bucket. Everything works except that my file paramters do not seem appropriate. I am using Amazon S3 sdk to upload from nodejs to s3. These are my routes settings: var multiparty =…
Maximus S
  • 10,759
  • 19
  • 75
  • 154
1 2 3
99
100