Creating a Node.js function using TypeScript
Written by
Updated at September 23, 2024
Node.js doesn't support TypeScript
-
Install Node.js
. -
Open your project directory.
-
Install TypeScript
:npm install typescript --save-dev
-
Create a TypeScript configuration:
npx ts --init --preserveConstEnums --moduleResolution Node --isolatedModules --outDir build --strict false --target ES2021
To use a different version of JavaScript, change the value of the
target
argument. The latest JavaScript version that can be specified depends on the Node.js version you are using:Node.js version Highest JavaScript version 12 ES2019 14 ES2020 16 ES2021 -
Compile a function:
npx tsc
-
The
build
directory will appear in the project folder. Add its contents to a ZIP archive.