You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1. Init a `tsconfig.json` for TypeScript options (`node ./node_modules/typescript/lib/tsc --init`)
10
+
1. Make sure you have `compilerOptions.module:commonjs` in your tsconfig.json
10
11
11
12
That's it! Fire up your IDE (e.g. `alm -o`) and play around. Now you can use all the built in node modules (e.g. `import fs = require('fs');`) with all the safety and developer ergonomics of TypeScript!
12
13
13
14
## Bonus: Live compile + run
14
15
* Add `ts-node` which we will use for live compile + run in node (`npm install ts-node --save-dev`)
15
16
* Add `nodemon` which will invoke `ts-node` whenever a file is changed (`npm install nodemon --save-dev`)
16
17
17
-
Let's explicitly tell `ts-node` where to look for types by editing `tsconfig.json`:
18
-
19
-
```json
20
-
{
21
-
"compilerOptions": {
22
-
...
23
-
"typeRoots": ["node_modules/@types"]
24
-
}
25
-
}
26
-
```
27
-
28
18
Now just add a `script` target to your `package.json` based on your application entry e.g. assuming its `index.ts`:
0 commit comments