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
Copy file name to clipboardExpand all lines: docs/quick/nodejs.md
+16-2
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,22 @@
1
1
# TypeScript with NodeJS
2
2
TypeScript has had *first class* support for NodeJS since inception. Here's how to get setup with a NodeJS project in TypeScript:
3
3
4
-
1. Compile with `--module` set to `"commonjs"` (as we mentioned in [modules](../project/external-modules.md))
5
-
1. Add `node.d.ts` (`typings install dt~node --global`) to your [compilation context](../project/compilation-context.md).
4
+
1. Add `node.d.ts` (`npm install @types/node --save-dev`) to your [compilation context](../project/compilation-context.md).
5
+
1. Compile with `--module` set to `"commonjs"`.
6
+
1. Add node to the global resolution by simply adding it to `types` in your tsconfig.
7
+
8
+
So your tsconfig will look like:
9
+
10
+
```json
11
+
{
12
+
"compilerOptions": {
13
+
"module": "commonjs",
14
+
"types": [
15
+
"node"
16
+
]
17
+
}
18
+
}
19
+
```
6
20
7
21
That's it! 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!
0 commit comments