How to open .JS files on Windows

To open .JS files on Windows, to view or edit: Right-click the .js file → Open with → Visual Studio Code, Notepad++, or Notepad. Set your editor as the default if Explorer keeps launching the wrong handler.

Step-by-step instructions

  1. To view or edit: Right-click the .js file → Open with → Visual Studio Code, Notepad++, or Notepad. Set your editor as the default if Explorer keeps launching the wrong handler.
  2. To run with Node.js: Install Node LTS from nodejs.org, open PowerShell or Command Prompt, cd to the script folder, then run: node .\yourfile.js (use the real filename). Read errors in the same window.
  3. If the script belongs to a Node project: open the folder that contains package.json in your editor, run npm install when the project expects it, then use npm run … or node … as documented for that repo.
  4. If double-clicking runs the file: Windows may still associate .js with Windows Script Host (wscript.exe / cscript.exe) for legacy JScript. Use Open with → your editor, and only run scripts you trust from a terminal with node yourfile.js.

Common issues

Double-clicking runs or flashes a console instead of opening the editor

File associations may point to wscript/cscript, node, or another host, so Explorer treats the file as executable.

  1. Right-click → Open with → choose your editor, then use “Always” / Default apps to keep .js opening for editing.
  2. Run scripts only from a terminal with an explicit command: node yourfile.js.

'node' is not recognized (Windows) or command not found (macOS/Linux)

Node.js is not installed or not on your PATH.

  1. Install Node.js LTS and reopen the terminal, or on Windows use the installer option to add to PATH.
  2. Confirm with node -v; if multiple versions exist, use a version manager (nvm, fnm, volta) as your team recommends.

Error about "Cannot use import statement outside a module" or require()

Node treats .js as CommonJS by default unless package.json sets "type": "module" or you use .mjs; bundlers and browsers have their own rules.

  1. Read the project’s package.json and README for module mode.
  2. Rename to .cjs/.mjs only when you understand the implications; renaming alone does not fix logic errors.

The file looks fine in an editor but the browser still blocks it

Web servers must send text/javascript (RFC 9239); HTML <script type="module"> vs classic scripts also changes behavior.

  1. Verify response headers and <script> attributes in DevTools.
  2. Consult MDN or the HTML Standard for script loading and MIME requirements.

Security note

JavaScript can perform network requests, file access (within Node permissions), and process control. Never run unfamiliar .js with node or npm npx without reading the source and understanding what install scripts execute.

Back to .JS extension page