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

Commit b675f11

Browse files
author
Orta
authored
Merge pull request #152 from Fazendaaa/master
Updating Node examples and adding some
2 parents ef9798f + 1f8ccfe commit b675f11

File tree

16 files changed

+307
-1112
lines changed

16 files changed

+307
-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: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,46 @@
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 from the this project root folder:
13+
```bash
14+
ts-node ./examples/example-name.ts
15+
```
616

7-
## Running
8-
For HttpServer
17+
To run the HTTPS server example, just:
18+
```bash
19+
ts-node ./examples/HttpServer.ts
920
```
10-
tsc --sourcemap --module commonjs HttpServer.ts
11-
node HttpServer.js
21+
22+
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
1225
```
1326

14-
For TcpServer
27+
And then running the compiled JavaScript (JS) example file with:
28+
```bash
29+
node ./dist/example-name.js
1530
```
16-
tsc --sourcemap --module commonjs TcpServer.ts
17-
node TcpServer.js
18-
```
31+
32+
## Examples
33+
* [TcpServer](./src/TcpServer.ts) - a simple TCP server
34+
* [HttpServer](./src/HttpServer.ts) - a simple HTTPS server
35+
* [API Client](./src/APIClient.ts) - client that sends a "ping"
36+
* [API Server](./src/APIServer.ts) - server the receives that "ping" and responds with a "pong"
37+
* [Word counter](./src/WordCounter.ts) - shows how many of the desired words are presented in a file
38+
* [Wikipedia Search](./src/Wikipedia.ts) - searches the [Wikipedia](https://en.wikipedia.org/w/api.php?) website
39+
40+
**note**: due to HTTP/HTTPS distinct way of handle localhost requests, in the examples HTTP is used instead of HTTPS because is a more easy way to set it up.
41+
42+
## Standards
43+
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.
44+
45+
## Git Hooks
46+
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 :)

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();

node/lorem.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"

0 commit comments

Comments
 (0)