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 
I noticed that port 3000 was available and no application was running on it. I even ran the command
sudo pkill node
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))
 

 
    
Top comments (0)