Skip to content

Commit 39525df

Browse files
Basarat Ali SyedBasarat Ali Syed
Basarat Ali Syed
authored and
Basarat Ali Syed
committed
migrate node quick start to types
1 parent 731a974 commit 39525df

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

docs/quick/nodejs.md

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
# TypeScript with NodeJS
22
TypeScript has had *first class* support for NodeJS since inception. Here's how to get setup with a NodeJS project in TypeScript:
33

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+
```
620

721
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!
822

0 commit comments

Comments
 (0)