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.

Filter by
Sorted by
Tagged with
5333 votes
22 answers
1.8m views

What's the difference between tilde(~) and caret(^) in package.json?

After I upgraded to the latest stable node and npm, I tried npm install moment --save. It saves the entry in the package.json with the caret ^ prefix. Previously, it was a tilde ~ prefix. Why are ...
Fizer Khan's user avatar
  • 90.5k
3162 votes
34 answers
2.2m views

Using async/await with a forEach loop

Are there any issues with using async/await in a forEach loop? I'm trying to loop through an array of files and await on the contents of each file. import fs from 'fs-promise' async function ...
Saad's user avatar
  • 52.1k
3072 votes
16 answers
1.1m views

What is the --save option for npm install?

I saw some tutorial where the command was: npm install --save What does the --save option mean?
Dmitri's user avatar
  • 35.6k
3063 votes
41 answers
1.8m views

How do I pass command line arguments to a Node.js program and receive them?

I have a web server written in Node.js and I would like to launch with a specific folder. I'm not sure how to access arguments in JavaScript. I'm running node like this: $ node server.js folder here ...
milkplus's user avatar
  • 33.7k
2997 votes
32 answers
2.2m views

Find the version of an installed npm package

How can I find the version of an installed Node.js or npm package? This prints the version of npm itself: npm -v <package-name> This prints a cryptic error: npm version <package-name> ...
Laurent Couvidou's user avatar
2905 votes
16 answers
987k views

What's the difference between dependencies, devDependencies, and peerDependencies in NPM package.json file?

This documentation answers my question very poorly. I didn't understand those explanations. Can someone say in simpler words? Maybe with examples if it's hard to choose simple words? Also added ...
Vitalii Korsakov's user avatar
2788 votes
42 answers
1.6m views

How can I update each dependency in package.json to the latest version?

I copied package.json from another project and now want to bump all of the dependencies to their latest versions since this is a fresh project and I don't mind fixing something if it breaks. What's ...
Raine Revere's user avatar
  • 32.3k
2459 votes
15 answers
1.1m views

Do I commit the package-lock.json file created by npm 5?

npm 5 was released today and one of the new features include deterministic installs with the creation of a package-lock.json file. Is this file supposed to be kept in source control? I'm assuming it'...
rink.attendant.6's user avatar
2317 votes
22 answers
1.2m views

How to exit in Node.js

What is the command that is used to exit? (i.e terminate the Node.js process)
700 Software's user avatar
  • 86.5k
2225 votes
67 answers
2.8m views

Error message "error:0308010C:digital envelope routines::unsupported"

I created the default IntelliJ IDEA React project and got this: Error: error:0308010C:digital envelope routines::unsupported at new Hash (node:internal/crypto/hash:67:19) at Object.createHash (...
a1cd's user avatar
  • 22.9k
2191 votes
17 answers
585k views

How to decide when to use Node.js?

I am new to this kind of stuff, but lately I've been hearing a lot about how good Node.js is. Considering how much I love working with jQuery and JavaScript in general, I can't help but wonder how to ...
Legend's user avatar
  • 115k
2155 votes
67 answers
2.3m views

How can I update Node.js and NPM to their latest versions?

I just installed Node.js and NPM (Node Package Manager). I installed NPM for access to additional Node.js modules. After I installed Node.js and NPM, I noticed that neither were the latest versions ...
Dail's user avatar
  • 21.8k
2105 votes
18 answers
2.1m views

Writing to files in Node.js

I've been trying to find a way to write to a file when using Node.js, but with no success. How can I do that?
Gjorgji's user avatar
  • 22.9k
1815 votes
41 answers
2.8m views

map function for objects (instead of arrays)

I have an object: myObject = { 'a': 1, 'b': 2, 'c': 3 } I am looking for a native method, similar to Array.prototype.map that would be used as follows: newObject = myObject.map(function (value, ...
Randomblue's user avatar
  • 115k
1754 votes
36 answers
2.8m views

How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)

My version of node is always v0.6.1-pre even after I install brew node and NVM install v0.6.19. My node version is: node -v v0.6.1-pre NVM says this (after I install a version of node for the first ...
Dominic Tancredi's user avatar
1708 votes
42 answers
551k views

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 ...
Fabian Jakobs's user avatar
1667 votes
31 answers
1.4m views

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....
Pablo Ezequiel Inchausti's user avatar
1608 votes
33 answers
1.6m views

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's user avatar
1588 votes
26 answers
1.9m views

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 ...
XMen's user avatar
  • 29.9k
1561 votes
13 answers
527k views

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 ...
mrwooster's user avatar
  • 24.1k
1554 votes
11 answers
913k views

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's user avatar
  • 52.7k
1509 votes
40 answers
693k views

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 ...
Chad's user avatar
  • 18.3k
1507 votes
23 answers
1.2m views

Where does npm install packages?

Can someone tell me where can I find the Node.js modules, which I installed using npm?
trnc's user avatar
  • 21.2k
1500 votes
19 answers
981k views

Check synchronously if file/directory exists in Node.js

How can I synchronously check, using node.js, if a file or directory exists?
user avatar
1495 votes
20 answers
943k views

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", "...
user avatar
1440 votes
25 answers
1.0m views

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 ...
arnemart's user avatar
  • 14.8k
1414 votes
23 answers
1.6m views

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 <module_name>. I have installed a few modules that I do not use any more and I just want to get them ...
Manish Kumar's user avatar
  • 15.4k
1320 votes
15 answers
1.2m views

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 /...
Kyle Slattery's user avatar
1318 votes
11 answers
836k views

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 ...
kpimov's user avatar
  • 13.8k
1286 votes
34 answers
1.4m views

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). ...
idophir's user avatar
  • 14.6k
1262 votes
3 answers
1.3m views

How do I get started with Node.js [closed]

Are there any good resources to get started with Node.JS? Any good tutorials, blogs or books? Of course, I have visited its official website http://nodejs.org/, but I didn't think the documentation ...
1253 votes
18 answers
499k views

What is the difference between --save and --save-dev?

What is the difference between: npm install [package_name] and: npm install [package_name] --save and: npm install [package_name] --save-dev What does this mean? And what is really the effect of --...
nfort's user avatar
  • 12.7k
1239 votes
8 answers
1.1m views

How can I do Base64 encoding in Node.js?

Does Node.js have built-in Base64 encoding yet? The reason why I ask this is that final() from crypto can only output hexadecimal, binary or ASCII data. For example: var cipher = crypto.createCipheriv(...
murvinlai's user avatar
  • 49.7k
1227 votes
29 answers
1.1m views

In Node.js, how do I "include" functions from my other files?

Let's say I have a file called app.js. Pretty simple: var express = require('express'); var app = express.createServer(); app.set('views', __dirname + '/views'); app.set('view engine', 'ejs'); app....
TIMEX's user avatar
  • 266k
1224 votes
10 answers
1.1m views

How to install a previous exact version of a NPM package?

I used nvm to download node v0.4.10 and installed npm to work with that version of node. I am trying to install express using npm install express -g and I get an error that express requires node ...
stewart99's user avatar
  • 14.5k
1214 votes
49 answers
2.1m views

Error: Can't set headers after they are sent to the client

I'm fairly new to Node.js and I am having some issues. I am using Node.js 4.10 and Express 2.4.3. When I try to access http://127.0.0.1:8888/auth/facebook, i'll be redirected to http://127.0.0.1:...
DjangoRocks's user avatar
1171 votes
25 answers
951k views

How to create a directory if it doesn't exist using Node.js

Is the following the right way to create a directory if it doesn't exist? It should have full permission for the script and readable by others. var dir = __dirname + '/upload'; if (!path.existsSync(...
Whisher's user avatar
  • 32.1k
1142 votes
24 answers
1.6m views

How is an HTTP POST request made in node.js?

How can I make an outbound HTTP POST request, with data, in node.js?
Mark's user avatar
  • 68.6k
1139 votes
12 answers
441k views

Node.js + Nginx - What now?

I've set up Node.js and Nginx on my server. Now I want to use it, but, before I start there are 2 questions: How should they work together? How should I handle the requests? There are 2 concepts for ...
Van Coding's user avatar
  • 24.4k
1129 votes
40 answers
2.1m views

Upgrading Node.js to the latest version

So, I have Node.js installed and now when I tried to install Mongoosejs, I got an error telling me that I don't have the needed version of Node.js (I have v0.4.11 and v0.4.12 is needed). How can I ...
holyredbeard's user avatar
  • 20.4k
1100 votes
9 answers
384k views

Node.js/Windows error: ENOENT, stat 'C:\Users\RT\AppData\Roaming\npm'

I have Windows 7 32-bit. I installed the latest Node.js 32 bit. When I try to run the command npm install jquery, I receive the error: Error: ENOENT, stat 'C:\Users\RT\AppData\Roaming\npm How ...
tryasko's user avatar
  • 11.1k
1035 votes
31 answers
1.1m views

How to parse JSON using Node.js? [closed]

How should I parse JSON using Node.js? Is there some module which will validate and parse JSON securely?
Tikhon Jelvis's user avatar
1031 votes
32 answers
1.1m views

Upgrade Node.js to the latest version on Mac OS

Currently I am using Node.js v0.6.16 on Mac OS X 10.7.4. Now I want to upgrade it to the latest Node.js v0.8.1. But after downloading and installing the latest package file from nodejs.org, I found ...
afterglowlee's user avatar
1020 votes
19 answers
743k views

How to list npm user-installed packages

How do I list the user-installed / environment package only in npm? When I do npm -g list, it outputs every package and their dependencies. Instead I'd like to see the packages installed in the ...
lolski's user avatar
  • 16.7k
991 votes
40 answers
628k views

How to change node.js's console font color?

I had to change the console background color to white because of eye problems, but the font is gray colored and it makes the messages unreadable. How can I change it?
MaiaVictor's user avatar
  • 52.1k
946 votes
12 answers
454k views

Why does "npm install" rewrite package-lock.json?

I just recently upgraded to npm@5. I now have a package-lock.json file with everything from package.json. I would expect that, when I run npm install that the dependency versions would be pulled ...
Viper Bailey's user avatar
  • 11.8k
930 votes
9 answers
557k views

Node.js: printing to console without a trailing newline?

Is there a method for printing to the console without a trailing newline? The console object documentation doesn't say anything regarding that: console.log() Prints to stdout with newline. This ...
Evan Carroll's user avatar
925 votes
32 answers
763k views

How can I run multiple npm scripts in parallel?

In my package.json I have these two scripts: "scripts": { "start-watch": "nodemon run-babel index.js", "wp-server": "webpack-dev-server", } I have to run these 2 scripts in parallel ...
Andre Pena's user avatar
  • 58.1k
921 votes
34 answers
560k views

Is there a way to get the version from the 'package.json' file in Node.js code?

Is there a way to get the version set in the package.json file in a Node.js application? I would want something like this var port = process.env.PORT || 3000 app.listen port console.log "Express ...
Abhik Bose Pramanik's user avatar
919 votes
12 answers
667k views

Error "npm WARN package.json: No repository field"

I installed Express.js with the following command: sudo npm install -g express I get the following warnings: npm WARN package.json [email protected] No repository field. npm WARN package.json fresh@...
JR Galia's user avatar
  • 17.3k

1
2 3 4 5
9450