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

354
Views
How to connect front and back end using replit & mongodb?

I made a simple full stack app for a job application using a mern stack. The application requires the app to be deployed on replit. I was able to run my app from my laptop but I am having issue connecting my back end with my front end api calls.

I have not used replit or other online coding platforms much before, so I am not very sure how to. If I run my front end on replit and my back end from my local laptop files, the api calls are working fine. But If I run start both front and back end on replit, the server will start but no API calls will reach it.

Here is the replit link: https://replit.com/@MayurKumar4/In-replit-how-to-connect-to-mongoosemongo-api-endpoints?v=1

Below is the index page of my express app.

The dbURI is currently linked to a mongodb atlas cluster I have set up and is working with some seed data.

port is set to 4000

import express from 'express'
import mongoose from 'mongoose'
import router from './config/routes.js'
import { port, dbURI } from './config/environment.js'
import cors from 'cors'

const app = express()

const startServer = async () => {
try {
// Attempt mongodb connection
await mongoose.connect(dbURI)
console.log('Mongodb connected')

// --Middleware--
// JSON Parser
app.use(express.json())


app.use(cors())


// Logger
app.use((req, _res, next) => {
  console.log(`๐Ÿšจ Request received: ${req.method} - ${req.url}`)
  next()
})

// Routes
app.use('/api', router)

// Catch All
app.use((_req, res) => {
  return res.status(404).json({ message: 'Route Not Found' })
})

// If mongodb connects successfully
app.listen(port, () => console.log(`๐Ÿš€ Server listening on port ${port}`))
} catch (err) {
console.log(err)
  }
 }
 startServer()
about 4 years ago ยท Juan Pablo Isaza
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!