Skip to content

Commit 44173d0

Browse files
authored
Merge pull request #13 from Talento90/refactor-template
Refactor template
2 parents 757e3de + 02a9dd9 commit 44173d0

File tree

95 files changed

+9328
-1589
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+9328
-1589
lines changed

.editorconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ insert_final_newline = true
1010

1111
[*.md]
1212
trim_trailing_whitespace = false
13+
indent_style = space
14+
indent_size = 2
15+
16+
[*.json]
17+
indent_style = space
18+
indent_size = 2

.gitignore

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ lib-cov
1414
# Coverage directory used by tools like istanbul
1515
coverage
1616
reports
17+
.nyc_output
1718

1819

1920
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
@@ -29,12 +30,6 @@ build/Release
2930
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
3031
node_modules
3132

32-
#VSCode
33-
.vscode
34-
35-
#Ignore build folder
36-
build
37-
38-
#Ignore typings
39-
typings
33+
#Ignore dist folder
34+
dist
4035

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8.10

.travis.yml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
11
language: node_js
22
node_js:
3-
- "7"
4-
before_script:
5-
- npm install -g typescript
6-
- npm install -g gulp
3+
- "8"
4+
env:
5+
global:
6+
- PORT=8080
7+
- DB_HOST=127.0.0.1
8+
- DB_PORT=3306
9+
- DB_USER=travis
10+
- DB_PASSWORD=secret
11+
712
services:
8-
- mongodb
13+
- mysql
14+
15+
before_install:
16+
- mysql -u root -e "SET PASSWORD FOR 'travis'@'localhost' = PASSWORD('secret')"
17+
- mysql -u travis --password="secret" < db-scripts/create_database.sql
18+
19+
install:
20+
- npm install
21+
- npm install -g codecov
22+
23+
script:
24+
- ./node_modules/nyc/bin/nyc.js --exclude dist/test --reporter lcovonly npm run test:all
25+
- codecov

.vscode/launch.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "launch",
10+
"name": "Mocha Tests",
11+
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
12+
"args": [
13+
"${workspaceRoot}/dist/test/**/*.js"
14+
],
15+
"internalConsoleOptions": "openOnSessionStart",
16+
"remoteRoot": "/app",
17+
"outFiles": [
18+
"${workspaceRoot}/dist/**/*.js"
19+
]
20+
},
21+
{
22+
"type": "node",
23+
"request": "attach",
24+
"name": "Docker: Attach to Node",
25+
"port": 5858,
26+
"address": "localhost",
27+
"localRoot": "${workspaceFolder}",
28+
"remoteRoot": "/app",
29+
"protocol": "inspector",
30+
"outFiles": [
31+
"${workspaceRoot}/dist/**/*.js"
32+
]
33+
}
34+
]
35+
}

Dockerfile

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,12 @@
1-
FROM mhart/alpine-node:6.9.1
1+
FROM node:8.10-alpine
22

3-
MAINTAINER Talento90
4-
5-
# create a specific user to run this container
6-
RUN adduser -S -D user-app
7-
8-
# add files to container
9-
ADD . /app
3+
USER nobody
104

115
# specify the working directory
126
WORKDIR app
137

14-
RUN chmod -R 777 .
15-
16-
# build process
17-
RUN npm install
18-
RUN npm run build
19-
RUN npm prune --production
20-
21-
# run the container using a specific user
22-
USER user-app
23-
24-
EXPOSE 8080
8+
# expose server and debug port
9+
EXPOSE 8080 5858
2510

2611
# run application
27-
CMD ["npm", "start"]
12+
CMD ["node", "dist/src/index.js"]

README.md

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
# typescript-node [![Build Status](https://travis-ci.org/Talento90/typescript-node.svg?branch=master)](https://travis-ci.org/Talento90/typescript-node)
1+
# typescript-node [![Build Status](https://travis-ci.org/Talento90/typescript-node.svg?branch=master)](https://travis-ci.org/Talento90/typescript-node) [![codecov](https://codecov.io/gh/Talento90/typescript-node/branch/master/graph/badge.svg)](https://codecov.io/gh/Talento90/typescript-node)
22

3-
Boilerplate template for node and typescript services.
43

5-
## Deprecated
6-
Please for an updated version look at this repository: https://github.com/dwyl/hapi-typescript-example
4+
Template for building nodejs and typescript services. The main goal of this boilerplate is to offer a good Developer Experience (eg: debugging, watch and recompile) by providing the following features out of the box:
75

6+
***Features***
87

9-
**Installation**
8+
* Language - [TypeScript](https://www.typescriptlang.org/)
9+
* REST API - [koa2](http://koajs.com/)
10+
* Graceful Shutdown - [Pattern](https://nemethgergely.com/nodejs-healthcheck-graceful-shutdown/)
11+
* HealthCheck - [Patern /health](http://microservices.io/patterns/observability/health-check-api.html)
12+
* SQL Database & Migrations - [knex](http://knexjs.org/)
13+
* Authentication and Authorization - [JWT Tokens](https://github.com/auth0/node-jsonwebtoken)
14+
* Validation - [Joi](https://github.com/hapijs/joi)
15+
* Testing - [Mocha](https://mochajs.org/) [Chai](http://www.chaijs.com/) + [Sinon](http://sinonjs.org/) [Coverage](https://istanbul.js.org/)
16+
* Code Style - [Prettier](https://prettier.io/)
17+
* Git Hooks - [Husky](https://github.com/typicode/husky)
1018

11-
* *npm run setup* (install nuget packages & typings)
19+
## Installation & Run
1220

13-
**Run**
21+
* *npm install* - Install dependencies
22+
* *npm run start* - Start application (It needs a mysql database)
1423

15-
* *gulp build* (build ts files)
16-
* *gulp test* (run mocha tests)
17-
* *gulp tslint* (run tslint)
18-
* *gulp watch* (watch ts files)
19-
* *npm run start* (start the application)
20-
* *npm run watch* (restart the application when files change)
21-
* *npm start* (run the application on http://localhost:5000/api/docs)
24+
### Running with Docker
2225

23-
**Docker**
24-
* *docker-compose build* (compose images)
25-
* *docker-compose up* (running containers)
26-
* *browser: http://localhost:8080/docs* (have fun :)
26+
* *docker-compose up* (compose and run, it also creates the mysql database)
27+
* *docker-compose down* (Destroy application and mysql containers)
2728

28-
**Features**
29+
## Useful npm commands
2930

30-
* *Project Structure - Feature oriented*
31-
* *Hapijs - REST Api*
32-
* *Swagger - documentation*
33-
* *Jwt - authentication*
34-
* *Mongoose - MongoDb*
35-
* *nconf - configurations*
36-
* *Unit Tests - chai + sinon + mocha*
37-
38-
Have fun :)
31+
* *npm run build* - Transpile TypeScript code
32+
* *npm run clean* - Remove dist, node_modules, coverage folders
33+
* *npm run coverage* - Run NYC coverage
34+
* *npm run lint* - Lint your TypeScript code
35+
* *npm run start:dev* - Run application in dev mode (debug & watch). Debug mode is running on port 5858 (open `chrome://inspect/#devices`).
36+
* *npm run test* - Run unit tests
37+
* *npm run test:integration* - Run integration tests
38+
* *npm run test:all* - Run Unit and Integration tests

db-scripts/create_database.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CREATE DATABASE IF NOT EXISTS task_manager

docker-compose.yml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
1-
version: '2'
1+
version: '2.1'
22
services:
33
app:
44
build: .
5+
command: npm run start:dev
56
environment:
67
- PORT=8080
7-
- MONGO_URL=mongodb:27017
8-
ports:
8+
- DB_HOST=mysql
9+
- DB_PORT=3306
10+
- DB_USER=root
11+
- DB_PASSWORD=secret
12+
ports:
913
- "8080:8080"
14+
- "5858:5858"
1015
links:
11-
- mongodb
12-
mongodb:
13-
image: mongo:latest
16+
- mysql
17+
volumes:
18+
- .:/app/
19+
network_mode: bridge
20+
mysql:
21+
image: mysql:latest
22+
environment:
23+
- MYSQL_DATABASE=task_manager
24+
- MYSQL_ROOT_PASSWORD=secret
1425
ports:
15-
- "27017:27017"
26+
- "3306:3306"
27+
volumes:
28+
- ./db-scripts:/docker-entrypoint-initdb.d
29+
network_mode: bridge

gulpfile.js

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

0 commit comments

Comments
 (0)