- JavaScript Basics
- Node.js Environment
- Package Manager (npm/pnpm)
- Install typescript dependencies:
npm install typescript
- Initiate a TypeScript project:
npx tsc --init
- Create a new
.ts
file in thesrc/
folder. You can add and edit.ts
file insrc/
folder.
mkdir src
touch src/index.ts
- Update the
package.json
file with a new script:
{
"scripts": {
"dev": "tsc && node ./build/index.js"
},
"devDependencies": {
"typescript": "^5.8.2"
}
}
- Configure the
tsconfig.json
file, add"outDir": "./build"
to specify where the compiled JavaScript files should be placed. Also, set"rootDir": "./src"
to indicate the root directory of your source files.
{
"compilerOptions": {
...
"outDir": "./build",
...
"rootDir": "./src"
...
}
}
- Happy Coding. If you want build and run the project, run the build script to compile TypeScript code into JavaScript:
npm run dev