Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express = require('express')
- const { PrismaClient } = require('@prisma/client')
- const app = express();
- app.use(express.json());
- const prisma = new PrismaClient();
- app.get('/', async (req, res) => {
- const allUsers = await prisma.User.findMany();
- res.json(allUsers)
- })
- app.post('/', async (req, res) => {
- // console.log('hit')
- const newUser = await prisma.User.create({ data: req.body })
- res.json(newUser)
- })
- app.put('/:id', async (req, res) => {
- // console.log('hit')
- const id = req.params.id
- const newName = req.body.firstName;
- const updatedUser = await prisma.User.update({
- where: { id: parseInt(id) },
- data: { firstName: newName }
- })
- res.json(updatedUser)
- })
- app.listen(4141, () => console.log('server is listening on port 4141..'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement