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
The main purpose of this repository is to show a good end-to-end project setup and workflow for writing Node code in TypeScript.
10
-
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.
10
+
We 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.
11
11
12
12
13
13
# Pre-reqs
@@ -45,15 +45,15 @@ npm start
45
45
Or, if you're using VS Code, you can use `cmd + shift + b` to run the default build task (which is mapped to `npm run build`), and then you can use the command palette (`cmd + shift + p`) and select `Tasks: Run Task` > `npm: start` to run `npm start` for you.
46
46
47
47
> **Note on editors!** - TypeScript has great support in [every editor](http://www.typescriptlang.org/index.html#download-links), but this project has been pre-configured for use with [VS Code](https://code.visualstudio.com/).
48
-
Throughout the README I'll try to call out specific places where VS Code really shines or where this project has been setup to take advantage of specific features.
48
+
Throughout the README We will try to call out specific places where VS Code really shines or where this project has been setup to take advantage of specific features.
49
49
50
50
Finally, navigate to `http://localhost:3000` and you should see the template being served and rendered locally!
51
51
52
52
# Deploying the app
53
53
There are many ways to deploy an Node app, and in general, nothing about the deployment process changes because you're using TypeScript.
54
54
In this section, I'll walk you through how to deploy this app to Azure App Service using the extensions available in VS Code because I think it is the easiest and fastest way to get started, as well as the most friendly workflow from a developer's perspective.
55
55
56
-
## Pre-reqs
56
+
## Prerequisites
57
57
-[**Azure account**](https://azure.microsoft.com/en-us/free/) - If you don't have one, you can sign up for free.
58
58
The Azure free tier gives you plenty of resources to play around with including up to 10 App Service instances, which is what we will be using.
59
59
-[**VS Code**](https://code.visualstudio.com/) - We'll be using the interface provided by VS Code to quickly deploy our app.
@@ -64,7 +64,7 @@ The easiest way to achieve this is by using a managed cloud database.
64
64
There are many different providers, but the easiest one to get started with is [MongoLab](#mlab).
65
65
66
66
### <aname="mlab"></a> Create a managed MongoDB with MongoLab
67
-
1. Navigate to [MongoLab's Website](https://mlab.com/), sign up for a free account, and then log in.
67
+
1. Navigate to [mLab's Website](https://mlab.com/), sign up for a free account, and then log in.
68
68
2. In the **MongoDB Deployments** section, click the **Create New** button.
69
69
3. Select any provider (I recommend **Microsoft Azure** as it provides an easier path to upgrading to globally distributed instances later).
70
70
4. Select **Sandbox** to keep it free unless you know what you're doing, and hit **Continue**.
@@ -104,7 +104,7 @@ You can confirm that everything worked by seeing your Azure subscription listed
104
104
Additionally you should see the email associated with your account listed in the status bar at the bottom of VS Code.
105
105
106
106
### Build the app
107
-
Building the app locally is required for before a zip deploy because the App Service won't execute build tasks.
107
+
Building the app locally is required before a zip deploy because the App Service won't execute build tasks.
108
108
Build the app however you normally would:
109
109
-`ctrl + shift + b` - kicks off default build in VS Code
110
110
- execute `npm run build` from a terminal window
@@ -143,7 +143,7 @@ Deployment can fail for various reasons, if you get stuck with a page that says
143
143
144
144
# TypeScript + Node
145
145
In the next few sections I will call out everything that changes when adding TypeScript to an Express project.
146
-
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.
146
+
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 projects to TypeScript.
147
147
148
148
## Getting TypeScript
149
149
TypeScript itself is simple to add to any project with `npm`.
@@ -176,7 +176,7 @@ The full folder structure of this app is explained below:
176
176
|**src/public**| Static assets that will be used client side |
177
177
|**src/types**| Holds .d.ts files not found on DefinitelyTyped. Covered more in this [section](#type-definition-dts-files)|
178
178
|**src**/server.ts | Entry point to your express app |
179
-
|**test**| Contains your tests. Seperate from source because there is a different build process. |
179
+
|**test**| Contains your tests. Separate from source because there is a different build process. |
180
180
|**views**| Views define how your app renders on the client. In this case we're using pug |
181
181
| .env.example | API keys, tokens, passwords, database URI. Clone this, but don't check it in to public repos. |
182
182
| .travis.yml | Used to configure Travis CI build |
@@ -188,7 +188,7 @@ The full folder structure of this app is explained below:
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.
191
+
It is rare for JavaScript projects not to have some kind of build pipeline these days. However, Node projects typically have the least amount of build configuration.
192
192
Because of this I've tried to keep the build as simple as possible.
193
193
If you're concerned about compile time, the main watch task takes ~2s to refresh.
194
194
@@ -229,7 +229,7 @@ Let's dissect this project's `tsconfig.json`, starting with the `compilerOptions
229
229
230
230
231
231
232
-
The rest of the file define the TypeScript project context.
232
+
The rest of the file defines the TypeScript project context.
233
233
The project context is basically a set of options that determine which files are compiled when the compiler is invoked with a specific `tsconfig.json`.
234
234
In this case, we use the following to define our project context:
235
235
```json
@@ -363,7 +363,7 @@ Source maps allow you to drop break points in your TypeScript source code and ha
363
363
> **Note!** - Source maps aren't specific to TypeScript.
364
364
Anytime JavaScript is transformed (transpiled, compiled, optimized, minified, etc) you need source maps so that the code that is executed at runtime can be _mapped_ back to the source that generated it.
365
365
366
-
The best part of source maps is when configured correctly, you don't even know they exist! So let's take a look at how we do that in this project.
366
+
The best part of source maps is, when configured correctly, you don't even know they exist! So let's take a look at how we do that in this project.
367
367
368
368
#### Configuring source maps
369
369
First you need to make sure your `tsconfig.json` has source map generation enabled:
@@ -523,7 +523,7 @@ In that file you'll find two sections:
523
523
| node-sass | Allows to compile .scss files to .css |
524
524
| nodemon | Utility that automatically restarts node process when it crashes |
525
525
| supertest | HTTP assertion library. |
526
-
| ts-jest | A preprocessor with sourcemap support to help use TypeScript wit Jest.|
526
+
| ts-jest | A preprocessor with sourcemap support to help use TypeScript with Jest.|
527
527
| ts-node | Enables directly running TS files. Used to run `copy-static-assets.ts`|
528
528
| tslint | Linter (similar to ESLint) for TypeScript files |
@@ -532,3 +532,7 @@ To install or update these dependencies you can use `npm install` or `npm update
532
532
533
533
# Hackathon Starter Project
534
534
A majority of this quick start's content was inspired or adapted from Sahat's excellent [Hackathon Starter project](https://github.com/sahat/hackathon-starter).
535
+
536
+
## License
537
+
Copyright (c) Microsoft Corporation. All rights reserved.
0 commit comments