Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

248
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda