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!
- VS Code debugger configs in .vscode folder
- recommended Dockerfile for secure nodejs container
- tsconfig.json for typescript compiler
- strict tslint.json for tslint
# Clone the repo
git clone https://github.com/nucleode/typescript-microservice-starter.git {your_project_name}
cd {your_project_name}
# Remove reference to the original starter
rm -rf .git && npm init
# Initialize git repo with your own
git init
# Install development dependencies
npm i
# Add remote origin and make initial commit
git remote add origin [email protected]:{your_repository}.git
git add .
git commit -m "Initial commit"
git push -u origin master
# start development server
npm run dev
Run this commands from the project folder with npm run "script-name"
.
dev
: runs project in development mode, with ts linter andchokidar
watching.ts
files inside./src
folder and autorestart on save.build
: builds all .ts files from./src
folder to./build
lint
: lints source code usingtslint
update
: easily check for updates and update all dependenciestest
: run tests using taptest:watch
: run tests using tap in watch modetest:report
: run tests using tap and adds report filetest:reporter
: run tests using tap and convert output to mocha
This starter is already configured to allow you to extend typings of external packages. The logic behind it is based on this 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 you can find a real world example.
Warning: This starter uses new V8 inspect protocol so you have to use at least Node.js 7.7.4 if you want to use the included debugger settings.
- start dev server with
npm run dev
- now you have two ways:
- use the provided debug URL in Chrome
- use VS Code included (inside .vscode folder)
attach
config (best debugging experience)
This stater uses Node.js best practices and creates dummy user to start node process, instead of using root user.
# Go to the root of your repo created from this starter
# Build your docker image
docker build -t my-project-name .
# run your docker container
docker run -p PORT:PORT my-project-name