Home > Software engineering >  nodejs 5500 port API get connect refused
nodejs 5500 port API get connect refused

Time:12-26

Using enter image description here

And the 5050 port is open on my cloud server:

enter image description here

CodePudding user response:

You should set listen at address 0.0.0.0

fastify.listen(5500, '0.0.0.0', function (err, address) {
  if (err) {
    fastify.log.error(err)
    process.exit(1)
  }
  fastify.log.info(`server listening on ${address}`)
})

Link at Note

The above examples, and subsequent examples in this document, default to listening only on the localhost 127.0.0.1 interface. To listen on all available IPv4 interfaces the example should be modified to listen on 0.0.0.0 like so:

fastify.listen(3000, '0.0.0.0', function (err, address) {
  if (err) {
    fastify.log.error(err)
    process.exit(1)
  }
  fastify.log.info(`server listening on ${address}`)
})
  • Related