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

238
Views
Basic express setup: not sending anything to local port

I created a frontend app and now trying to incorporate backend into it. ON the same frontend app i added an index.js file in the root directory, and installed express and required it in index.js file.

Very basic setup as below:

const express = require('express')
const cors = require('cors')

const port = process.env.PORT || 3001

const app = express()

app.get('/', (req, res) => {
  res.send({
    greetings: 'hi'
  })
})

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

Server is successfully on port 3001 as per my terminal, however, on localhost:3001 I'm not seeing any json response I set up in app.get. It says Cannot GET / instead. When i inspected in devtool(Network) it says 404.

This seems a very straightforward setup, but what could've gone wrong here?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

i just figured why. I installed nodemon but my “start” script is “node index.js”. Should’ve used “nodemon index.js” Working now with nodemon index.ks

over 4 years ago · Santiago Trujillo Report

0

Your code is fine, There are no errors, I tested it and it works as expected.

However few things to note, Keep Backend in Seperate folder/dirctory unless required.

Coming back to your question, There are many possiblity such as some modules are not installed properly

try running following command

//this will install if any library is currupt or not installed properly
npm i

if it doesn't work then try clearing cache

Also keep in mind, In nodeJS dev server does not automatically refresh changes, you need to restart server to see changes or you can use dev dependancy called Nodemon (this will auto restart server on saving changes)

over 4 years ago · Santiago Trujillo 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!