All Questions

Tagged with
Filter by
Sorted by
Tagged with
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
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
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
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
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
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
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
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
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
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 ...
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
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
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
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
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
919 votes
24 answers
948k views

How to access POST form fields in Express

Here is my simple form: <form id="loginformA" action="userlogin" method="post"> <div> <label for="email">Email: </label> <input type="text" id="email" ...
murvinlai's user avatar
  • 49.7k
891 votes
12 answers
768k views

What is "export default" in JavaScript?

File: SafeString.js // Build out our basic SafeString type function SafeString(string) { this.string = string; } SafeString.prototype.toString = function() { return "" + this.string; }; ...
damphat's user avatar
  • 18.6k
888 votes
32 answers
935k views

How can I print a circular structure in a JSON-like format?

I have a big object I want to convert to JSON and send. However it has circular structure, so if I try to use JSON.stringify() I'll get: TypeError: Converting circular structure to JSON or ...
Harry's user avatar
  • 54.1k
884 votes
12 answers
557k views

Call async/await functions in parallel

As far as I understand, in ES7/ES2016 putting multiple await's in code will work similar to chaining .then() with promises, meaning that they will execute one after the other rather than in parallel. ...
Victor Marchuk's user avatar
871 votes
24 answers
327k views

How do I convert an existing callback API to promises?

I want to work with promises but I have a callback API in a format like: 1. DOM load or other one time event: window.onload; // set to callback ... window.onload = function() { }; 2. Plain ...
Benjamin Gruenbaum's user avatar
864 votes
24 answers
350k views

module.exports vs exports in Node.js

I've found the following contract in a Node.js module: module.exports = exports = nano = function database_module(cfg) {...} I wonder what's the difference between module.exports and exports and why ...
Andreas Köberle's user avatar
852 votes
14 answers
774k views

Using Node.JS, how do I read a JSON file into (server) memory?

Background I am doing some experimentation with Node.js and would like to read a JSON object, either from a text file or a .js file (which is better??) into memory so that I can access that object ...
Matt Cashatt's user avatar
  • 23.9k
839 votes
12 answers
849k views

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 ...
Dave Thompson's user avatar
834 votes
54 answers
1.1m views

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. ...
Pankaj Thakur's user avatar
828 votes
48 answers
770k views

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" ] } ...
BrunoLM's user avatar
  • 99.1k
809 votes
31 answers
755k views

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/...
mike james's user avatar
  • 9,210
769 votes
27 answers
1.4m views

How can I wait In Node.js (JavaScript)? l need to pause for a period of time

I'm developing a console script for personal needs. I need to be able to pause for an extended amount of time, but, from my research, Node.js has no way to stop as required. It’s getting hard to read ...
Christopher Allen's user avatar
769 votes
31 answers
731k views

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("...
Alex C's user avatar
  • 16.9k
767 votes
18 answers
831k views

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;...
supercobra's user avatar
718 votes
8 answers
1.1m views

What is "require" in JavaScript and NodeJS?

I'm trying to get JavaScript to read/write to a PostgreSQL database. I found this project on GitHub. I was able to get the following sample code to run in Node. var pg = require('pg'); //native libpq ...
neuromancer's user avatar
  • 54.7k
708 votes
17 answers
269k views

Node.js on multi-core machines

Node.js looks interesting, BUT I must miss something - isn't Node.js tuned only to run on a single process and thread? Then how does it scale for multi-core CPUs and multi-CPU servers? After all, it ...
zaharpopov's user avatar
  • 17.1k
673 votes
11 answers
552k views

Installing a local module using npm?

I have a downloaded module repo, I want to install it locally, not globally in another directory? What is an easy way to do this?
fancy's user avatar
  • 50.2k
669 votes
33 answers
882k views

How to download a file with Node.js (without using third-party libraries)?

How do I download a file with Node.js without using third-party libraries? I don't need anything special. I only want to download a file from a given URL, and then save it to a given directory.
greepow's user avatar
  • 7,213
668 votes
33 answers
1.7m views

SyntaxError: Cannot use import statement outside a module

I've got an ApolloServer project that's giving me trouble, so I thought I might update it and ran into issues when using the latest Babel. My "index.js" is: require('dotenv').config() import ...
user3810626's user avatar
  • 7,310
654 votes
12 answers
371k views

How to print a stack trace in Node.js?

Does anyone know how to print a stack trace in Node.js?
mike.toString's user avatar
642 votes
33 answers
457k views

Invalidating JSON Web Tokens

For a new node.js project I'm working on, I'm thinking about switching over from a cookie based session approach (by this, I mean, storing an id to a key-value store containing user sessions in a user'...
funseiki's user avatar
  • 9,307
631 votes
16 answers
532k views

Fastest way to copy a file in Node.js

The project that I am working on (Node.js) implies lots of operations with the file system (copying, reading, writing, etc.). Which methods are the fastest?
bonbonez's user avatar
  • 6,808
618 votes
21 answers
424k views

Can I use jQuery with Node.js?

Is it possible to use jQuery selectors/DOM manipulation on the server-side using Node.js?
John's user avatar
  • 6,197
609 votes
12 answers
322k views

How can I write a test which expects an 'Error' to be thrown in Jasmine?

I'm trying to write a test for the Jasmine Test Framework which expects an error. At the moment I'm using a Jasmine Node.js integration from GitHub. In my Node.js module I have the following code: ...
echox's user avatar
  • 9,816
591 votes
15 answers
221k views

Is it not possible to stringify an Error using JSON.stringify?

Reproducing the problem I'm running into an issue when trying to pass error messages around using web sockets. I can replicate the issue I am facing using JSON.stringify to cater to a wider audience: ...
Jay's user avatar
  • 19.5k
574 votes
31 answers
505k views

How to auto-reload files in Node.js?

Any ideas on how I could implement an auto-reload of files in Node.js? I'm tired of restarting the server every time I change a file. Apparently Node.js' require() function does not reload files if ...
disc0dancer's user avatar
  • 9,265
568 votes
26 answers
946k views

ReferenceError: fetch is not defined

I have this error when I compile my code in node.js, how can I fix it? RefernceError: fetch is not defined This is the function I am doing, it is responsible for recovering information from a ...
jasa1704's user avatar
  • 5,799
563 votes
36 answers
1.0m views

Node.js heap out of memory

Today I ran my script for filesystem indexing to refresh RAID files index and after 4h it crashed with following error: [md5:] 241613/241627 97.5% [md5:] 241614/241627 97.5% [md5:] 241625/...
Lapsio's user avatar
  • 6,734
562 votes
23 answers
570k views

React - changing an uncontrolled input

I have a simple react component with the form which I believe to have one controlled input: import React from 'react'; export default class MyForm extends React.Component { constructor(props) { ...
alexs333's user avatar
  • 12.4k
546 votes
45 answers
891k views

How to fix Error: listen EADDRINUSE while using NodeJS?

If I run a server with the port 80, and I try to use XMLHttpRequest I am getting this error: Error: listen EADDRINUSE Why is it problem for NodeJS, if I want to do a request, while I run a server on ...
Danny Fox's user avatar
  • 39.8k

1
2 3 4 5
3548