Welcome to the VOID Express.js Starter project! This boilerplate provides a clean and scalable setup to start building Node.js APIs using Express.js, PostgreSQL with a focus on best practices, error handling, and developer experience.
To get started, simply run the following command in your terminal:
npx void-expressjs-setup my-project-name
This command will:
- Clone the repository.
- Install all dependencies.
- Set up the basic project structure for you to start coding right away!
- Express.js: A fast and minimalist web framework.
- PostgreSQL: Integrated with a basic CRUD setup using
pg
andasync/await
. - Winston Logger: For advanced logging with timestamps and error handling.
- Environment Configuration: Easily manage your environment variables using
.env
. - CORS & Helmet: Basic security and CORS setup.
cors
– Enable CORS for your API.dotenv
– Manage environment variables.express
– Minimalist web framework.helmet
– Security middleware for Express.morgan
– HTTP request logger.pg
– PostgreSQL client for Node.js.winston
– Logger for structured logging.
eslint
– Linting JavaScript code.eslint-config-airbnb-base
– Airbnb's style guide base rules.eslint-plugin-import
– Linting support for ES6+ import/export syntax.jest
– Testing framework.nodemon
– Auto-restart server on changes.supertest
– Testing HTTP APIs.
An overview of the project structure:
.
├── src
│ ├── config
│ │ ├── env.config.js # Environment configuration
│ │ ├── db.config.js # PostgreSQL connection
│ ├── controllers
│ │ └── user.controller.js # User API controllers
│ ├── middlewares
│ │ └── error.middleware.js # Error handling middleware
│ ├── services
│ │ └── user.service.js # User service for business logic
│ ├── utils
│ │ └── logger.util.js # Winston logger setup
│ ├── routes
│ │ └── user.route.js # API routes for users
│ └── app.js # Main app setup
├── test # Test folder
│ └── app.test.js # Test file for the app
├── .env.example # Example environment variables
├── .eslintrc.js # ESLint configuration
├── .gitignore # Git ignored files
├── README.md # Project documentation
├── index.js # Entry point for the app
├── package.json # Project metadata
├── package-lock.json # Automatically generated for exact dependency tree
-
Clone the repository manually:
git clone https://github.com/LilVoidx/void-api-starter.git cd void-api-starter
-
Install dependencies:
npm install
-
Environment Variables: Copy the
.env.example
file and rename it to.env
. Fill in the required environment variables:NODE_ENV=development PORT=5000 SECRET=secret CLIENT_URL=http://localhost:2000 SERVER_URL=http://localhost:5000 DB_USER=user DB_HOST=localhost DB_NAME=database-name DB_PASSWORD=password DB_PORT=5432 DB_URL=postgresql://user:password@localhost:5432/database-name
-
Run the application:
npm start
Method | Endpoint | Description |
---|---|---|
GET | /api/users |
Get all users |
GET | /api/users/:id |
Get user by ID |
POST | /api/users |
Create a new user |
PUT | /api/users/:id |
Update an existing user |
DELETE | /api/users/:id |
Delete a user |
-
Run the server:
npm start
npm start
-
Run the server using nodemon (during development):
npm run dev
-
Run tests:
npm test
-
Lint your code:
npm run lint
- Adding user authentication (JWT or OAuth).
- Adding validation middleware
- Setup continuous integration with GitHub Actions.
Feel free to fork this repository, create a new branch, and submit a pull request. I appreciate any contributions that improve the project!
This project is licensed under the MIT License. See the LICENSE file for more details.
- Void – GitHub
Thank you for using VOID Express Starter! Let's build something amazing together. 🌟