In this post, I’ll describe a quick setup to start hacking on a TypeScript project on
yarn as package manager instead of npm. I’ll use an app called readnext as example.
Create a directory and initialize yarn:
To add dependencies, use
yarn add tsc
yarn add typescript
yarn add typescript-eslint-parser
yarn add express
yarn add ts-node # for live compile+run
yarn add nodemon # will invoke ts-node when a file changes
We will use ts-node and nodemon to automate the restart of the application when we make changes. This will recompile the source and launch nodemon to keep looking for changes (as suggested in tdd). Tweak
package.json to include “scripts”:
(Oh, and now it would be a good time to init a git repo:
git init. Add
If you do
which tsc you’ll get nothing; it’s because tsc is actually inside
./node_modules/tsc/bin/tsc. Update (2019-01-07): you can run it without worrying about the exact location by running
npx tsc instead.
Start the server with
yarn start. Every time a file is changed,
localhost:3000 will change (reload to make that happen).