Skip to content

Commit c195a91

Browse files
authored
Merge branch 'master' into dockerfile-dumbinit
2 parents 2d8864f + 97ac876 commit c195a91

File tree

6 files changed

+1538
-1702
lines changed

6 files changed

+1538
-1702
lines changed

.dockerignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ coverage
1717
# nyc test coverage
1818
.nyc_output
1919

20+
# TAP files
21+
out.tap
22+
junit-testresults.xml
23+
2024
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
2125
.grunt
2226

@@ -28,7 +32,6 @@ node_modules
2832
jspm_packages
2933
# Compiled binary addons (http://nodejs.org/api/addons.html)
3034
build
31-
.nyc_output
3235

3336
# Optional npm cache directory
3437
.npm

.vscode/launch.json

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
{
2-
// Use IntelliSense to learn about possible Node.js debug attributes.
3-
// Hover to view descriptions of existing attributes.
4-
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
52
"version": "0.2.0",
63
"configurations": [
74
{

README.md

+109-42
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,144 @@
1-
# TypeScript Microservice Starter ![microlib](https://user-images.githubusercontent.com/6388707/58275504-7818c880-7d95-11e9-84af-f8aa50b93d5f.png)
1+
# ![Stampo](https://user-images.githubusercontent.com/6388707/58275504-7818c880-7d95-11e9-84af-f8aa50b93d5f.png) Stampo - TypeScript Microservice Starter
22

33
[![styled with prettier](https://img.shields.io/badge/styled%20with-Prettier-blue.svg)](https://github.com/prettier/prettier)
44
[![eslint](https://img.shields.io/badge/linted%20by-eslint-brightgreen.svg)](https://eslint.org)
5-
[![tested with tap](https://img.shields.io/badge/tested%20with-node--tap-yellow.svg)](https://github.com/tapjs/node-tap) ![Node Build](https://github.com/nucleode/typescript-microservice-starter/workflows/Node%20Build/badge.svg) ![Docker Build](https://github.com/nucleode/typescript-microservice-starter/workflows/Docker%20Build/badge.svg?branch=master)
5+
[![tested with tap](https://img.shields.io/badge/tested%20with-node--tap-yellow.svg)](https://github.com/tapjs/node-tap)
6+
![Node Build](https://github.com/nucleode/typescript-microservice-starter/workflows/Node%20Build/badge.svg)
7+
![Docker Build](https://github.com/nucleode/typescript-microservice-starter/workflows/Docker%20Build/badge.svg?branch=master)
68

7-
This is an easy boilerplate for building Node.js microservices with TypeScript. Put your typescript code inside `./src` folder and you are ready to go!
9+
`Stampo` is a friction-free features-complete boilerplate for building Node.js backend services and microservices with TypeScript. It works on Windows, Linux, and macOS and makes the developer productive in no time! It supports any _Active LTS_ Node.js version (`12.12.x`, `14.x.x`, `16.x.x`).
10+
11+
There are only three steps you need to do to be productive after `Stampo` is initialized (follow the [Getting Started](#getting-started) section):
12+
1. Put your code inside the `./src` folder
13+
2. Put your tests inside the `./test` folder.
14+
3. Relax and enjoy coding!
815

916
## Features
1017

1118
* VS Code debugger configs in .vscode folder
12-
* recommended Dockerfile for secure nodejs container
13-
* tsconfig.json for [typescript compiler](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html)
19+
* recommended Dockerfile for secure Node.js production-ready images
20+
* most strict and backend specific [`tsconfig.json`](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) configuration
21+
* configured tests and reporters via [tap](https://node-tap.org)
1422

1523
## Getting Started
24+
### Clone the repo
25+
```
26+
$ git clone https://github.com/nucleode/typescript-microservice-starter.git {your_project_name}
27+
$ cd {your_project_name}
28+
```
1629

30+
### Remove references to the original starter
31+
```
32+
$ rm -rf .git && npm init
1733
```
18-
# Clone the repo
19-
git clone https://github.com/nucleode/typescript-microservice-starter.git {your_project_name}
20-
cd {your_project_name}
2134

22-
# Remove reference to the original starter
23-
rm -rf .git && npm init
35+
### Initialize a git repository with your own
36+
```
37+
$ git init
38+
```
2439

25-
# Initialize git repo with your own
26-
git init
40+
### Install development dependencies
41+
```
42+
$ npm i
43+
```
2744

28-
# Install development dependencies
29-
npm i
45+
### Add remote origin and make an initial commit
46+
```
47+
$ git remote add origin [email protected]:{your_repository}.git
48+
$ git add .
49+
$ git commit -m "Initial commit"
50+
$ git push -u origin master
51+
```
52+
### Start the development server
3053

31-
# Add remote origin and make initial commit
54+
```
55+
$ npm run dev
56+
```
57+
58+
## Included npm scripts
59+
`Stampo` includes a bunch of scripts that cover the most common scenarios for Node.js backend projects.
3260

33-
git remote add origin [email protected]:{your_repository}.git
34-
git add .
35-
git commit -m "Initial commit"
36-
git push -u origin master
61+
The commands must be run from the project's root folder.
3762

38-
# start development server
39-
npm run dev
63+
### `dev`
64+
It runs the project in development mode. It uses [`nodemon`](https://github.com/remy/nodemon) to watch the `./src/**/*.ts` files and restart the server on save. It exposes the debugger port, ready to be used via the provided VS Code configuration.
65+
```
66+
$ npm run dev
4067
```
4168

42-
## Included npm scripts
69+
### `build`
70+
It builds for production all files from the `./src` to the `./build` folder. It uses `tsc` directly and therefore checks types too. It also emits the source maps.
71+
```
72+
$ npm run build
73+
```
74+
75+
### `start`
76+
It runs previously built code from the `./build` folder. In addition, it uses `--enable-source-maps` flag for native source-maps support. Note: this flag is present in Node.js since version `12.12.x`.
77+
```
78+
$ npm run start
79+
```
80+
It is advised to run Node.js binary directly to avoid any overhead or `sigterm` propagation issues in production.
81+
```
82+
$ node --enable-source-maps build/index.js
83+
```
4384

44-
Run this commands from the project folder with `npm run "script-name"`.
45-
* `dev`: runs project in development mode, with [ts linter](https://palantir.github.io/tslint/) and `chokidar` watching `.ts` files inside `./src` folder and autorestart on save.
46-
* `build`: builds all .ts files from `./src` folder to `./build`
47-
* `lint`: lints source code using `tslint`
48-
* `update`: easily check for updates and update all dependencies
49-
* `test`: run tests using tap
50-
* `test:watch`: run tests using tap in watch mode
51-
* `test:report`: run tests using tap and adds report file
52-
* `test:reporter`: run tests using tap and convert output to mocha
85+
### `lint`
86+
It uses [`eslint`](https://eslint.org) and [`prettier`](https://prettier.io) to lint the code. It checks `./src` and `./test` folders. Note: `prettier` is run as `eslint` plugin via [`eslint-plugin-prettier`](https://github.com/prettier/eslint-plugin-prettier).
87+
```
88+
$ npm run lint
89+
```
90+
If you want to fix all of the fixable problems, run
91+
```
92+
$ npm run lint -- --fix
93+
```
94+
95+
### `update`
96+
It uses [npm-check](https://www.npmjs.com/package/npm-check) to help you upgrading your dependencies and never have any outdated and broken packages again.
97+
```
98+
$ npm run update
99+
```
100+
101+
### `test`
102+
It uses [`tap`](https://node-tap.org) to run tests. Since version 15 `tap` needs `ts-node` to run TS files, `Stampo` also includes it.
103+
```
104+
$ npm run test
105+
```
106+
107+
### `test:watch`
108+
It runs `tap` in [watch mode](https://node-tap.org/docs/watch/) with interactive repl.
109+
```
110+
$ npm run test:watch
111+
```
112+
113+
### `test:report`
114+
It runs tests and reports the results in the widely used `junit` format using [`tap-mocha-reporter`](https://www.npmjs.com/package/tap-mocha-reporter). The default `xunit` reporter can be changed to anyone from the [supported reporters list](https://node-tap.org/docs/reporting/). This command is mainly intended to be used in CI/CD environments. The generated `junit-testresults.xml` can be consumed by automatic reporting systems.
53115

54116
## External typings augmentation
55-
This starter is already configured to allow you to extend typings of external packages. The logic behind it is based on [this](https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-plugin-d-ts.html) official template. To augment a module, just create a folder with the same name as the module you are augmenting and add an index.d.ts in it. [Here](https://github.com/fox1t/fastify-websocket-router/tree/master/typings/fastify) you can find a real world example.
117+
`Stampo` is configured to allow you to extend typings of external packages using `./typings` folder. The logic behind it is based on [this](https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-plugin-d-ts.html) official template. To augment a module, create a folder with the same module name you are augmenting and add an `index.d.ts` file inside it. [Here](https://github.com/fox1t/fastify-websocket-router/tree/master/typings/fastify) you can find a real-world example.
56118

57-
## Debugging
58-
> Warning: This starter uses new V8 [inspect protocol](https://nodejs.org/api/debugger.html) so you have to use at least Node.js 7.7.4 if you want to use the included debugger settings.
119+
## Debugging Steps
120+
121+
* run the `dev` script to start your application (`$ npm run dev`)
122+
* either
123+
* use the VS Code included `attach` config for the best debugging experience
124+
<img width="327" alt="image" src="https://user-images.githubusercontent.com/1620916/129894966-15385c33-da0c-4e00-9f6f-a8ddf966e63e.png">
59125

60-
#### Steps:
61-
* start dev server with `npm run dev`
62-
* now you have two ways:
63126
* use the provided debug URL in Chrome
64-
* use VS Code included (inside .vscode folder) `attach` config (best debugging experience)
65127

66128
## Docker Support
67129

68-
This stater uses Node.js best practices and creates dummy user to start node process, instead of using root user.
130+
`Stampo` provides a `Dockerfile` that follows the best practices regarding Node.js containerized applications.
131+
* the application is run using a dedicated non-root user
132+
* the Dockerfile uses a dedicated build step
133+
69134

135+
### Build your docker image
70136
```
71-
# Go to the root of your repo created from this starter
72-
# Build your docker image
73137
docker build -t my-project-name .
138+
```
74139

75-
# run your docker container
140+
### Run your docker container
141+
142+
```
76143
docker run -p PORT:PORT my-project-name
77144
```

0 commit comments

Comments
 (0)