Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

188
Visualizações
Unexpected end of JSON input : SyntaxError

I keep getting Unexpected end of JSON input error when I test and it keeps crashing

import express from 'express';
import mongoose from 'mongoose';
import Messages from './dbMessages.js'

const app = express ()
const port = process.env.PORT || 9000;

app.use(express.json());

const connection_url = '...'

mongoose.connect(connection_url, {
    useNewUrlParser: true,
    useUnifiedTopology: true
})

app.get('/', (req, res)=> res.status(200).send('hello world'))

app.get('/messages/sync', (req, res) => {
    Messages.find((err, data) => {
        if(err) {
            res.status(500).send(err)
        } else {
            res.status(200).send(data)
        }
    })
})

app.post('/messages/new', (req, res) => {
    const dbMessage = req.body

    Messages.create(dbMessage, (err, data) => {
        if (err) {
            res.status(500).send(err)
        } else {
            res.status(201).send(data)
        }
    })
})

app.listen(port, ()=>console.log(`Listening on localhost:${port}`))

with all these I don't know why I keep getting an error each time I test the get method using postman,

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The error is likely coming from the client side. Do check the format of your data from the client side. For example, if you are using postman to test, make sure you do not add a comma at the end of your json data.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda