Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ff0b56e
working on refactor
Talento90 Mar 25, 2018
fb6369a
working on refaactor
Talento90 Mar 29, 2018
b80da58
add mysql
Talento90 Mar 30, 2018
6d9d5f8
add mysql
Talento90 Mar 30, 2018
c406716
fix husky
Talento90 Mar 30, 2018
b959791
working on auth
Talento90 Apr 1, 2018
d2b8441
refactor lib
Talento90 Apr 3, 2018
a7e6e24
working on api
Talento90 Apr 3, 2018
02af846
fix users routes
Talento90 Apr 4, 2018
ec9ddf1
add users endpoints
Talento90 Apr 5, 2018
d1a4934
working on error
Talento90 Apr 6, 2018
c098780
fix endpoints
Talento90 Apr 6, 2018
2e85eed
write readme
Talento90 Apr 7, 2018
778d3a9
working on tests
Talento90 Apr 8, 2018
5028b0d
fix travis
Talento90 Apr 8, 2018
18d9884
fix travis
Talento90 Apr 8, 2018
fa6f06f
working on tests
Talento90 Apr 9, 2018
55d0b9e
working on tests
Talento90 Apr 9, 2018
7b368f9
working on tests
Talento90 Apr 10, 2018
df6b00d
working on tests
Talento90 Apr 12, 2018
f8d76b8
working on tests
Talento90 Apr 13, 2018
f497ff3
add health
Talento90 Apr 14, 2018
7c42010
add health
Talento90 Apr 14, 2018
b613fbc
add delete user
Talento90 Apr 14, 2018
edc1e7e
add delete user
Talento90 Apr 14, 2018
96e48f8
fix travis
Talento90 Apr 14, 2018
d45b56d
fix travis
Talento90 Apr 14, 2018
6293790
add coverage
Talento90 Apr 14, 2018
d9c40b6
add coverage
Talento90 Apr 14, 2018
a360a98
add coverage
Talento90 Apr 14, 2018
b4b56c9
add health unit test
Talento90 Apr 15, 2018
c247656
add integration tests in health
Talento90 Apr 15, 2018
59b1067
add more unit tests
Talento90 Apr 16, 2018
6b3a5e1
add unit tests
Talento90 Apr 17, 2018
02a9dd9
add unit tests
Talento90 Apr 17, 2018
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
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
indent_style = space
indent_size = 2

[*.json]
indent_style = space
indent_size = 2
11 changes: 3 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ lib-cov
# Coverage directory used by tools like istanbul
coverage
reports
.nyc_output


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

#VSCode
.vscode

#Ignore build folder
build

#Ignore typings
typings
#Ignore dist folder
dist

1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8.10
27 changes: 22 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
language: node_js
node_js:
- "7"
before_script:
- npm install -g typescript
- npm install -g gulp
- "8"
env:
global:
- PORT=8080
- DB_HOST=127.0.0.1
- DB_PORT=3306
- DB_USER=travis
- DB_PASSWORD=secret

services:
- mongodb
- mysql

before_install:
- mysql -u root -e "SET PASSWORD FOR 'travis'@'localhost' = PASSWORD('secret')"
- mysql -u travis --password="secret" < db-scripts/create_database.sql

install:
- npm install
- npm install -g codecov

script:
- ./node_modules/nyc/bin/nyc.js --exclude dist/test --reporter lcovonly npm run test:all
- codecov
35 changes: 35 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Mocha Tests",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"${workspaceRoot}/dist/test/**/*.js"
],
"internalConsoleOptions": "openOnSessionStart",
"remoteRoot": "/app",
"outFiles": [
"${workspaceRoot}/dist/**/*.js"
]
},
{
"type": "node",
"request": "attach",
"name": "Docker: Attach to Node",
"port": 5858,
"address": "localhost",
"localRoot": "${workspaceFolder}",
"remoteRoot": "/app",
"protocol": "inspector",
"outFiles": [
"${workspaceRoot}/dist/**/*.js"
]
}
]
}
25 changes: 5 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
FROM mhart/alpine-node:6.9.1
FROM node:8.10-alpine

MAINTAINER Talento90

# create a specific user to run this container
RUN adduser -S -D user-app

# add files to container
ADD . /app
USER nobody

# specify the working directory
WORKDIR app

RUN chmod -R 777 .

# build process
RUN npm install
RUN npm run build
RUN npm prune --production

# run the container using a specific user
USER user-app

EXPOSE 8080
# expose server and debug port
EXPOSE 8080 5858

# run application
CMD ["npm", "start"]
CMD ["node", "dist/src/index.js"]
56 changes: 28 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
# typescript-node [![Build Status](https://travis-ci.org/Talento90/typescript-node.svg?branch=master)](https://travis-ci.org/Talento90/typescript-node)
# 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)

Boilerplate template for node and typescript services.

## Deprecated
Please for an updated version look at this repository: https://github.com/dwyl/hapi-typescript-example
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:

***Features***

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

* *npm run setup* (install nuget packages & typings)
## Installation & Run

**Run**
* *npm install* - Install dependencies
* *npm run start* - Start application (It needs a mysql database)

* *gulp build* (build ts files)
* *gulp test* (run mocha tests)
* *gulp tslint* (run tslint)
* *gulp watch* (watch ts files)
* *npm run start* (start the application)
* *npm run watch* (restart the application when files change)
* *npm start* (run the application on http://localhost:5000/api/docs)
### Running with Docker

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

**Features**
## Useful npm commands

* *Project Structure - Feature oriented*
* *Hapijs - REST Api*
* *Swagger - documentation*
* *Jwt - authentication*
* *Mongoose - MongoDb*
* *nconf - configurations*
* *Unit Tests - chai + sinon + mocha*

Have fun :)
* *npm run build* - Transpile TypeScript code
* *npm run clean* - Remove dist, node_modules, coverage folders
* *npm run coverage* - Run NYC coverage
* *npm run lint* - Lint your TypeScript code
* *npm run start:dev* - Run application in dev mode (debug & watch). Debug mode is running on port 5858 (open `chrome://inspect/#devices`).
* *npm run test* - Run unit tests
* *npm run test:integration* - Run integration tests
* *npm run test:all* - Run Unit and Integration tests
1 change: 1 addition & 0 deletions db-scripts/create_database.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE DATABASE IF NOT EXISTS task_manager
28 changes: 21 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
version: '2'
version: '2.1'
services:
app:
build: .
command: npm run start:dev
environment:
- PORT=8080
- MONGO_URL=mongodb:27017
ports:
- DB_HOST=mysql
- DB_PORT=3306
- DB_USER=root
- DB_PASSWORD=secret
ports:
- "8080:8080"
- "5858:5858"
links:
- mongodb
mongodb:
image: mongo:latest
- mysql
volumes:
- .:/app/
network_mode: bridge
mysql:
image: mysql:latest
environment:
- MYSQL_DATABASE=task_manager
- MYSQL_ROOT_PASSWORD=secret
ports:
- "27017:27017"
- "3306:3306"
volumes:
- ./db-scripts:/docker-entrypoint-initdb.d
network_mode: bridge
89 changes: 0 additions & 89 deletions gulpfile.js

This file was deleted.

Loading