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
* fix typo
* fix: copying issues
* fix: fix for tslint
* port changes from PR microsoft#11
* Added survey links that I forgot ><
* fix: fix lint warnings for test files
* Bump tasks.json version from 0.10 to 2.00. Add default build task.
* updating package-lock
* looks like new version of npm adds a blank line after each npm install. Committing it
* updated specific .d.ts files to point to definitely typed file. Also added recommended extensions using vs code's extensions.json
* update to node 8 on travis
* removed yarn as npm 5 makes it mostly unneccesary and it's causing some issues with CI
* add attach debug configuration
- Attach debug configuration
- Scripts: debug, serve-debug, watch-debug
- Readme
* fix: word
* .
* Update build task
* change tests to not always pass
* separate server binding to port from other app config
this seems a bit crude but allows running the tests and having them take
care of setting up the port to use
* might as well also add the change for issue microsoft#41
* Update README.md
Added missing "node_modules/*" path mapping to README.
* feat(*): update several dependencies
* Removed extra "s" in sourceMap compilerOptions
* Update README.md
Added missing "node_modules/*" path mapping to README.
* change tests to not always pass
* feat(*): update several dependencies
* Removed extra "s" in sourceMap compilerOptions
* separate server binding to port from other app config
this seems a bit crude but allows running the tests and having them take
care of setting up the port to use
* fix up tests
* update repo field
* made some changes to mongo connection
Copy file name to clipboardExpand all lines: README.md
+20-15Lines changed: 20 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,7 @@ Navigate to `http://localhost:3000`
29
29
30
30
# TypeScript + Node
31
31
The main purpose of this repository is to show a good end-to-end project setup and workflow for writing Node code in TypeScript.
32
-
I will try to keep this as up-to-date as possible, but community contributions and recommendations for improvements are encourage and will be most welcome.
32
+
I will try to keep this as up-to-date as possible, but community contributions and recommendations for improvements are encouraged and will be most welcome.
33
33
34
34
In the next few sections I will call out everything that changes when adding TypeScript to an Express project.
35
35
Note that all of this has already been setup for this project, but feel free to use this as a reference for converting other Node.js project to TypeScript.
@@ -48,13 +48,13 @@ For other editors, make sure you have the corresponding [TypeScript plugin](http
48
48
49
49
## Project Structure
50
50
The most obvious difference in a TypeScript + Node project is the folder structure.
51
-
In a TypeScript project, you it's best to have separate _source_ and _distributable_ files.
51
+
In a TypeScript project, it's best to have separate _source_ and _distributable_ files.
52
52
TypeScript (`.ts`) files live in your `src` folder and after compilation are output as JavaScript (`.js`) in the `dist` folder.
53
53
The `test` and `views` folders remain top level as expected.
54
54
55
55
The full folder structure of this app is explained below:
56
56
57
-
> **Note!** Make sure you have already built the app using `npm run build` or `yarn run build`
57
+
> **Note!** Make sure you have already built the app using `npm run build`
| yarn.lock | Contains same dependency version info as package.json, but used with yarn |
81
80
82
81
## Building the project
83
82
It is rare for JavaScript projects not to have some kind of build pipeline these days, however Node projects typically have the least amount build configuration.
@@ -138,7 +137,7 @@ All the different build steps are orchestrated via [npm scripts](https://docs.np
138
137
Npm scripts basically allow us to call (and chain) terminal commands via npm.
139
138
This is nice because most JavaScript tools have easy to use command line utilities allowing us to not need grunt or gulp to manage our builds.
140
139
If you open `package.json`, you will see a `scripts` section with all the different scripts you can call.
141
-
To call a script, simply run `npm run <script-name>`(or `yarn run <script-name` if using yarn) from the command line.
140
+
To call a script, simply run `npm run <script-name>` from the command line.
142
141
You'll notice that npm scripts can call each other which makes it easy to compose complex builds out of simple individual build scripts.
143
142
Below is a list of all the scripts this template has available:
144
143
@@ -188,6 +187,7 @@ In the `tsconfig.json` for this project you'll see the following:
188
187
"baseUrl": ".",
189
188
"paths": {
190
189
"*": [
190
+
"node_modules/*",
191
191
"src/types/*"
192
192
]
193
193
}
@@ -205,7 +205,7 @@ The [README](https://github.com/Microsoft/dts-gen#dts-gen-a-typescript-definitio
205
205
In this project, `bcrypt-nodejs.d.ts`, `fbgraph.d.ts`, and `lusca.d.ts` were all generated using `dts-gen`.
206
206
207
207
#### Writing a `.d.ts` file
208
-
If generating a `.d.ts` using `dts-gen` isn't working, [you should tell me about it first](TODO-survey-link), but then you can create your own `.d.ts` file.
208
+
If generating a `.d.ts` using `dts-gen` isn't working, [you should tell me about it first](https://www.surveymonkey.com/r/LN2CV82), but then you can create your own `.d.ts` file.
209
209
210
210
If you just want to silence the compiler for the time being, create a file called `<some-library>.d.ts` in your `types` folder and then add this line of code:
211
211
```ts
@@ -219,7 +219,7 @@ The reason it's so easy to get great `.d.ts` files for most libraries is that de
219
219
Contributing `.d.ts` files is a great way to get into the open source community if it's something you've never tried before, and as soon as your changes are accepted, every other developer in the world has access to your work.
220
220
221
221
If you're interested in giving it a shot, check out the [guidance on DefinitelyTyped](https://github.com/definitelyTyped/DefinitelyTyped/#how-can-i-contribute).
222
-
If you're not interested, [you should tell me why](TODO-survey-link) so we can help make it easier in the future!
222
+
If you're not interested, [you should tell me why](https://www.surveymonkey.com/r/LN2CV82) so we can help make it easier in the future!
223
223
224
224
### Summary of `.d.ts` management
225
225
In general if you stick to the following steps you should have minimal `.d.ts` issues;
@@ -253,7 +253,7 @@ The best part of source maps is when configured correctly, you don't even know t
253
253
First you need to make sure your `tsconfig.json` has source map generation enabled:
254
254
```json
255
255
"compilerOptions" {
256
-
"sourceMaps": true
256
+
"sourceMap": true
257
257
}
258
258
```
259
259
With this option enabled, next to every `.js` file that the TypeScript compiler outputs there will be a `.map.js` file as well.
@@ -291,7 +291,7 @@ This is mostly identical to the "Node.js: Launch Program" template with a couple
291
291
|`"program": "${workspaceRoot}/dist/server.js",`| Modified to point to our entry point in `dist`|
292
292
|`"smartStep": true,`| Won't step into code that doesn't have a source map |
293
293
|`"outFiles": [...]`| Specify where output files are dropped. Use with source maps |
294
-
|`"protocol": inspector,`| Use the new Node debug protocal because we're on the latest node|
294
+
|`"protocol": inspector,`| Use the new Node debug protocol because we're on the latest node|
295
295
296
296
With this file in place, you can hit `F5` to serve the project with the debugger already attached.
297
297
Now just set your breakpoints and go!
@@ -300,6 +300,11 @@ Now just set your breakpoints and go!
300
300
VS Code will try to launch on the same port and error out.
301
301
Likewise be sure to stop the debugger before returning to your normal `npm start` process.
302
302
303
+
#### Using attach debug configuration
304
+
VS Code debuggers also support attaching to an already running program. The `Attach` configuration has already configured, everything you need to do is change `Debug Configuration` to `Attach` and hit `F5`.
305
+
306
+
> Tips! Instead of running `npm start`, using `npm run debug` and `Attach Configuration` that make you don't need to stop running project to debug.
307
+
303
308
## Testing
304
309
For this project, I chose [Jest](https://facebook.github.io/jest/) as our test framework.
305
310
While Mocha is probably more common, Mocha seems to be looking for a new maintainer and setting up TypeScript testing in Jest is wicked simple.
@@ -340,7 +345,7 @@ This all happens in memory when you run the tests, so there are no output `.js`
340
345
341
346
### Writing tests
342
347
Writing tests for web apps has entire books dedicated to it and best practices are strongly influenced by personal style, so I'm deliberately avoiding discussing how or when to write tests in this guide.
343
-
However, if prescriptive guidance on testing is something that you're interested in, [let me know](TODO-survey-link), I'll do some homework and get back to you.
348
+
However, if prescriptive guidance on testing is something that you're interested in, [let me know](https://www.surveymonkey.com/r/LN2CV82), I'll do some homework and get back to you.
344
349
345
350
## TSLint
346
351
TSLint is a code linter which mainly helps catch minor code quality and style issues.
@@ -397,14 +402,14 @@ In that file you'll find two sections:
0 commit comments