Today version 6.0 was released. There are a lot of changes, including due to the upgrade of the v8 version (to v5.0), and some of them may break your code. In October of this year, the v6.x branch will become the new active LTS version and its support will last until April 2018.
Changed the logic of Buffer to improve application security. Out of the box, Proxy, Reflect, and expanded support for ES 2015 will be available. Major changes with examples under the cat.
Support for the current LTS branch of Node.js v4 'Argon' will last until April 2017. Support for v5 will last another two months so that developers using this version can upgrade to v6. Support for v0.10 and v0.12 will be completely discontinued in November and December 2016, respectively.
Excerpt from the changelog of the most significant changes:
The constructor of the Buffer object has changed its behavior. The old constructor received the status of deprecated, and its behavior turned into separate methods:
// new Buffer(size); // Buffer.alloc(size);
By default, the buffer is filled with zeros; if this is not required, use Buffer.allocUnsafe
. To initialize the buffer from a string or other buffers, the Buffer.from
method Buffer.from
:
// new Buffer(str, 'utf8'); // Buffer.from(str, 'utf8');
The EventEmitter object received two new methods, prependListener
and prependOnceListener
, both of which add a new event handler to the top of the list of event handlers.
var ee = new EventEmitter(); var result = []; ee.on('event', () => result.push(1)); ee.prependListener('event', () => result.push(2)); ee.emit('event'); result; // -> [2, 1]
The fs.realpath
and fs.realpathSync
now use updated libuv logic and may throw additional errors. Also at the entrance to these methods you can submit Buffer.
The HTTP server now raises the clientError event for a client error. An example can be seen here .
A problem warning mechanism is presented. Instead of outputting to stderr, you can now send warnings to a special method:
process.emitWarning('something goes wrong');
You can also pass an Error
object to it. See the documentation for details.
Threads in object mode can no longer accept to write null
.
The url.resolve
method will drop username and password values when the host changes.
Refusal of WinXP and Vista support.
Now you can use many cool features from ECMAScript 2015 in node.js!
You can select values from an array or an object directly into variables:
let [a, b] = [1, 2]; let {c, e} = {c: 3, e: 4};
You can parse an object or array when passing to a function:
function fn({arg}) { return arg; } fn({arg: '1'}); // -> 1
Functions got default values, finally you can get rid of unnecessary checks at the beginning of the function body:
function doSomething(task = 'nothing') { console.log('I\'m gonna do %s.', task); } doSomething(); // -> I'm gonna do nothing.
Proxy and Reflect objects are available without command line flags.
An almost complete inheritance from an Array
object is finally available.
In my opinion, a very cool release turned out this time! I think you can congratulate the team Node.js.
Thank you, Dimd13 and ChALkeRx for the important versioning support supplement.
Source: https://habr.com/ru/post/282688/
All Articles