Callbacks are completely gone with Node 7 (using --harmony flag)
NodeJS is good now.var req = require('request-promise');
async function test(url1,url2) {
if(url1 === '' || url2 === '') {
throw new Error();
}
return [await req(url1), await req(url2)];
}
test('http://www.google.com', 'http://www.bing.com')
.then(res=>{
console.log(res);
})
.catch(err=>{
console.log(err);
});
eh go is still faster and fills the same niche. its also designed by smarter people. i think ill stick with go.
Callbacks were never a big deal and nobody ever forced you to inline them.
There are still plenty of cases where you'd want to use callbacks instead of async/await
>>58494304
Why even bother using node if you're going to force shit to be synchronous?
>>58494340
other tasks run while waiting, it only looks synchronous
>>58494304
I haven't touched node in a while but isn't it the whole point? I always thought using async was just a temporary solution until you fix your program model. Granted there were some things that were extremely inconvenient to do without async at least.
>>58494304
Can't you just use await in a try/catch block instead of the .then and .catch callbacks?try {
res = await test('http://www.google.com', 'http://www.bing.com')
console.log(res);
} catch(err) {
console.log(err);
}
I've only looked briefly into async/await in Javascript but I think that should work.
>>58494728
Yes, but the try-catch needs to be in an async function or you won't have access to the await keyword.
Promises
>>58494321
this
>>58494654
node only looks like true concurrency
why would anyone use node besides hipster points and for the chance to jump on some doomed startup to fix other hipster's shit?
>>58495515
Dont you like learning new techniques / using new technology?
>>58495582
>lots and lots of poop.jpg
why would anyone like learning shit for the sake of it?
>webshits
>programmers
>>58495515
I only use it to prototype APIs and automate frontend builds. Anyone deploying a serious server using it had better have a good excuse.
That said, it's sometimes faster than e.g. Spring + Java because it doesn't need to jump through 100+ call layers of validation, (de)serialization, object mapping, filters and whatever just to grab some JSON from a database and pass it to the client.
>>58495515
One example - for distributed systems that operate on a strict que. Node's event loop basically solves a very complex problem without you even trying.
Node is just a tool, use it for what you will, preferably for what it makes sense.
>>58495515
Best general purpose modern scripting language. For 90% of new non-legacy projects there is little reason to go with anything else.
>>58495602
yah fuck anything new. New stuff is automatically shit.
>>58495515
Why would anyone hate node besides for /g/ points and for the chance to jump on some doomed discussion to shill Haskell?
I'm probably going to stick with Golang for the backend. If I do front end stuff I'll probably try to use as little JS as possible, but if I had to use a framework I'd use react or vue.js.
BUT... can anyone recommend a book on learning the latest nodejs and ECMAscript versions? I quit javascript right when people started using arrow functions.