CommonJS
Fleeting- Référence externe : https://jameshfisher.com/2020/09/27/what-does-the-require-function-do-in-nodejs/
“CommonJS” module system, which is mainly used in Node.js, and is identified by calls to a require function
— https://jameshfisher.com/2020/09/27/what-does-the-require-function-do-in-nodejs/
CommonJS module exports things by adding properties to an exports object
— https://jameshfisher.com/2020/09/27/what-does-the-require-function-do-in-nodejs/
const express = require(’express’), but what does this do? The full search algorithm is a bit horrifying. But in a standard setup, this loads the JavaScript file at ./node_modules/express/index.js. You can equivalently write const express = require(’./node_modules/express/index.js’).
— https://jameshfisher.com/2020/09/27/what-does-the-require-function-do-in-nodejs/
also use require.resolve to debug it:
> require.resolve(’express’) ‘/Users/jim/dev/tmp/node_require/node_modules/express/index.js’
— https://jameshfisher.com/2020/09/27/what-does-the-require-function-do-in-nodejs/
require to load new modules
.cjs extension
Notes pointant ici
- danez/pirates
- deno
- determining module system
- jupyter javascript/typescript
- modules loaders
- playwright/test + ts-node = wrong stack traces (blog)
- trying rust in webassembly
- What are CJS, AMD, UMD, and ESM in Javascript?