Skip to main content

All Questions

Tagged with
3219 votes
34 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 ...
Saad's user avatar
  • 52.8k
874 votes
24 answers
330k 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
1222 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
  • 14.1k
240 votes
7 answers
38k views

When is .then(success, fail) considered an antipattern for promises?

I had a look at the bluebird promise FAQ, in which it mentions that .then(success, fail) is an antipattern. I don't quite understand its explanation as for the try and catch. What's wrong with the ...
user2127480's user avatar
  • 4,701
194 votes
4 answers
151k views

Is it an anti-pattern to use async/await inside of a new Promise() constructor?

I'm using the async.eachLimit function to control the maximum number of operations at a time. const { eachLimit } = require("async"); function myFunction() { return new Promise(async (resolve, ...
user avatar
172 votes
15 answers
209k views

setState doesn't update the state immediately [duplicate]

I would like to ask why my state is not changing when I do an onClick event. I've search a while ago that I need to bind the onClick function in constructor but still the state is not updating. Here's ...
Sydney Loteria's user avatar
205 votes
6 answers
145k views

async function implicitly returns promise?

I read that async functions marked by the async keyword implicitly return a promise: async function getVal(){ return await doSomethingAync(); } var ret = getVal(); console.log(ret); but that is ...
Alexander Mills's user avatar
1765 votes
36 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 ...
Dominic Tancredi's user avatar
199 votes
5 answers
70k views

Is it bad practice to have a constructor function return a Promise?

I'm trying to create a constructor for a blogging platform and it has many async operations going on inside. These range from grabbing the posts from directories, parsing them, sending them through ...
adam-beck's user avatar
  • 5,869
60 votes
2 answers
43k views

Updating a Nested Array with MongoDB

I am trying to update a value in the nested array but can't get it to work. My object is like this { "_id": { "$oid": "1" }, "array1": [ ...
masanorinyo's user avatar
  • 1,128
1562 votes
13 answers
528k 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
1833 votes
42 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
1510 votes
21 answers
968k 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
2111 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
  • 23k
889 votes
32 answers
942k 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.4k

15 30 50 per page
1
2 3 4 5
840