Typescript + Docker + Express + Mongoose = Awesome
About this
This project is a fully working bootstrap for developping an express-mongoose api with typescript.
Why is it awesome ?
- the ONLY install you need is docker. Don't worry about installing mongo, npm or whatever else. Docker-compose takes all the leverage for you (see Installation).
- Typescript is awesome, and it's not only for frontend users. your code is checked against a LOT of possible mistakes. Try inserting some typos such as
ssend(...)
instead ofsend()
and see the console warn you about it. - Possible usage of
await/async
and/or Promise-style code => no Callback Hell - Linters are already installed. Keep your code clean.
- Automated mocha unit testing. Mocha tests are written in ts, but run on the transpiled javascript code. So the actual transpiled application is properly tested.
- Automated testing by codeship on code commit. They run the same container as you do : if it works at home, it works on CI-servers.
Installation
- clone the repo
- run
docker-compose up
- browse
http://localhost:9000/api/ping
,http://localhost:9000/api/ping/fail
,http://localhost:9000/api/views/visit
- profit
Useful knowledge
Rebuilding the images
After adding new npm or typings package, you will have to rebuild your images as follows:
docker-compose kill
docker-compose rm
docker-compose build
docker-compose up
Add new npm package:
docker-compose run api yarn add <wathever>
, then rebuild the images
Can I deploy ?
I'v not yet automated the deployment. For now you can do whatever you want with the /dist
folder, that contains the transplied js
code.
Typos
Typescript validations are awesome:
Await
Typescript support async/await and this build let you take advantage of it. See /api/views
for two implementations of a simple mongoose request.
The code now looks like as it where synchronous, but does not block the thread:
Continuous Testing
The config provided in codeship-services.yml
and codeship-steps.yml
will trigger a build at each code commit, provided you have connected account.