file1.js
console.log("foo")
file2.js
require("./file1")
➜ node file2.js
foo
How would I convert file2.js's require
to import
and keep the same logic (so no assignment)?
CodePudding user response:
You can use like below, this will import file1 to file2
import './file1';
This is useful when you want to execute the file1 code but does not want to assign it to the variable. ex:
- create a database connection if you don't need a connection object.
- TypeScript compiler generates JavaScript completely without a module definition.