Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 678b3d7

Browse files
committed
First commit.
1 parent 1a9d4f9 commit 678b3d7

File tree

13 files changed

+258
-1112
lines changed

13 files changed

+258
-1112
lines changed

node/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
dist/
3+
package-lock.json

node/HttpServer.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

node/README.md

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,55 @@
11
# TypeScript Sample: Node.js
2+
## Overview
23

3-
## Overview
4+
This sample implements a very basic [node.js](https://nodejs.org/) application using TypeScript.
45

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

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
930
```
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
1235
```
1336

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
1555
```
16-
tsc --sourcemap --module commonjs TcpServer.ts
17-
node TcpServer.js
18-
```

node/TcpServer.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

node/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Just running the command line program.
3+
*/
4+
import { ChildProcess, exec } from 'child_process';
5+
6+
const main: Function = (): ChildProcess => {
7+
let command: string = `ts-node ./src/${process.argv[3]}.ts`;
8+
9+
if (process.argv[2] === 'js') {
10+
exec('tsc');
11+
12+
command = `node ./dist/${process.argv[3]}.js`;
13+
}
14+
15+
return exec(command);
16+
};
17+
18+
main();

0 commit comments

Comments
 (0)