source: frontend/node_modules/mz/README.md

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 2.8 KB
Line 
1
2# MZ - Modernize node.js
3
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 Usage
16
17Set `mz` as a dependency and install it.
18
19```bash
20npm i mz
21```
22
23Then prefix the relevant `require()`s with `mz/`:
24
25```js
26var fs = require('mz/fs')
27
28fs.exists(__filename).then(function (exists) {
29 if (exists) // do something
30})
31```
32
33With ES2017, this will allow you to use async functions cleanly with node's core API:
34
35```js
36const fs = require('mz/fs')
37
38
39async function doSomething () {
40 if (await fs.exists(__filename)) // do something
41}
42```
43
44## Promisification
45
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```js
58var exec = require('mz/child_process').exec
59
60exec('node --version').then(function (stdout) {
61 console.log(stdout)
62})
63```
64
65## Promise Engine
66
67`mz` uses [`any-promise`](https://github.com/kevinbeaty/any-promise).
68
69## FAQ
70
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 with
75`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 node
89- ECMAScript7 Streams
90
91[bluebird]: https://github.com/petkaantonov/bluebird
92
93[npm-image]: https://img.shields.io/npm/v/mz.svg?style=flat-square
94[npm-url]: https://npmjs.org/package/mz
95[github-tag]: http://img.shields.io/github/tag/normalize/mz.svg?style=flat-square
96[github-url]: https://github.com/normalize/mz/tags
97[travis-image]: https://img.shields.io/travis/normalize/mz.svg?style=flat-square
98[travis-url]: https://travis-ci.org/normalize/mz
99[coveralls-image]: https://img.shields.io/coveralls/normalize/mz.svg?style=flat-square
100[coveralls-url]: https://coveralls.io/r/normalize/mz?branch=master
101[david-image]: http://img.shields.io/david/normalize/mz.svg?style=flat-square
102[david-url]: https://david-dm.org/normalize/mz
103[license-image]: http://img.shields.io/npm/l/mz.svg?style=flat-square
104[license-url]: LICENSE
105[downloads-image]: http://img.shields.io/npm/dm/mz.svg?style=flat-square
106[downloads-url]: https://npmjs.org/package/mz
Note: See TracBrowser for help on using the repository browser.