D
Deno

help

Possible to have multiple http servers listening to different ports in the same module?

Sshawnbu8/16/2023
I'm porting a service mesh platform we wrote for NodeJS over to Deno and it is based on the idea of hosting multiple servers in the same module.
The only examples I can find for Deno's http server uses a for loop to handle requests which seems like it's blocking. Is it possible to have different http server instances listening on different ports at the same time?
IioB8/16/2023
Yes, you can host multiple servers in one module. Are you using http? If so:
Deno.serve({ port: 1000 }, () => {
return new Response("server 1");
})
Deno.serve({ port: 2000 }, () => {
return new Response("server 2");
})
Deno.serve({ port: 3000 }, () => {
return new Response("server 3");
})
Deno.serve({ port: 1000 }, () => {
return new Response("server 1");
})
Deno.serve({ port: 2000 }, () => {
return new Response("server 2");
})
Deno.serve({ port: 3000 }, () => {
return new Response("server 3");
})
Sshawnbu8/16/2023
Awesome, thanks The same with serveHttp also in case I need to drop in and use that instead for some reason?
IioB8/16/2023
yup

Looking for more? Join the community!