Node.js server very slow starting time

Viewed 11378

I've build a small angular.js web app hosted on a Node.js server running on my computer. When I start my node server, it takes ~30/35 seconds. The exact same server on a collegue computer takes 2-4s to start.

I've logged times in the console to see which steps were slower. It is right from the beggining, when it loads dependencies in the require() steps. The Express module takes 26s, Morgan module takes 4s, and the rest 3s.

I understand that you probably can't find the root cause, but if anyone has an idea of what can cause this on my computer, I would gladly take any hint :)

Thank you for the help.

5 Answers

So, sometimes this process can be very slow depending on your PC. require is actually loading the modules and this could take a while depending on hardware and size of the dependency. For me, express takes under a second on my Macbook + SSD.

Check out how much free space you have on your drive. Sometimes, it may be because the drive is old and has run out of ample blocks!

Found it... The application was on a remote drive, on a cloud or something I guess (we have access to this drive when connected to our session, no matter the pc). Relocate it on D: solved the issue...

I ran across this question as I was searching for a solution to my issue with a slow starting node server in development. None of the answers took care of my issue, but for those that are trying to root out potential causes, I was loading a large json object (~500mb) in the root of a file (outside of a function) and it caused my server to go from about 1 sec loading time to 20.

So double check that your not loading any large dependencies on server start if this has happend to you.

The restarting of my server was very slow due to this issue with faker (version: 7.3.0).

Using const { faker } = require('@faker-js/faker/locale/en_US'); instead of const { faker } = require('@faker-js/faker'); sped up the require statement and the app restart by about 50 seconds.

Related