April 24 2020
export keyword and importexport function hello () {
console.log("hello world");
}
packagel.json
{
"name":"es-modules",
"type":"module"
}
import { hello } from './lib.js';
hello();
node main.js
esbuild --bundle --outfile=out.js main.js
node out.js
require and module.exportsfunction add (a, b) { return a + b }
function minus (a, b) { return a + b }
module.exports = { add, minus };
const { add, minus } = require('./lib');
sources: - https://www.sitepoint.com/understanding-module-exports-exports-node-js/ - https://2ality.com/2019/04/nodejs-esm-impl.html
id: bt-20200424gcoe