474,039
questions
5429
votes
22
answers
1.9m
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 ...
3232
votes
35
answers
2.3m
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 ...
3108
votes
16
answers
1.2m
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?
3090
votes
41
answers
1.9m
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 ...
3026
votes
32
answers
2.3m
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>
...
2937
votes
17
answers
1.0m
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 ...
2822
votes
42
answers
1.7m
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 ...
2492
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'...
2396
votes
68
answers
3.1m
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 (...
2335
votes
22
answers
1.3m
views
How to exit in Node.js
What is the command that is used to exit? (i.e terminate the Node.js process)
2191
votes
17
answers
586k
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 ...
2181
votes
68
answers
2.4m
views
How can I update Node.js and npm to their latest versions?
I just installed Node.js and npm. 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 available.
So my ...
2113
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?
1837
votes
41
answers
2.9m
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, ...
1770
votes
34
answers
2.9m
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 ...
1757
votes
25
answers
1.5m
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....
1709
votes
42
answers
554k
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 ...
1628
votes
33
answers
1.7m
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?
1601
votes
27
answers
2.0m
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 ...
1562
votes
11
answers
939k
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'].
1562
votes
13
answers
529k
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 ...
1519
votes
23
answers
1.3m
views
Where does npm install packages?
Can someone tell me where can I find the Node.js modules, which I installed using npm?
1517
votes
22
answers
979k
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",
"...
1511
votes
40
answers
708k
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 ...
1506
votes
19
answers
996k
views
Check synchronously if file/directory exists in Node.js
How can I synchronously check, using node.js, if a file or directory exists?
1467
votes
25
answers
1.1m
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 ...
1418
votes
24
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 ...
1335
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 /...
1324
votes
11
answers
850k
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 ...
1291
votes
35
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).
...
1270
votes
18
answers
521k
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 --...
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 ...
1258
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(...
1245
votes
10
answers
1.2m
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 ...
1228
votes
29
answers
1.2m
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....
1225
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:...
1183
votes
25
answers
975k
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(...
1166
votes
40
answers
2.3m
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 ...
1145
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?
1138
votes
12
answers
443k
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 ...
1118
votes
10
answers
420k
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 ...
1057
votes
19
answers
788k
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 ...
1045
votes
32
answers
1.2m
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 ...
1037
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?
1011
votes
42
answers
646k
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?
954
votes
12
answers
471k
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 ...
944
votes
32
answers
791k
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 ...
938
votes
10
answers
570k
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 ...
934
votes
34
answers
586k
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 ...
923
votes
22
answers
1.1m
views
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 ...