Run .mjs files from your command line, with all the tweaks from esmod-pmb.
npm install nodemjs
nodemjs
=======
Run .mjs files from your command line, with all the tweaks from esmod-pmb.
Added features:
* Legacy-resolves module names passed with -r if they would otherwise
yield the ERR_MODULE_RESOLUTION_LEGACY error.
* Pre-imports all modules listed in env var NODEMJS_PRELOAD and
npm setting nodemjs-preload (see caveats below).
Multiple module specs can be separated with spaces.
They will be loaded even before the -r pre-imports.
⚠ Incompatible with node.js v20+! ⚠
-----------------------------------
… because the upstream esm module is no longer maintained.
See issue #2.
API
---
No.
CLI
---
``text
$ nodemjs test/uc1st.mjs
uc1st: [ 'Using dummy input', 'Because there were', 'No CLI args' ]
$ ./test/uc1st.mjs foo bar qux
uc1st: [ 'Foo', 'Bar', 'Qux' ]
`
Setup
-----
1. npm install --global nodemjsnodejs
1. Make sure you have a node.js (compatible) binary available as the
command. If you use sane package sources, you probably do.nodejs
If you don't, just make a symlink to node or whatevernode
it's called on your system.
(If you'd like to argue the supremacy of the more generic nodejs
command name, file an issue, ideally after you've renamed the
Node.js foundation to Node foundation.)
As of 0.1.7, you can configure your favorite replacementNODEJS_CMD
via the env var.
Known issues
------------
* Currently no support for setting __process.mainModule__, see the
upstream bug ticket.
* __npm config caveat:__
The nodemjs-preload npm settingundefined
is currently ignored if its value as a string is literally .
If you want to pre-load a module with that name and nothing else,
put it in twice, with a space between.
See also: Duplicate pre-imports.
* __Duplicate pre-imports:__
nodemjs currently does not check whether a module you're trying to
pre-import had already been imported before.
Usually node's module cache voids all non-first import attempts
per module, so this won't matter
— unless you use cache-busting modules, in which case you're on your own.
* __REPL:__
The REPL isn't upgraded to ESM because esm currently
[cannot expose its REPL in a clean and easy way][esm-issue-592].
* The invokedAs context property for nodemjsCliMain` doesn't work.
* Needs more/better __tests and docs__.
[esm-issue-592]: https://github.com/standard-things/esm/issues/592
License
-------
ISC