.JS file extension

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.

Treat “open” and “run” differently: use a code or text editor to read and change the file. To execute it, use an explicit runtime from a terminal (for example Node: node yourfile.js). Avoid double-clicking unknown .js files; on Windows especially, legacy associations can still hand .js to Windows Script Host (wscript/cscript) for JScript.

Last updated: June 11, 2026 · Reviewed by Julian Stricker

What “reviewed” means on this page
  • Format fit: whether the “what is this file?” description matches common real-world use of the extension, including category, typical MIME types, and aliases.
  • Opening paths: whether Windows / macOS / Linux steps read plausibly for current OS dialogs and default apps; we remove fantasy menus and unsafe shortcuts.
  • Security framing: whether risk notes match the extension class (for example executables vs plain data) and whether affiliate wording does not contradict the security section.
  • Sources and further reading: whether external links point to vendors, standards bodies, or other primary references where possible; we avoid inventing details we cannot ground.
  • Limits: this is clarity and safety-messaging QA, not a guarantee that every statement is exhaustive or that every binary you download is harmless.

Full methodology in the Imprint The Imprint also states where AI is used and what that does—and does not—replace.

Open on your device

Choose your operating system for a dedicated step-by-step opening guide.

How to open .JS files

Use these platform-specific instructions to open .JS files safely.

Windows

  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.
Full Windows guide

Mac

  1. To view or edit: Control-click → Open With → VS Code or another editor. Prefer that over double-click until you know how .js is associated.
  2. To run with Node: Install Node if needed, open Terminal, cd to the directory, run: node ./yourfile.js. If the file starts with #!/usr/bin/env node and is executable (chmod +x), you can run ./yourfile.js from the same directory.
  3. For web front-end projects, .js files are usually bundled or served by a dev server (Vite, webpack, etc.); follow the project README instead of guessing a generic “compatible app.”
Full Mac guide

Linux

  1. To view or edit: use your editor or IDE from the file manager’s Open With menu, or open the path directly in the editor.
  2. To run with Node: install the node package from your distro or NodeSource, then: node ./yourfile.js. Check for a shebang (#!/usr/bin/env node); if present and the file is executable, ./yourfile.js may be the intended entry.
  3. MIME associations come from shared-mime-info; if a click runs instead of editing, change the default application for JavaScript/text types to your editor.
Full Linux guide

iOS

  1. Use a code or plain-text app via Open In; iOS does not provide a full Node runtime like a desktop. For real execution or npm workflows, copy the file or clone the repo on macOS/Linux/Windows.
Full iOS guide

Android

  1. Open with a capable text/code editor app to inspect. Running Node projects reliably belongs on a desktop or server environment.
Full Android guide

Security notes

  • 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.
  • Supply-chain attacks often arrive as “run this setup.js”. Prefer opening in an editor first; use lockfiles and npm audit/yarn npm audit in real projects.
  • In the browser, only load scripts from origins you trust; inline and third-party scripts are a primary XSS surface.
  • Windows Script Host can still execute .js if associated—treat unexpected email or download attachments as malware until proven otherwise.

Before you run downloaded code

These files usually need a runtime (Python, Node, Java, …). They are not classic “file viruses,” but untrusted code can still do serious harm if you execute it. Prefer official packages, verify publishers, and scan archives or sketchy downloads when you are unsure.

We may earn a commission when you use affiliate links. This supports our free file extension guides.

Can't open this file?

These are the most common causes and fixes when .JS files fail to open.

Common reasons

  • Double-clicking runs or flashes a console instead of opening the editor
  • 'node' is not recognized (Windows) or command not found (macOS/Linux)
  • Error about "Cannot use import statement outside a module" or require()
  • The file looks fine in an editor but the browser still blocks it

Fix steps

  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.

What is a .JS file?

A .js file is almost always JavaScript/ECMAScript source. On the web, browsers load it via <script> and MIME rules (text/javascript per RFC 9239 / IANA). On machines, the same file is often run with Node.js (CommonJS require, ES module import, or package.json "type": "module"). On Unix-like systems a first line such as #!/usr/bin/env node can mark a script for execution after chmod +x. None of that changes the fact that the bytes on disk are text—your editor shows truth; execution is a separate, deliberate step.

Background

JavaScript is standardized as ECMAScript (ECMA-262) and usually stored in .js files. Web servers deliver those files to browsers, which execute them when referenced from HTML (<script src="..."></script>) under MIME and CSP rules from the HTML and Fetch standards.

Outside the browser, Node.js is the most common runtime: it resolves modules, reads package.json, and can access the filesystem and network—so “supporting the format” is the wrong mental model; you choose an editor for text and a runtime plus working directory for execution.

On Windows, legacy Windows Script Host associations may still execute .js as JScript when double-clicked. On Linux, freedesktop.org shared-mime-info maps *.js to a text/javascript concept and then to user-chosen apps. In all environments, prefer explicit node yourfile.js (or project-documented npm scripts) over opaque double-click behavior for anything you did not write yourself.

Correct Content-Type for static hosting remains text/javascript (RFC 9239); MDN documents practical browser behavior when types or module modes are wrong.

Common MIME types: text/javascript

Further reading

Authoritative resources for more details on the .JS format.

Common .JS 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.

FAQ

What is the difference between opening and running a .js file?

Opening in an editor shows text only. Running passes the file to an engine (Node, a browser context, or legacy WSH) that executes code—potentially with full user or server permissions in Node.

How do I run a .js file with Node.js?

In a terminal, change to the folder containing the file and run node ./filename.js. If the project documents npm run dev or similar, use that so the correct environment variables and bundler run.

What does a shebang like #!/usr/bin/env node mean?

On Unix-like systems it tells the kernel which interpreter to use when the file is marked executable. It does nothing on Windows by itself; there you still invoke node explicitly.

What MIME type should a web server use for .js?

text/javascript (RFC 9239; IANA). Wrong types cause browsers to refuse execution or apply unexpected sniffing rules.

Will renaming a file to .js make it JavaScript?

No. Renaming does not change bytes on disk or magically make code valid ECMAScript.

Similar file extensions

Compare related formats in the same category to find the right tool faster.