A small boilerplate of a minimal typescript express application with automatic client and server compilation (separate), live reload and automatic testing.
Keywords: Typescript, gulp, nodejs, express, handlebars, sass, livereload, mocha, chai.
The client
directory contains all files for the client side of the application, sass and typescript/javascript files to be bundled and the handlebars templates. The bundled and compiled files will then be put into the public
folder.
The server
directory contains all server side scripts and modules. These files will be compiled to javascript and be put into the dist
directory.
The test
folder will contain all automated tests. These files are not compiled into javascript, but uses the typescript runtime environment ts-node
instead, when running npm test
.
Rename or copy .env.example
to .env
, change the environment variables to your setups preferences. (Currently only used by docker, not the application.)
Install LiveReload in Google Chrome for automatic browser reload (and make sure it is enabled).
npm install -g nodemon typescript ts-node gulp-cli
# Install.
npm install
# Start server and watch for changes.
gulp watch
# Run test suite.
npm test
docker-compose up
(But really... uninstall Windows, and use Docker with a linux distro instead.)
vagrant up
vagrant ssh
docker-compose up
To get rid of annoying TSlint errors in test files, add "tslint.exclude": "**/test/**/*.ts"
to your user settings in VS Code.
When a NodeJS-application crashes, it may report that the port used (EADDRINUSE
) is already taken when trying to restart it. The following is a way to fix that on a linux system.
ps -ax | grep node
The output will show something like:
6316 ? Sl 0:00 node dist/index.js
Find the row with the node command to start your application and note the process number, then run:
kill -9 6316
WARNING!! THIS WILL REMOVE ALL CONTAINERS AND VOLUMES! (But only this image.)
docker rm $(docker ps -a -q) && docker rmi studdb_web && docker volume rm `docker volume ls -q -f dangling=true`