Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

189
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!