Using require
TypeScript encourages using ES Module syntax, but sometimes you will need to use the require
function
when working with Node.js and compiling to CommonJS
.
This guide covers various programming paradigms relating to the use of require
, and also provides some alternative solutions that do not depend on the use of require
.
Requiring a JSON file
A common use of require
is to load a JSON file.
Loading TypeScript...