Skip to content

from

In JavaScript, from is a contextual keyword that names the source module in an import declaration or a re-exporting export statement. The module specifier after it must be a string literal, such as "./utils.mjs" or "node:fs".

In an import declaration, from follows the list of bindings to import. In an export statement, it turns the statement into a re-export that passes another module’s bindings along without creating local ones. A side-effect import such as import "./setup.mjs"; has no bindings and no from clause. The host resolves the specifier. Node.js and browsers treat relative paths as URLs relative to the current module.

Both forms are module syntax, which only works in a module. Outside these clauses, from isn’t reserved and stays a valid identifier, even in modules. The dynamic import() syntax takes the specifier as an argument and doesn’t use from. The keyword was added together with modules in ES2015.

JavaScript from Keyword Syntax

The from keyword names the source module in import and re-export declarations. An optional with clause after the specifier passes import attributes, added in ES2025:

Language: JavaScript Syntax
import <bindings> from "<specifier>" [with { <attributes> }];
export <bindings> from "<specifier>" [with { <attributes> }];

JavaScript from Keyword Examples

The units.mjs module exports two temperature conversions:

Language: JavaScript Filename: units.mjs
export const toCelsius = (f) => ((f - 32) * 5) / 9;
export const toFahrenheit = (c) => (c * 9) / 5 + 32;

Another module, convert.mjs, imports from units.mjs and the built-in node:util module:

Language: JavaScript Filename: convert.mjs
import { toCelsius } from "./units.mjs";
import { format } from "node:util";

console.log(format("%d degrees Celsius", toCelsius(212)));

Running convert.mjs prints the converted temperature:

Language: Shell
$ node convert.mjs
100 degrees Celsius

Outside an import or export clause, from works as an ordinary name:

Language: JavaScript
> const from = "[email protected]";
undefined
> from
'[email protected]'

JavaScript from Keyword Use Cases

  • Naming the module that an import declaration reads from
  • Loading Node.js built-in modules through node: specifiers
  • Re-exporting another module’s bindings with export ... from
  • Building a single entry point that gathers several modules

Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.


By Leodanis Pozo Ramos • Updated Nov. 4, 2026