Categories
JavaScript Answers

How to use Node.js require inside TypeScript file?

Spread the love

To use Node.js require inside TypeScript file, we call require with import or use the import statement.

For instance, we write

import sampleModule = require("module-name");

to require the module-name module with require and import.

Or we write

import * as sampleModule from "module-name";

to import the module-name module as a default import.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *