When writing for both, 3 things are important:
- using
type="module"
in the HTML file - using
"type": "module"
in thepackage.json
file (for Node.js) - and every import statement uses
.js
extension
typeof feature != "undefined"
is used to check if a feature is available. Else, another method is used; for example console.log
for alert
.
files used:
index.html
- for Webindex.js
- entry point for bothpackage.json
- for Node.jsmain.js
- not needed, extra layermodule.js
- example module layer
to run with Node.js, just run node index.js