2019-11-12 15:51:14 -05:00
|
|
|
# Deno Node compatibility
|
|
|
|
|
|
|
|
This module is meant to have a compatibility layer for the
|
2020-01-15 14:13:12 -05:00
|
|
|
[NodeJS standard library](https://nodejs.org/docs/latest-v12.x/api/).
|
2019-11-12 15:51:14 -05:00
|
|
|
|
2020-01-15 14:13:12 -05:00
|
|
|
**Warning**: Any function of this module should not be referred anywhere in the
|
2020-05-11 09:13:06 -04:00
|
|
|
deno standard library as it's a compatibility module.
|
2019-11-19 16:44:59 -05:00
|
|
|
|
2020-01-15 14:13:12 -05:00
|
|
|
## Supported Builtins
|
|
|
|
|
|
|
|
- [ ] assert
|
2020-06-13 09:58:08 -04:00
|
|
|
- [x] buffer
|
2020-01-15 14:13:12 -05:00
|
|
|
- [ ] child_process
|
|
|
|
- [ ] cluster
|
|
|
|
- [ ] console
|
|
|
|
- [ ] crypto
|
|
|
|
- [ ] dgram
|
|
|
|
- [ ] dns
|
2020-02-10 18:19:48 -05:00
|
|
|
- [x] events
|
2020-01-15 14:13:12 -05:00
|
|
|
- [x] fs _partly_
|
|
|
|
- [ ] http
|
|
|
|
- [ ] http2
|
|
|
|
- [ ] https
|
|
|
|
- [x] module
|
|
|
|
- [ ] net
|
2020-01-29 20:57:29 -05:00
|
|
|
- [x] os _partly_
|
2020-01-15 14:13:12 -05:00
|
|
|
- [x] path
|
|
|
|
- [ ] perf_hooks
|
|
|
|
- [x] process _partly_
|
2020-03-14 16:43:49 -04:00
|
|
|
- [x] querystring
|
2020-01-15 14:13:12 -05:00
|
|
|
- [ ] readline
|
|
|
|
- [ ] repl
|
|
|
|
- [ ] stream
|
|
|
|
- [ ] string_decoder
|
|
|
|
- [ ] sys
|
|
|
|
- [x] timers
|
|
|
|
- [ ] tls
|
|
|
|
- [ ] tty
|
|
|
|
- [ ] url
|
|
|
|
- [x] util _partly_
|
|
|
|
- [ ] ~~v8~~ _can't implement_
|
|
|
|
- [ ] vm
|
|
|
|
- [ ] worker_threads
|
|
|
|
- [ ] zlib
|
|
|
|
|
|
|
|
* [x] node globals _partly_
|
|
|
|
|
|
|
|
### Deprecated
|
|
|
|
|
|
|
|
These builtins are deprecated in NodeJS v13 and will probably not be polyfilled:
|
|
|
|
|
|
|
|
- constants
|
|
|
|
- domain
|
|
|
|
- freelist
|
|
|
|
- punycode
|
|
|
|
|
|
|
|
### Experimental
|
|
|
|
|
|
|
|
These builtins are experimental in NodeJS v13 and will not be polyfilled until
|
|
|
|
they are stable:
|
|
|
|
|
|
|
|
- async_hooks
|
|
|
|
- inspector
|
|
|
|
- policies
|
|
|
|
- report
|
|
|
|
- trace_events
|
|
|
|
- wasi
|
|
|
|
|
2019-11-19 16:44:59 -05:00
|
|
|
## CommonJS Module Loading
|
|
|
|
|
|
|
|
`createRequire(...)` is provided to create a `require` function for loading CJS
|
2020-04-30 10:00:02 -04:00
|
|
|
modules. It also sets supported globals.
|
2019-11-19 16:44:59 -05:00
|
|
|
|
|
|
|
```ts
|
2020-10-04 08:18:36 -04:00
|
|
|
import { createRequire } from "https://deno.land/std@$STD_VERSION/node/module.ts";
|
2019-11-19 16:44:59 -05:00
|
|
|
|
2020-04-20 14:30:52 -04:00
|
|
|
const require = createRequire(import.meta.url);
|
2019-11-19 16:44:59 -05:00
|
|
|
// Loads native module polyfill.
|
2020-04-20 14:30:52 -04:00
|
|
|
const path = require("path");
|
2019-11-19 16:44:59 -05:00
|
|
|
// Loads extensionless module.
|
2020-04-20 14:30:52 -04:00
|
|
|
const cjsModule = require("./my_mod");
|
2019-11-19 16:44:59 -05:00
|
|
|
// Visits node_modules.
|
2020-04-20 14:30:52 -04:00
|
|
|
const leftPad = require("left-pad");
|
2019-11-19 16:44:59 -05:00
|
|
|
```
|