Nodejs
FleetingNode.js is a JavaScript runtime built on the V8 JavaScript engine.
hooks
-
Référence externe : https://nodejs.org/api/esm.html#loaders
When hooks are used they apply to each subsequent loader, the entry point, and all import calls. They won’t apply to require calls; those still follow CommonJS rules
determining module system
-
Référence externe : https://nodejs.org/api/packages.html#determining-module-system
Node.js will treat the following as ES modules when passed to node as the initial input, or when referenced by import statements or import() expressions:
- Files with an .mjs extension.
- Files with a .js extension when the nearest parent package.json file contains a top-level “type” field with a value of “module”.
- Strings passed in as an argument to –eval, or piped to node via STDIN, with the flag –input-type=module.
— https://nodejs.org/api/packages.html#determining-module-system
Node.js will treat as CommonJS all other forms of input, such as .js files where the nearest parent package.json file contains no top-level “type” field, or string input without the flag –input-type.
— https://nodejs.org/api/packages.html#determining-module-system
Node.js will treat the following as CommonJS when passed to node as the initial input, or when referenced by import statements, import() expressions, or require() expressions:
- Files with a .cjs extension.
- Files with a .js extension when the nearest parent package.json file contains a top-level field “type” with a value of “commonjs”.
- Strings passed in as an argument to –eval or –print, or piped to node via STDIN, with the flag –input-type=commonjs.
— https://nodejs.org/api/packages.html#determining-module-system
modules loaders
Référence externe : https://nodejs.org/api/packages.html#modules-loaders CommonJS module loader:
- It is fully synchronous.
- It is responsible for handling require() calls.
- It is monkey patchable.
- It supports folders as modules.
- When resolving a specifier, if no exact match is found, it will try to add extensions (.js, .json, and finally .node) and then attempt to resolve folders as modules.
- It treats .json as JSON text files.
- .node files are interpreted as compiled addon modules loaded with process.dlopen().
- It treats all files that lack .json or .node extensions as JavaScript text files.
- It cannot be used to load ECMAScript modules (although it is possible to load ECMASCript modules from CommonJS modules). When used to load a JavaScript text file that is not an ECMAScript module, it loads it as a CommonJS module.
ECMAScript module loader:
- It is asynchronous.
- It is responsible for handling import statements and import() expressions.
- It is not monkey patchable, can be customized using loader hooks.
- It does not support folders as modules, directory indexes (e.g. ‘./startup/index.js’) must be fully specified.
- It does no extension searching. A file extension must be provided when the specifier is a relative or absolute file URL.
- It can load JSON modules, but an import assertion is required.
- It accepts only .js, .mjs, and .cjs extensions for JavaScript text files.
- It can be used to load JavaScript CommonJS modules. Such modules are passed through the cjs-module-lexer to try to identify named exports, which are available if they can be determined through static analysis. Imported CommonJS modules have their URLs converted to absolute paths and are then loaded via the CommonJS module loader.
package.json “type” value of “module” tells Node.js to interpret .js files within that package as using ES module syntax
If the nearest parent package.json lacks a “type” field, or contains “type”: “commonjs”, .js files are treated as CommonJS.
package
package is a folder tree described by a package.json file
— https://nodejs.org/api/packages.html#determining-module-system
Notes pointant ici
- dap-node
- does nodejs wait for all promises before exiting? (blog)
- how to connect to a websocket with a self signed certificate in nodejs
- ms-vscode.js-debug
- ms-vscode.node-debug2
- Node.js Event Loop, Timers, and process.nextTick()
- npm
- trying to make programming easier
- ts-node
- What are CJS, AMD, UMD, and ESM in Javascript?