https://github.com/bnb/import-modules-as-esm-from-nodejs
Code from my talk, import {modules} as esm from "nodejs"
https://github.com/bnb/import-modules-as-esm-from-nodejs
Last synced: about 1 year ago
JSON representation
Code from my talk, import {modules} as esm from "nodejs"
- Host: GitHub
- URL: https://github.com/bnb/import-modules-as-esm-from-nodejs
- Owner: bnb
- License: other
- Created: 2020-06-22T17:48:38.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2020-06-22T17:49:06.000Z (almost 6 years ago)
- Last Synced: 2025-03-18T05:11:15.636Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# `import {modules} as esm from "nodejs"`
Code for my talk, going over modules and ESM in Node.js.
## Contents
- [**./conditional-exports**](./conditional-exports):
- Contains a relatively barebones example of using Node.js's [conditional exports](https://nodejs.org/api/esm.html#esm_conditional_exports) with ESM and CommonJS exports from a module (checked in to `node_modules`) and using them, respectively. Uses both implicit ESM and explicit ESM.
- [**./explicit-esm**](./explicit-esm):
- Demonstrates explicit ESM in Node.js, using `.mjs` extensions for ESM files.
- [**./implicit-esm**](./implicit-esm):
- Demonstrates implicit ESM in Node.js, using `"type": "module"` in the project's `package.json` and `.js` extensions for ESM files.
## Definitions
- ESM
- ECMAScript Modules, the moudle system that's built-in to JavaScript and defined by TC39.
- Implicit ESM
- Implicit ESM is ESM in Node.js that uses `"type": "module"` as a property in `package.json`, which Node.js uses as an indicator to passively read all `.js` files as ESM rather than CommonJS (which Node.js defaults to or can be told to )
- Explicit ESM
- Explicit ESM is ESM in Node.js that uses `.mjs` as its file extension. Node.js will automatically parse any file with .mjs as its file extension as ESM.