- JavaScript Basics
- Node.js Environment
- Package Manager (npm/pnpm)
- Familiar working with terminal
- Create new folder for the project.
- In that folder, install TypeScript dependencies:
npm install typescript
- Initiate a TypeScript project:
npx tsc --init
- Create a new
.ts
file in thesrc/
folder via terminal or via UI:
mkdir src
touch src/index.ts
- Open the the project in your code editor, and update the
package.json
file with a new script:
{
"scripts": {
"dev": "tsc && node ./build/index.js"
},
"devDependencies": {
...
}
}
- 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": {
...
"rootDir": "./src",
...
"outDir": "./build",
...
}
}
- Try edit the
src/index.ts
, add several JavaScript code you know for testing the environment.
const myName = "Alfonso";
console.log(myName);
console.log("Hello World");
- If you want build and run the project, execute the build script in terminal to compile TypeScript code into JavaScript:
npm run dev
- Happy Coding.