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

251
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 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