TypeScript configuration in a Node.js project controls how source files are type-checked and emitted as JavaScript for the runtime. A focused tsconfig.json keeps the compiler, package scripts, and Node.js module loader aligned before generated files are deployed or run.
Modern Node.js projects commonly pair NodeNext module output with an explicit "type": "module" package setting when source files use import and export. TypeScript then resolves package exports, built-in node: imports, and emitted file formats in the same style that Node.js uses at runtime.
Native Node.js TypeScript execution follows a different path. Recent Node.js releases can strip erasable type syntax from .ts files, but Node.js ignores tsconfig.json options that change emitted JavaScript, output directories, or path aliases; use tsc when the project needs a build directory, strict type checks, and JavaScript files that deployment tooling can run.
$ npm pkg get name "typescript-configure-demo"
If the directory does not have package.json yet, initialize the project before adding TypeScript configuration.
Related: How to create a Node.js project with npm
$ npm install --save-dev typescript @types/node added 3 packages, and audited 4 packages in 2s found 0 vulnerabilities
Use --save-dev for build and type-check tools that are not required by the running application.
Related: How to install a Node.js dependency
$ npm pkg set type=module
Use this setting when the project source uses import and export syntax. Projects that intentionally stay on CommonJS should keep their package type unchanged and use .cts files or require()-style source where needed.
Related: How to enable ES modules in Node.js
$ npm pkg set scripts.build="tsc -p tsconfig.json" scripts.typecheck="tsc -p tsconfig.json --noEmit" scripts.start="node dist/index.js"
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"rootDir": "src",
"outDir": "dist",
"strict": true,
"types": ["node"],
"sourceMap": true,
"noEmitOnError": true,
"skipLibCheck": true
},
"include": ["src/**/*.ts"],
"exclude": ["dist", "node_modules"]
}
rootDir keeps TypeScript source under src, outDir writes compiled JavaScript under dist, and types loads Node.js globals and built-in module declarations from @types/node.
$ mkdir -p src
import { argv } from "node:process";
const target: string = argv[2] ?? "Node.js";
console.log(`TypeScript build ready for ${target}`);
$ npm run typecheck > typescript-configure-demo@1.0.0 typecheck > tsc -p tsconfig.json --noEmit
$ npm run build > typescript-configure-demo@1.0.0 build > tsc -p tsconfig.json
$ ls dist index.js index.js.map
$ node dist/index.js Node.js TypeScript build ready for Node.js