DEV Community

NarayaN Yaduvanshi
NarayaN Yaduvanshi

Posted on

Fastify port is in use but in reality it is not

Problem

This happened to me when I was trying to run my fasify server on local port defined in .env file.

Fastify error :  Port is already in use 
Enter fullscreen mode Exit fullscreen mode

I noticed that port 3000 was available and no application was running on it. I even ran the command

sudo pkill node
Enter fullscreen mode Exit fullscreen mode

to kill all the instances of running node and free all the ports.
This did not help

Solution

Upon closer look I noticed that, all the values loaded from .env file are in type String and thats what caused the issue. Fastify expect the port in Number/Integer type.
So simple solution to this problem is to conver or parse the string into number before passing it to fastify.

fastify.start(ParseInt(process.env.PORT))
Enter fullscreen mode Exit fullscreen mode

Top comments (0)