Welcome to the documentation for your auto-generated backend API using Express.js and Prisma. This API is designed to provide CRUD functionality for your defined entities and relations, along with optional authentication features.
To get started with your backend, follow these steps:
1npm install
Create a `.env` file at the root of your project and add the following variables:
1DATABASE_URL="your-database-url"2JWT_SECRET="your-secret-key"3PORT=3000
If you enabled authentication during the generation, JWT-based authentication is built into the backend. This includes:
Add the `authMiddleware` to any route to secure it:
1router.get('/protected', authMiddleware, (req, res) => {2res.json({ message: 'You are authenticated!' });3});
The backend provides CRUD operations for all your entities. Here's an example of the auto-generated routes:
Replace `entity-name` with your entity's actual name in lowercase.
The project uses Prisma to interact with your database. Here's an example of the Prisma schema that was generated:
1model User {2id String @id @default(auto()) @map("_id") @db.ObjectId3email String @unique4password String5}
To apply changes to your database schema, run the following commands:
1npx prisma generate
To run your backend, after setting up the environment and the database, use the following command:
1npm run dev
To deploy your backend, you can use services like Heroku, Vercel, or Railway. Make sure to set up your environment variables on the hosting platform.