Skip to content

Commit

Permalink
feat: add example on how to save into MongoDB with Prisma
Browse files Browse the repository at this point in the history
  • Loading branch information
ixartz committed Nov 24, 2022
1 parent 67c6fc5 commit 73b35d4
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
import 'express-async-errors';

import { PrismaClient } from '@prisma/client';
import express, { json } from 'express';
import helmet from 'helmet';

const app = express();
app.use(json());
app.use(helmet());

const prisma = new PrismaClient();

app.get('/', (_, res) => {
res.json({
msg: 'Hello World',
});
});

app.get('/prisma', async (_, res) => {
await prisma.user.create({
data: {
email: 'random@example.com',
},
});

res.json({
msg: 'Add a new unique user without duplicate',
});
});

app.use((_, res, _2) => {
res.status(404).json({ error: 'NOT FOUND' });
});
Expand Down

0 comments on commit 73b35d4

Please sign in to comment.