How to get public url for Node server hosted on Replit

I made a basic fastify server listening on port 3000. It works fine locally when I curl http://localhost:3000/ in the Replit shell.

How can I get the public link so I can use the endpoint? I’ve tried the url syntax https://<my-repl-name>.<my-username>.repl.co/, but keep getting the following page instead of an API response

I believe that means that the code is not running properly. Perhaps check the request logs?

Logs show the API is working fine when I curl http://localhost:3000 in the Shell

mmmm, create a support ticket?

this has happened in the past, I find it’s normally due to replit lag and stuff

Hey!
I played around with your repl for a minute, found that if you add host: "0.0.0.0" after the port it works!

Here is the working code!

const fastify = require('fastify')({
  logger: true
})

// Declare a route
fastify.get('/', function (_request, response) {
  response.send({ hello: 'world' })
})

// Run the server!
fastify.listen({ port: 3000, host: "0.0.0.0" }, function (err, _address) {
  if (err) {
    fastify.log.error(err)
    process.exit(1)
  }
  // Server is now listening on ${address}
})

Good luck!

Oh, you didn’t change the host!! Ah, on replit to make the host “0.0.0.0” to make it so you can access it anywhere @clairefro

Yep, took a minute for me to realize it since ive never used fastify before, but its the same in Flask with py.

mhm, yup I’ve never done any express/js server stuff

THANK YOU! It worked and popped up the webview automatically

you’re welcome :smiley: have a nice coding journey

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.