Skip to content

TopTeamEU/node-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 

Repository files navigation

πŸ“¦ Node.js Starter Project

A robust and scalable foundation for building modern backend services and APIs using Node.js and Express.

⚑️ Overview

This project template provides a structured starting point for a professional Node.js application. It includes:

Express: For handling routing and middleware.

TypeScript: For static typing and better maintainability.

ESLint & Prettier: For consistent code style and quality.

Dotenv: For managing environment variables easily.

Jest: Configured for unit and integration testing.

The goal is to provide a clean separation of concerns, making it easy to grow and maintain the codebase.

πŸš€ Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

You need the following installed on your system:

Node.js (v18 or higher)

npm or Yarn

Installation

Clone the repository:

git clone https://github.com/your-username/node-starter-project.git cd node-starter-project

Install dependencies:

npm install

or

yarn install

Create a configuration file: Create a file named .env in the root directory and add your environment variables.

Example .env content

PORT=3000 NODE_ENV=development DATABASE_URL=postgres://user:password@host:port/dbname JWT_SECRET=yoursupersecuresecretkey

Running the Application

Command

Description

npm run dev

Runs the application in development mode with nodemon. It watches for changes in .ts files and automatically recompiles and restarts the server.

npm start

Builds the TypeScript source into JavaScript (dist/) and runs the production code (node dist/index.js).

npm run build

Compiles the TypeScript source code into the dist directory.

πŸ“‚ Project Structure

The codebase is organized into logical directories to ensure scalability and clarity:

. β”œβ”€β”€ dist/ # Compiled JavaScript output (ignored by Git) β”œβ”€β”€ node_modules/ # Dependencies β”œβ”€β”€ src/ β”‚ β”œβ”€β”€ api/ # Express route definitions β”‚ β”œβ”€β”€ config/ # Configuration loading and environment variables β”‚ β”œβ”€β”€ controllers/ # Business logic layer (handles requests) β”‚ β”œβ”€β”€ middleware/ # Custom Express middleware β”‚ β”œβ”€β”€ models/ # Database interaction (e.g., Sequelize/Prisma schemas) β”‚ β”œβ”€β”€ services/ # Reusable business logic (non-HTTP specific) β”‚ └── index.ts # Main entry point of the application β”œβ”€β”€ tests/ β”‚ β”œβ”€β”€ unit/ # Unit tests for functions and services β”‚ └── integration/ # Integration tests for routes and controllers β”œβ”€β”€ .env.example # Example environment file β”œβ”€β”€ .eslintrc.json # ESLint configuration β”œβ”€β”€ package.json # Project metadata and dependencies └── README.md

βœ… Testing

Testing is handled by Jest and can be run with the following commands:

Command

Description

npm test

Runs all tests (unit and integration).

npm run test:watch

Runs tests in watch mode for continuous development.

npm run test:coverage

Runs tests and generates a code coverage report.

🎨 Style and Linting

This project uses ESLint for static analysis and Prettier for code formatting.

Command

Description

npm run lint

Runs ESLint across all source files to find code quality issues.

npm run format

Runs Prettier to automatically fix formatting issues.

npm run precheck

Runs both lint and format checks.

βš™οΈ Deployment

To deploy this application:

Build the project: npm run build

Ensure Environment Variables: Set your production environment variables (e.g., PORT, NODE_ENV=production, database credentials).

Run the compiled code: npm start (This executes the dist/index.js file).

This setup is compatible with popular cloud platforms like Heroku, AWS, Google Cloud Run, and Docker containers.

🀝 Contributing

Contributions are welcome! Please ensure you adhere to the project's coding standards (use npm run precheck before submitting) and open an issue before submitting a major feature request.

πŸ“„ License

This project is licensed under the MIT License.

About

Starter code for a node project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published