https://nodejs.org/en/learn/typescript/run-natively July Security Release is available [ ] LearnAboutDownloadBlogDocsContributeCertification Change pageRunning TypeScript Natively[]Getting Started Introduction to Node.jsHow much JavaScript do you need to know to use Node.js?Differences between Node.js and the BrowserThe V8 JavaScript EngineAn introduction to the npm package manager ECMAScript 2015 (ES6) and beyondNode.js, the difference between development and productionNode.js with WebAssemblyDebugging Node.jsProfiling Node.js ApplicationsFetching data with Node.js WebSocket client with Node.jsSecurity Best Practices TypeScript Introduction to TypeScriptRunning TypeScript NativelyRunning TypeScript with a runnerRunning TypeScript code using transpilationPublishing a TypeScript package Asynchronous Work Asynchronous flow controlOverview of Blocking vs Non-Blocking JavaScript Asynchronous Programming and CallbacksDiscover Promises in Node.jsDiscover JavaScript TimersThe Node.js Event LoopThe Node.js Event EmitterUnderstanding process.nextTick() Understanding setImmediate()Don't Block the Event Loop Manipulating Files Node.js file statsNode.js File PathsWorking with file descriptors in Node.jsReading files with Node.jsWriting files with Node.js Working with folders in Node.jsHow to work with Different Filesystems Command Line Run Node.js scripts from the command lineHow to read environment variables from Node.jsHow to use the Node.js REPLOutput to the command line using Node.jsAccept input from the command line in Node.js Userland Migrations Introduction to Userland Migrations Modules Publishing a packageHow to publish a Node-API packageAnatomy of an HTTP TransactionABI StabilityHow to use streamsBackpressuring in Streams Diagnostics User JourneyMemoryLive DebuggingPoor PerformanceFlame Graphs Test Runner Discovering Node.js's test runnerUsing Node.js's test runner Mocking in testsCollecting code coverage in Node.js Running TypeScript Natively Since v23.6.0, Node.js enables "type stripping" by default. If you are using v23.6.0 or later and your source code contains only erasable typescript syntax, you do not need this article. Running TypeScript code with Node.js Since V22.6.0, Node.js has experimental support for some TypeScript syntax via "type stripping". You can write code that's valid TypeScript directly in Node.js without the need to transpile it first. The --experimental-strip-types flag tells Node.js to strip the type annotations from the TypeScript code before running it. node --experimental-strip-types example.ts ShellCopy to clipboard And that's it! You can now run TypeScript code directly in Node.js without the need to transpile it first, and use TypeScript to catch type-related errors. In V22.7.0 this experimental support was extended to transform TypeScript-only syntax, like enums and namespace, with the addition of the --experimental-transform-types flag. Enabling --experimental-transform-types automatically implies that --experimental-strip-types is enabled, so there's no need to use both flags in the same command: node --experimental-transform-types another-example.ts ShellCopy to clipboard From v23.6.0 onwards, type stripping is enabled by default (you can disable it via --no-experimental-strip-types), enabling you to run any supported syntax, so running files like the one below with node file.ts is supported: function foo(bar: number): string { return 'hello'; } TypeScriptCopy to clipboard However, running any code that requires transformations, like the code below still needs the use of --experimental-transform-types: enum MyEnum { A, B, } console.log(MyEnum.A); TypeScriptCopy to clipboard Future versions of Node.js will include support for TypeScript without the need for a command line flag. Limitations At the time of writing, the experimental support for TypeScript in Node.js has some limitations. You can get more information on the API docs. Configuration The Node.js TypeScript loader (Amaro) does not need or use tsconfig.json to run TypeScript code. We recommend configuring your editor and tsc to reflect Node.js behavior by creating a tsconfig.json using the compilerOptions listed here, as well as using TypeScript version 5.7 or higher. Important notes Thanks to all the contributors who have made this feature possible. We hope that this feature will be stable and available in the LTS version of Node.js soon. We can understand that this feature is experimental and has some limitations; if that doesn't suit your use-case, please use something else, or contribute a fix. Bug reports are also welcome, please keep in mind the project is run by volunteers, without warranty of any kind, so please be patient if you can't contribute the fix yourself. PrevIntroduction to TypeScriptNextRunning TypeScript with a runner Reading Time 2 min Authors AMKJR Contribute Edit this page Table of Contents 1. Running TypeScript code with Node.js 2. Limitations 3. Configuration 4. Important notes 1. 2. TypeScript 3. Running TypeScript Natively Trademark PolicyPrivacy PolicyVersion SupportCode of ConductSecurity Policy (c) OpenJS Foundation