Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions node/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
dist/
package-lock.json
9 changes: 0 additions & 9 deletions node/HttpServer.ts

This file was deleted.

48 changes: 38 additions & 10 deletions node/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,46 @@
# TypeScript Sample: Node.js
## Overview

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

This sample implements a very basic node.js application using TypeScript
## Running
First of all, install all dependencies with:
```bash
npm install
```

Then, you can run each of the listed [examples](#examples) with the following command from the this project root folder:
```bash
ts-node ./examples/example-name.ts
```

## Running
For HttpServer
To run the HTTPS server example, just:
```bash
ts-node ./examples/HttpServer.ts
```
tsc --sourcemap --module commonjs HttpServer.ts
node HttpServer.js

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:
```bash
npm run build
```

For TcpServer
And then running the compiled JavaScript (JS) example file with:
```bash
node ./dist/example-name.js
```
tsc --sourcemap --module commonjs TcpServer.ts
node TcpServer.js
```

## Examples
* [TcpServer](./src/TcpServer.ts) - a simple TCP server
* [HttpServer](./src/HttpServer.ts) - a simple HTTPS server
* [API Client](./src/APIClient.ts) - client that sends a "ping"
* [API Server](./src/APIServer.ts) - server the receives that "ping" and responds with a "pong"
* [Word counter](./src/WordCounter.ts) - shows how many of the desired words are presented in a file
* [Wikipedia Search](./src/Wikipedia.ts) - searches the [Wikipedia](https://en.wikipedia.org/w/api.php?) website

**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.

## Standards
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.

## Git Hooks
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 :)
9 changes: 0 additions & 9 deletions node/TcpServer.ts

This file was deleted.

18 changes: 18 additions & 0 deletions node/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Just running the command line program.
*/
import { ChildProcess, exec } from 'child_process';

const main: Function = (): ChildProcess => {
let command: string = `ts-node ./src/${process.argv[3]}.ts`;

if (process.argv[2] === 'js') {
exec('tsc');

command = `node ./dist/${process.argv[3]}.js`;
}

return exec(command);
};

main();
1 change: 1 addition & 0 deletions node/lorem.txt
Original file line number Diff line number Diff line change
@@ -0,0 +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?"
Loading