Why one other starter template?
I created this template to assist myself to construct some easy instruments and prototypes whereas studying Node.js
, JavaScript
and TypeScript
. There are lots of guides on the internet that present the right way to construct a CLI software with Node.js
and TypeScript
. Nevertheless, I discovered them to be too complicated for my wants.
That this template doesn’t present a solution to bundle the app for distribution. It’s meant for use for studying and prototyping or for constructing instruments that aren’t meant to be distributed.
Word: In case you are in search of even higher and extra developer’s pleasant solution to develop easy instruments and prototype take a look at Alternate options – Deno part of this text.
Code
The code is on the market on GitHub: https://github.com/kolorobot/vite-node-starter
Getting began
- Clone the repository:
git clone https://github.com/kolorobot/vite-node-starter
- Set up dependencies:
yarn
- Run pattern app:
yarn begin --say "Hiya, World!"
, ornpx vite-node src/app.ts --say "Hiya, World!"
- Outcomes:
Including new scripts
- Add script(s) to
src
listing. It may beTypeScript
orJavaScript
recordsdata. - Add any assessments to
assessments
listing. - Run the script utilizing
npx vite-node src/my-script.ts
.
That’s it!
Dependencies
The mission was created utilizing Vite
(yarn create vite
) and later modified to make use of Vite-Node
and Vitest
(and different dependencies).
Basis
- Vite – a brand new era construct software that considerably improves the event expertise.
- Vite-Node – to run recordsdata on
Node.js
utilizing Vite’s resolvers and transformers. The engine additionally powersVitest
. - Vitest – a take a look at runner. Very similar to
Jest
, however with a deal with simplicity and velocity. - TypeScript – a typed superset of JavaScript that compiles to plain
JavaScript
. - ESLint – a pluggable and configurable linter.
- Prettier – an opinionated code formatter.
Assist and utilities
- dotenv – load setting variables from a
.env
file intocourse of.env
. - chalk – a library that gives a set of instruments for styling strings within the terminal.
- commander – a library for constructing interactive command line instruments.
- inquirer – a group of widespread interactive command line consumer interfaces.
- figlet – a library that renders ASCII artwork from textual content.
The way to replace dependencies?
- Examine which dependencies are outdated –
yarn outdated
- Replace dependencies interactively –
yarn upgrade-interactive --latest
Alternate options – Deno
Deno is a free, open-source JavaScript
and TypeScript
runtime setting constructed on prime of V8 JavaScript
engine. It was created as an alternative choice to Node.js
and goals to offer a safer and environment friendly runtime expertise for builders. Not like Node.js
, Deno
doesn’t require a package deal supervisor for putting in third-party modules and consists of built-in assist for contemporary net improvement instruments comparable to WebSockets
, HTTP/HTTPS
servers, and testing frameworks. Moreover, Deno
goals to handle a number of the safety considerations current in Node.js
by providing a safer sandboxed setting for executing scripts.
Deno
can run JavaScript
or TypeScript
out of the field with no further instruments or config required. Listed below are the steps to get you began:
- Set up
Deno
runtime. I like to recommend utilizing asdf to put in it:asdf plugin add deno && asdf set up deno 1.30.0
- Create a brand new listing to your mission:
mkdir my-app && cd my-app
- Create a brand new file:
contact app.ts
- Add the next code to the file:
const title = Deno.args[0] || "World"; console.log(`Hiya, ${title}!`);
- Run the app:
deno run app.ts "John Doe"
- Bundle for
Deno
runtime:deno bundle app.ts app.bundle.js
- Run the bundled app:
deno run app.bundle.js "John Doe"
Word, to assist Deno
in your IDE, comparable to Visible Studio Code
or IntelliJ IDEA
, it is advisable to set up acceptable extension: