Skip to content

Instantly share code, notes, and snippets.

@purp
Last active October 5, 2024 16:29
Show Gist options
  • Save purp/55d0d9b5e854a9c3e9e7192844b43907 to your computer and use it in GitHub Desktop.
Save purp/55d0d9b5e854a9c3e9e7192844b43907 to your computer and use it in GitHub Desktop.
A beginner's notes on using Typescript and Node.js

Overview

Quick notes on how to bootstrap a project where you intend to use Typescript and Node.js

Bootstrapping

Commands and Code

mkdir foo && cd foo
npx gitignore node
npm init
npm intall typescript --save-dev
npm install ts-node --save-dev
npx tsc --init --target es2023 --module node16 --moduleResolution node16 --resolveJsonModule true

Development

To run code: ts-node <your-file>.ts or user the shebang #!/usr/bin/env ts-node

To compile code to javascript: [to come]

Notes

  • If you're new to typescript and struggling too hard to be productive in the face of typing errors, consider setting "noImplicitAny": false in your tsconfig.json
  • If you'd like to add a license, npx license is a handy tool.
    • It writes the license file to LICENSE by default
    • Given no arguments, it provides a list of all the open source licenses to scroll or search
    • You can also provide your preferred license as an argument, like npx license mit
    • More info here.
  • npx covgen will add a Contributor Covenant for you

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment