Is there a way to execute node.js files from Powershell without calling the file with node before the file name?
Example:
Now I'm executing it like this: node .\script.mjs.
I would like to execute it with the name only: .\script.mjs.
How to?
CodePudding user response:
You can register the .mjs file extension to be opened with node.exe by default. Then you can call node by just providing a path to a .mjs file. Steps:
- Right click any
.mjsfile - Click on Open with / Open with...
- Click on Choose another app / More apps ↓ > Look for another app on this PC
- Navigate to your
node.exefile - Tick the Always use this app to open .mjs files checkbox
- Confirm with OK
Now you can just enter .\script.mjs in CMD or PowerShell to automatically open the file with node.
CodePudding user response:
Maybe you can create an executable from that file using vercel/pkg, then can run pkg .\script.mjs -t win to create an exe file using pkg
