https://github.com/ho-cooh/typescriptdevwithvscode
Guide about setting up Typescript development with node and vscode
https://github.com/ho-cooh/typescriptdevwithvscode
node typescript vscode
Last synced: 13 days ago
JSON representation
Guide about setting up Typescript development with node and vscode
- Host: GitHub
- URL: https://github.com/ho-cooh/typescriptdevwithvscode
- Owner: HO-COOH
- Created: 2022-11-30T15:01:06.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-11-30T15:05:22.000Z (over 3 years ago)
- Last Synced: 2025-04-04T17:25:50.014Z (about 1 year ago)
- Topics: node, typescript, vscode
- Homepage:
- Size: 390 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# TypeScript Development with VSCode
This mainly serves as a reminder or "reference" to create a project and be able to debug it within VSCode.
Share it freely if you find this helpful.
## Prepreation
### Install node and npm
Open a powershell/cmd, and type
```
winget install Node.js
```
### Install VSCode
### Create a project
Create a folder which contains your project, open a terminal there and type
```
npm init -y
npm i typescript --save-dev
npm i -D @types/node
```
where `-y` means [continues without asking any questions](https://docs.npmjs.com/cli/v9/commands/npm-init#yes).
And you should see this and a `package.json` created under the folder.
### Modify `package.json`
1. Change `"type": "script"` -> `"type": "module"`, which would enable the ES module syntax, so you can use `import` instead of `require`, when using a module.
2. Under the `scripts` object, add `"build": "tsc"`, which would run the typescript compiler when `build` task is executed.
Your `package.json` should look like this
```json
{
"name":
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/node": "^18.11.9",
"typescript": "^4.9.3"
}
}
```
### Create `tsconfig.json`
Create `tsconfig.json` file, and copy the following content
```json
{
"compilerOptions": {
"module": "NodeNext",
"moduleResolution": "NodeNext",
"target": "ES2020",
"sourceMap": true,
"outDir": "dist"
},
"include": ["src/**/*"]
}
```
Now you should have your two `json` files like this

### Create source files
Create a folder named `src`, and in inside it, create your `index.ts`, like this

Now you should be able to run and debug with `F5` inside VsCode.
