How to open .JS files on Linux
To open .JS files on Linux, 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.
Step-by-step instructions
- 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.
- 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.
- 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.
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.
- Right-click → Open with → choose your editor, then use “Always” / Default apps to keep .js opening for editing.
- 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.
- Install Node.js LTS and reopen the terminal, or on Windows use the installer option to add to PATH.
- 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.
- Read the project’s package.json and README for module mode.
- 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.
- Verify response headers and <script> attributes in DevTools.
- 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.