Aiming on Node.js 4
This release drops Node.js 0.10/0.12 support, so we replaced lots of modules and reduce dependency tree more than twice (see PR overview). Module folder size reduced from 1.1 MB
to 216 KB
.
For older Node.js versions we will still maintain v5.x
for critical bug-fixes.
Promises by default
Callback interface was replaced by Promises, because it is a better way to work with asynchronous operations and they can be used with yield
/await
nicely.
If you use callback before:
got('todomvc.com', (err, body) => {
if (err) {
console.log(err);
return;
}
console.log(body);
});
You can rewrite it this way:
got('todomvc.com')
.then(res => {
console.log(res.body);
})
.catch(err => {
console.log(err);
});
You can read more about Promises in "ECMAScript 6 promises (2/2): the API" post and some caveats in "We have a problem with promises".
Update
$ npm install --save got@6