To be very clear, this is an opinionated idea of how to integrate the express framework with typescript (and connect to mysql). This is not necessarily the best way to do it, instead it is what works best for me and a layout whose organization makes sense to me.
A lot of it is standard express dependencies with additional packages for type support.
- The first departure from a standard express pattern is in routes handled by express-enrouten
- I have added in lodash because I felt it helped me not reinvent the wheel despite some of the features being added into newer versions of javascript.
- Moment is super useful for any datetime needs and I eventually find myself installing this sooner or later
- Sequelize and sequelize-cli are used to create the structure inside the
dbfolder. Theconnection.tsfile provides an object connected to the db as specified in the rootconfigfolder.
For local testing I prefer to use nodemon as: nodemon --watch 'src/**/*.ts' --ignore 'src/**/*.spec.ts' --exec 'ts-node' src/index.ts
Other than that npm run start is enough. It builds the project using tsc into a dist folder serves it.
I would love to know if I can make this setup any easier, feel free to make a PR to improve it!