2
votes

TypeScript/ESLint/Prettier have become my favorite tools for all kind of tasks. However, I am still struggling with small Nodejs-scripts that are just a few dozens lines of code. To write a small Nodejs-script with a comfortable IDE-experience, I need to:

  • Create a package.json
  • Configure tsconfig (strict compilation)
  • Configure ESLint
  • Configure Prettier
  • Compile to JavaScript if I care about startup performance (see below)

This is quite a lot of ceremony for small scripts. I have scripts where those configuration files are larger than the actual code. JavaScript-compilation is especially annoying if you just want to make a small tweak and then re-run the script.

In theory, there exists ts-node to solve those issues. However, I struggle with ts-node because of the following reasons:

  • Slow startup performance (>2 seconds for many scripts)
  • Lacks good typechecking unless you supply additional configuration
  • Lacks a good IDE-experience unless you configure all the above-mentioned stuff

Do you have any suggestions on how to quickly write small scripts, without deteriorating the ESLint/Prettier-experience?

1

1 Answers

0
votes

My solution in part to this was to write an eslint config that inspects package.json and auto configs itself to what ever tools my project is using

https://github.com/davidjbradshaw/eslint-config-auto

For the other bits I would use a simple boilier plate project as a starting point.