|
1 | 1 | # TypeScript Sample: Node.js
|
| 2 | +## Overview |
2 | 3 |
|
3 |
| -## Overview |
| 4 | +This sample implements a very basic [node.js](https://nodejs.org/) application using TypeScript. |
4 | 5 |
|
5 |
| -This sample implements a very basic node.js application using TypeScript |
| 6 | +## Running |
| 7 | +First of all, install all dependencies with: |
| 8 | +```bash |
| 9 | +npm install |
| 10 | +``` |
| 11 | + |
| 12 | +Then, you can run each of the listed [examples](#examples) with the following command: |
| 13 | +```bash |
| 14 | +npm run example ts example-name |
| 15 | +``` |
| 16 | + |
| 17 | +To run the HTTPS server example, just: |
| 18 | +```bash |
| 19 | +npm run example ts HttpsServer |
| 20 | +``` |
| 21 | + |
| 22 | +Under the hood, this examples are running through [ts-node](https://github.com/TypeStrong/ts-node), which is not recommended in production environments. You can also build those examples with: |
| 23 | +```bash |
| 24 | +npm run build |
| 25 | +``` |
6 | 26 |
|
7 |
| -## Running |
8 |
| -For HttpServer |
| 27 | +And then running the compiled JavaScript (JS) example file with: |
| 28 | +```bash |
| 29 | +npm run example js example-name |
9 | 30 | ```
|
10 |
| -tsc --sourcemap --module commonjs HttpServer.ts |
11 |
| -node HttpServer.js |
| 31 | + |
| 32 | +Or even trough node directly: |
| 33 | +```bash |
| 34 | +node ./dist/example-name.js |
12 | 35 | ```
|
13 | 36 |
|
14 |
| -For TcpServer |
| 37 | +## Examples |
| 38 | +* [TcpServer](./src/TcpServer.ts) - a simple TCP server |
| 39 | +* [HttpsServer](./src/HttpsServer.ts) - a simple HTTPS server |
| 40 | +* [API Client](./src/APIClient.ts) - client that sends a "ping" |
| 41 | +* [API Server](./src/APIServer.ts) - server the receives that "ping" and responds with a "pong" |
| 42 | + |
| 43 | +**note**: due to HTTP/HTTPS distinct way of handle localhost requests, in the API example, HTTP is used instead of HTTPS because is a more simple way to set it up. |
| 44 | + |
| 45 | +## Standards |
| 46 | +A modified version of the [Microsoft Linter Standards](https://github.com/Microsoft/tslint-microsoft-contrib) is used. Please be mindful that they are here to help you out improve you code. |
| 47 | + |
| 48 | +## Git Hooks |
| 49 | +Due to [Husky](https://github.com/typicode/husky) integration, before any push to this Github repository, [TSLint](https://github.com/palantir/tslint) will run and then point out all the fixes that needs to be done to follow the set of code [standards](#standards); if nothing needs to be corrected, you then can push it :) |
| 50 | + |
| 51 | +## Tests |
| 52 | +Tests are a resourceful tool to add it, they serve as examples and also as guarantee that your code is doing what needs to be bone. [TDD](https://en.wikipedia.org/wiki/Test-driven_development) is a great example of this. |
| 53 | +```bash |
| 54 | +npm test |
15 | 55 | ```
|
16 |
| -tsc --sourcemap --module commonjs TcpServer.ts |
17 |
| -node TcpServer.js |
18 |
| -``` |
|
0 commit comments