This repository serves as a starting point for building Express APIs, saving you time from setting up the project from scratch. It includes a structured folder setup, essential configurations, and examples to kickstart your development.
Before you begin, ensure you have met the following requirements:
- Node.js: Download and install Node.js from nodejs.org.
- npm: npm is included with Node.js. Ensure it is installed by running
npm -v.
To set up the project locally, follow these steps:
-
Clone the repository:
git clone https://github.com/floriankyn/express-api-template.git cd express-api-template -
Install the dependencies:
npm install
-
Copy the example environment file and make the required configuration changes in the .env file:
cp src/api/config/.env.example src/api/config/.env
-
Start the development server:
npm run dev
The API should now be running on http://localhost:3000.
Provide examples and instructions on how to use the API or include features of the template.
- src/: Source code for the application.
- api/: API specific code.
- config/: Configuration files.
- v1/: Version 1 of the API.
- controller/: Controller files.
- middleware/: Middleware files.
- routes/: Route definitions.
- validator/: Validation files.
- api/: API specific code.
- prisma/: Prisma ORM configuration and schema.
To configure the application, you need to set up environment variables. Copy the .env.example file in the src/api/config/ directory to a new file named .env, and fill in the values as described below:
PORT: The port number on which the Express server will run. For example,3000.JWT_SECRET: A secret key for signing JSON Web Tokens. Ensure this is a secure and unique string.DB_NAME: The name of your database.DB_USERNAME: The username for connecting to your database.DB_PASSWORD: The password for connecting to your database.DB_DIALECT: The dialect of your database (e.g.,mysql,postgres,sqlite).DB_HOST: The hostname or IP address of your database server.
Example:
PORT=3000
JWT_SECRET=your_jwt_secret
DB_NAME=your_database_name
DB_USERNAME=your_database_username
DB_PASSWORD=your_database_password
DB_DIALECT=mysql
DB_HOST=localhostEnsure you replace the placeholder values with your actual configuration. Keep this file secure, especially the JWT_SECRET, as it is crucial for the security of your application.