Start by cloning the repository to your local machine:
git clone https://github.com/FOT-Project/express-api-starter.git
cd express-api-starterInstall the required dependencies using npm or yarn:
npm install- Rename the
.envfile or create a new.envfile in the root directory. - Update the following environment variables in the
.envfile:PORT=3000 DB_HOST=localhost DB_PORT=3306 DB_NAME=express_starter DB_USERNAME=root DB_PASSWORD= DB_DIALECT=mysql- Replace the values with your database credentials.
- Ensure you have a MySQL database running.
- Create a database with the name specified in the
.envfile (DB_NAME).
Run the Sequelize migrations to create the necessary tables in the database:
npm run migrate(Optional) Populate the database with initial data using seeders:
npm run seedStart the server in development mode:
npm run dev- The server will run on the port specified in the
.envfile (default:3000).
- Use tools like Postman or cURL to test the API endpoints.
- Available routes:
GET /- Welcome message.GET /users- Fetch all users.GET /users/:id- Fetch a user by ID.POST /users- Create a new user.PUT /users/:id- Update a user by ID.DELETE /users/:id- Delete a user by ID.
If tests are included, run them using:
npm test- Prepare for Production:
- Set the
NODE_ENVtoproduction. - Update the
.envfile with production database credentials.
- Set the
- Start the Server:
npm start
- Undo Last Migration:
npm run migrate:undo
- Undo All Migrations:
npm run migrate:undo:all
- Undo Seeders:
npm run seed:undo
- Undo All Seeders:
npm run seed:undo:all
server.js: Main server file.routes/: Contains route definitions.controllers/: Handles request logic.services/: Business logic layer.repositories/: Database interaction layer.models/: Sequelize models.migrations/: Database migration files.seeders/: Database seed files.config/: Configuration files.