This is a skeleton project intended for projects requiring the use of Node with TypeScript. The solution is initially designed for general use but provides capabilities for unit testing, HTTP, and environment variable management.
This project primarily includes the following libraries and elements.
Follow these steps to set up the project on your local machine:
-
Clone the repository
Clone the project repository from GitHub:git clone https://github.com/JuniorCarrillo/nodets.git cd nodets
-
Install the dependencies Install the project dependencies using npm:
npm install --legacy-peer-deps
-
Configure environment variables Create a
.env
file in thesrc/app
directory and define your environment variables as needed. Here's an example:PORT=3000 NODE_ENV=development
-
Start the project Start the project using the following command:
npm start
The server should now be running at
http://localhost:3000
. -
Run the tests To run the unit tests, use:
npm test
This command will run all the tests in the
src/test
directory. -
Build the project To build the project, use:
npm run build
This command will compile the TypeScript code into JavaScript and place it in the
dist
directory.
Examples of how to use the project after installation. For example:
npm start
This command will start the project with the default configuration:
- Jest for unit testing
- Express for HTTP server
- DotEnv for environment variables
- Winston for logging
- TypeScript for code compilation
- Eslint for code linting
- Prettier for code formatting
- Husky for pre-commit hooks
- Nodemon for development server
- TS-node for TypeScript Node integration
The main.ts
file is the main application file where an example of how to use the project can be seen.
import express from "express";
import env from "./app.env";
import logger from "./app.logger";
const main = express();
const rootHandler = (req: express.Request, res: express.Response) => {
res.send("The sedulous hyena ate the antelope!");
};
main.get("/", rootHandler);
const server = main.listen(env.port, () => {
logger.info(`Server is running on port ${env.port}`);
});
export { rootHandler, server };
Guide to contribute to the project. For example:
- Fork the repository.
- Create a new branch (
git checkout -b feature/new-feature
). - Make your changes and commit them (
git commit -am 'Add new feature'
). - Push your changes (
git push origin feature/new-feature
). - Open a Pull Request.
Below is a flow diagram representing the main elements of the project:
graph TD;
A[src] --> B[app];
A --> C[test];
B --> D[app.schema.ts];
B --> E[app.env.ts];
B --> F[app.logger.ts];
B --> G[assets];
B --> H[infrastructure];
B --> I[services];
B --> J[scripts];
B --> K[templates];
B --> L[main.ts];
D --> M[Defines and validates environment variable schema];
E --> N[Validates environment variables using app.schema.ts];
F --> O[Handles logs, called from main.ts];
G --> P[Publicly exposed elements like images and audio];
H --> Q[Connects to databases, S3, and similar elements];
I --> R[Connects to external APIs via HTTP];
J --> S[Used for running ORM and similar tasks];
K --> T[Templates for Handlebars, emails, etc.];
L --> U[Example of how these components interact];
C --> V[*.spec.ts files are found in the same directory structure as in src/app];
V --> W[main.spec.ts];
Released under BSD 3-Clause License by @JuniorCarrillo.