How do I run a .js file in my browser?
- Open Notepad by pressing Window+R from your PC.
- Press ctrl+S to save the file in your system.
- After pressing ctrl+S it will ask for the name of your file.
- Give a name of the file with . JS extension i.e. "hello. js".
All you need to do is:
- Add the shbang line to your script.
- If on unix do the chmod +x thing.
- Turn your script into an npm project (if not already an npm project) by putting it into its own folder then running npm init inside that folder (this will create a package.json file)
To try it:
- Open the Console. For example, press Control + Shift + J (Windows, Linux) or Command + Option + J (macOS).