Coding Global Background
Coding Global

Prisma, findMany function sucks

Archiviert 2 years ago
1 Nachrichten
0 Mitglieder
Erstellt 2 years ago
Aktualisiert 2 years ago
In Discord öffnen
C
cablemanagment.
Hello guys if i do the findmany function from prisma on my model i get the error: Unexpected end of JSON input. Code:
 { PrismaClient } = require('@prisma/client');

const express = require('express');
const cors = require('cors');
const app = express();
var bodyParser = require('body-parser')

app.use(bodyParser.json())

app.use(cors());

const port = 3001;

const prisma = new PrismaClient()

async function upload(title, doxinfo, owner){
        const status = await prisma.dox.create({
            data: {
                title: title,
                doxinfo: doxinfo,
                owner: owner
            }
        })
        console.log(status)
}

async function doxes(){
    const doxesdata = await prisma.dox.findMany()
    return doxesdata
}




app.get('/', (req, res) => {
  res.send('Hello, Express!');
});


app.post('/upload', (req, res) => {
    const {title, doxinfo, owner} = req.body
    try{
        upload(title, doxinfo,owner)
    }catch(e){
        console.log(e)
    }
   res.send("Success")
})

app.get('/doxes', async (req, res) => {
    try {
        const doxesData = await doxes();
    res.send(doxesData)
    } catch (error) {
        console.error(error);
        res.status(500).json({ error: 'Internal Server Error' });
    }
});


// Start the server
app.listen(port, () => {
  console.log(`Server is listening on port ${port}`);
});

Antworten (1)