CoolFace
Apppublic

AK-21/Graphite-Industrial-Intelligence

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
README.md107 linesDownload Raw Back to mz
1 2# MZ - Modernize node.js3 4[![NPM version][npm-image]][npm-url]5[![Build status][travis-image]][travis-url]6[![Test coverage][coveralls-image]][coveralls-url]7[![Dependency Status][david-image]][david-url]8[![License][license-image]][license-url]9[![Downloads][downloads-image]][downloads-url]10 11Modernize node.js to current ECMAScript specifications!12node.js will not update their API to ES6+ [for a while](https://github.com/joyent/node/issues/7549).13This library is a wrapper for various aspects of node.js' API.14 15## Installation and Usage16 17Set `mz` as a dependency and install it.18 19```bash20npm i mz21```22 23Then prefix the relevant `require()`s with `mz/`:24 25```js26var fs = require('mz/fs')27 28fs.exists(__filename).then(function (exists) {29  if (exists) // do something30})31```32 33With ES2017, this will allow you to use async functions cleanly with node's core API:34 35```js36const fs = require('mz/fs')37 38 39async function doSomething () {40  if (await fs.exists(__filename)) // do something41}42```43 44## Promisification45 46Many node methods are converted into promises.47Any properties that are deprecated or aren't asynchronous will simply be proxied.48The modules wrapped are:49 50- `child_process`51- `crypto`52- `dns`53- `fs` (uses `graceful-fs` if available)54- `readline`55- `zlib`56 57```js58var exec = require('mz/child_process').exec59 60exec('node --version').then(function (stdout) {61  console.log(stdout)62})63```64 65## Promise Engine66 67`mz` uses [`any-promise`](https://github.com/kevinbeaty/any-promise).68 69## FAQ70 71### Can I use this in production?72 73Yes, Node 4.x ships with stable promises support. For older engines,74you should probably install your own promise implementation and register it with75`require('any-promise/register')('bluebird')`.76 77### Will this make my app faster?78 79Nope, probably slower actually.80 81### Can I add more features?82 83Sure.84Open an issue.85 86Currently, the plans are to eventually support:87 88- New APIs in node.js that are not available in older versions of node89- ECMAScript7 Streams90 91[bluebird]: https://github.com/petkaantonov/bluebird92 93[npm-image]: https://img.shields.io/npm/v/mz.svg?style=flat-square94[npm-url]: https://npmjs.org/package/mz95[github-tag]: http://img.shields.io/github/tag/normalize/mz.svg?style=flat-square96[github-url]: https://github.com/normalize/mz/tags97[travis-image]: https://img.shields.io/travis/normalize/mz.svg?style=flat-square98[travis-url]: https://travis-ci.org/normalize/mz99[coveralls-image]: https://img.shields.io/coveralls/normalize/mz.svg?style=flat-square100[coveralls-url]: https://coveralls.io/r/normalize/mz?branch=master101[david-image]: http://img.shields.io/david/normalize/mz.svg?style=flat-square102[david-url]: https://david-dm.org/normalize/mz103[license-image]: http://img.shields.io/npm/l/mz.svg?style=flat-square104[license-url]: LICENSE105[downloads-image]: http://img.shields.io/npm/dm/mz.svg?style=flat-square106[downloads-url]: https://npmjs.org/package/mz107