A minimal express server starter with TypeScript
- Make sure you have node.js installed locally
- Once you have node.js installed, add yarn to your global local directories with this command in terminal:
npm i -g yarn
- After you cloned this repo down to your local machine, start with installing dependencies by:
yarn install
- To start developing locally, use the command below:
yarn start:dev
-
yarn build
creates a production build of the server code in the build folder, which is ignored by git, in the project root. -
yarn start
runs the production build in build folder, will error out if the build folder doesn't exist. -
yarn start:dev
runs the development server and will live reload the server on ts file saves. -
yarn clean
removes yarn caches and output folders, then re-installs node_modules. -
yarn clean:dev
does the job ofyarn clean
but starts development server immediately after. -
yarn test
runs a jest unit test. -
yarn test:watch
runs jest in watch mode. -
yarn test:ci
runs jest in CI mode, most likely gets called in the CI scripts. -
yarn test:coverage
runs jest and has it return coverage report, then opens the generated coverage report html on the browser. -
yarn tslint
runs the linter on all typescript code. -
yarn lint-staged
runs the linter on all staged files in git, this command is most likely called by husky before creating a git commit. -
yarn semantic-release
runs the semantic-release package to bump package.json version and create git release tag. This is most likely called by Travis CI, but can be ran locally to do a dry-run without actually publishing a release.
Explanations for why they exist in this project. (Ignoring @types/* since they are just type definitions for the corresponding library)
- body-parser: express middleware that parses
req.body
into a trustable JSON before getting to the controllers. - compression: express middleware that compresses response bodies for all requests.
- cors: express middleware that adds CORS control on requests and responses, allowing developers to restrict origins, types, and etc. of all the calls coming in and out.
- dotenv: a library that puts all config variables defined in
.env
file intoprocess.env
. - express: popular node.js server framework.
- moment: popular date time utility library.
- morgan: express middleware that logs the status for all requests.
- winston: popular logging library that is highly customizable.
- @semantic-release/commit-analyzer: semantic-release plugin that analyzes commit messages to determine if a version bump is required.
- @semantic-release/git: semantic-release plugin that pushes git version tags and files that are generated for release to git remote.
- @semantic-release/npm: semantic-release plugin that updates the package.json version and publish package to npm (optional, so disabled for this starter).
- @semantic-release/release-notes-generator: semantic-release plugin that generates release notes based on commit messages.
- conventional-changelog-express: a library that multiple semantic-release plugins rely on.
- husky: git hooks configuration to call scripts before commit, push, and more.
- jest: popular testing framework.
- lint-staged: run linter to format staged files in git, used with husky to lint staged files before a commit.
- nodemon: listens to file saves and live reloads server during development.
- prettier: code formatter that makes code more readable.
- semantic-release: automatic release version management, the documentation for the workflow of the setup for this starter is available here.
- ts-jest: TypeScript preprocessor for Jest.
- ts-node: node.js that works with TypeScript so that no need to do
tsc
on every file save during development. - tslint: TypeScript linter.
- tslint-config-prettier: TSLint plugin that works with Prettier to remove conflicts.
- typescript: A JavaScript that enforces typing.
These libraries are not in this repo but they are some go-tos for certain functionalities.
- apollo server: popular GraphQL server framework.
- artillery: load testing framework that allows developers to customize load test scenarios.
- async: JavaScript promise utils library.
- axios: http client for both browser and node.js.
- jsonwebtoken: library that creates/verifies jwts.
- knex: SQL query builder.
- lodash: popular object/array/etc. utility library.
- mongoose: mongoDB node.js library.
- nodemailer: email cilent for node.js.
- node-postgres: PostGres client for node.js.
- node_redis: node.js client for Redis, which helps cache content to boost response time.
- passport: authentication middleware that supports 300+ kinds of log in methods, including traditional username/password, Facebook, Google, OAuth, SAML, etc.
- rabbitMQ: message broker which queues heavy duties, such as sending email and generating PDFs.