Loading topic
let, const, and var differ, and how to run a file with Node.js or in a browser. The previous chapter explained that every module has its own scope. A named export is how a module chooses which of4 min readlet, const, and var, and how named exports work from the previous chapter. You will learn how a default export is declared and what the engine actually creates for it. You will also learn which mistakes are common and5 min readimport declaration can take, how to combine forms, and the errors that come from mixing them up. How the 4 min readimport and export declarations, which earlier chapters covered. You should also be able to run a script with Node.js and open a page in a browser. The topic here is the string that follows from. It looks like a file path, but the rules for turning it 4 min readnode from a terminal and editing a package.json file. Here the question is narrower: when Node.js loads a file, how does it d5 min readlet and const differ and how to run an ES module in Node.js or the browser. To run the examples in Node.js, put them in a folder whose package.json contains "type": "module", or rena4 min readimport declarations are fixed. They sit at the top level of a module, they name a literal string, and the engine loads every one of them before any of your code runs. That fixed structure is what makes modules predictable, but it costs you in some cases. Sometimes you don't want to load a c5 min readpackage.json contains "type": "module", or rename the files to 5 min readimport statements and 5 min readasync/await. It also assumes you have read the earlier chapters on running modules in Node.js and on how modules are linked and evaluated. The examples use .mjs files so Node.js treats them as ES modules without any extra configuration.4 min read__dirname and __filename. ES modules get a special object called import.meta, which the host environment (the browser, Node.js, Deno, or a bundler) fills with 4 min readimport and export, while a dependency, an old internal file, or a build tool config still uses require() and module.exports. This chapter explains how Node.js connects the two systems, what each direction supports, and 4 min readlet and const behave before their declaration runs. You can follow along in Node.js with a package.json that sets "type": "module", or by using .mjs files.5 min readimport syntax, default exports, and how modules load in browsers and Node.js. You should also know that modules are evaluated once and cached, as earlier chapters described. Here you will learn how to import a JSON file as a module, why the language mak5 min readnpx. It also helps to know what re-exports and barrel modules are. You do not need to have used a bundler before.5 min read