This repository serves as a starter template for building Node.js applications using TypeScript. It includes essential configurations and tools to streamline development and testing.
yarn build
– Compiles TypeScript files into JavaScript and outputs them to thedist
folder.yarn dev
– Starts the application in watch mode usingtsx
for live reloading.yarn start
– Runs the compiled JavaScript output from thedist
folder.yarn test
– Executes tests using Vitest.yarn format
– Formats code files using Prettier.
- Node.js 22 or later
- TypeScript
The entry point for the application is src/index.ts
. All TypeScript source files should reside in the src
directory.
This template includes:
- TypeScript: For type-safe development.
- Vitest: A fast and lightweight testing framework.
- Dotenv: For managing environment variables via
.env
files. - Prettier: For consistent code formatting.
-
Install dependencies:
yarn install
-
Start development:
yarn dev
-
Build the project:
yarn build
-
Run tests:
yarn test
File/Folder | Description |
---|---|
index.mjs |
Entry point for the Node.js runtime, sets up the TypeScript paths loader. |
LICENSE |
License file for the project. |
package.json |
Contains project metadata and dependencies. |
README.md |
Project documentation. |
ts-paths-loader.mjs |
Loader for resolving TypeScript path aliases at runtime. |
tsconfig.json |
TypeScript configuration file, including path alias definitions. |
vitest.config.ts |
Configuration for Vitest testing framework. |
vitest.setup.ts |
Setup file for Vitest tests. |
src/* |
All TypeScript source code goes here. |
The ts-paths-loader.mjs
file is a critical component of this template. It ensures that TypeScript path aliases defined in tsconfig.json
are resolved correctly at runtime. Without this loader, Node.js would not recognize these aliases, leading to module resolution errors.
TypeScript allows developers to define custom path aliases in tsconfig.json
to simplify imports and improve code organization. However, these aliases are not natively supported by Node.js. The loader bridges this gap by dynamically mapping the aliases to their corresponding file paths during runtime, ensuring seamless compatibility between TypeScript and Node.js.
Contributions are welcome! Feel free to open issues or submit pull requests to improve this template.