Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Run .js files using node.exe on Windows 7

Want to run node.js files on Windows 7 just by typing in the file name? Here's how I got it to work:

echo %pathext%

You should see .JS included in the list. This allows you to type in the script name (hello.js) and Windows will attempt to run it. Next you need to tell Windows to use node.exe instead of wscript.exe (Anyone still use that?) You'll need a CMD.exe window with Administrator privileges. Easy way to do that is to tap the 'Windows' key, type in CMD, right click when it appears in the menu and click 'Run as Administrator'. You may need a password.

When you have the CMD.exe window enter the following:

assoc .js=JavaScript
ftype JavaScript=node.exe %1 %*

This renames the .js association (it was JSFile !?!) and tells Windows to use Node.exe to run .js files.

Now try it out by running a .js file. The first time I tried it odd stuff happened. The windows dialog popped up asking me which file I wanted to use to run the file. I browsed to my installed node.js and selected that (I also clicked 'Always use this program.') Then my script ran in a new window. Not what I wanted. But the second time around it ran in the same window.

@rsbohn

This comment has been minimized.

Copy link
Owner Author

@rsbohn rsbohn commented Feb 27, 2012

You can often leave of the .js extension.

@tracker1

This comment has been minimized.

Copy link

@tracker1 tracker1 commented Sep 27, 2012

Doesn't seem to work with the latest node, in an updated Windows 7 today... :-(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment