This template provides a foundational structure for creating web applications in Node.js with the Express framework. It leverages essential tools such as swc, TypeScript, ESLint, and Prettier to streamline development, ensuring high performance, adherence to coding standards, and efficient code optimization. The server responds on http://localhost:3000 with a JSON message: { ok: true }, indicating proper functionality.
This template has undergone substantial improvements to enhance code quality, maintenance, and tooling integration. Key changes include:
-
Dependency Updates: Updated versions of dependencies, including "@swc/cli," "@swc/core," and "@swc-node/register," to their latest releases.
-
ESLint Configuration: Simplified and refined ESLint configurations in the
.eslintrc.jsonfile, now extending@guarapi/eslint-config-guarapiwhile removing specific rules. -
VSCode Configuration: Adjusted Visual Studio Code settings in the
settings.jsonfile, modifying ESLint action to "explicit" on code save. -
Prettier Configuration: Introduced a specific Prettier configuration in the
package.jsonfile, referencing@guarapi/eslint-config-guarapi/prettierrc.js. -
Updates to npm Scripts: Enhanced npm scripts, including the addition of the "types" script for executing TypeScript and "lint" script for linting.
-
Versions of Development Dependencies: Updated versions of development dependencies, such as ESLint, TypeScript, Prettier, among others. This template now utilizes pnpm as the package manager to manage dependencies more efficiently.
These changes aim to improve code quality, maintenance, and the integration of linting and formatting tools within the "node-swc-template" project.
This project depends on the following tooling packages:
- swc: A high-speed JavaScript and TypeScript compiler written in Rust.
- eslint + prettier: Static code analysis tools identifying problematic patterns in JavaScript code.
- rimraf: A package providing a platform-independent way to execute the
rm -rfcommand. - nodemon: Tools monitoring project file changes and automatically restarting the server.
- @swc/register: Compiles TypeScript files on the fly, used in the development task by nodemon.
To install project dependencies, run the following command:
pnpm installTo initiate the application in production, executing the code in the dist folder, run:
pnpm startThis command launches the application by executing the index.js file in the dist folder.
To run the project in development mode, use:
pnpm run devThis starts nodemon, monitoring file changes and restarting the server automatically.
To build the project for production, run:
pnpm run buildThis uses swc to transpile TypeScript files into JavaScript, placing them in the dist folder.
To remove artifacts, run:
pnpm run cleanThis deletes the dist folder, containing files generated by swc.
To check if the code adheres to ESLint and Prettier rules, run:
pnpm run lintThis displays potential errors and warnings in the code, along with suggestions for resolution.
To execute TypeScript and check types, run:
pnpm run typesThis task ensures type correctness and validates TypeScript files in the project.