5

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.

capitaineballs
  • 165
  • 1
  • 1
  • 11

5 Answers5

4

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...

capitaineballs
  • 165
  • 1
  • 1
  • 11
  • Spent three hours trying to micro-optimise (for no reason) & debugging line-by-line only to realise the code wasn't the problem. SSH was just slow. Sigh... I'm on a local development server and it's taking ~2-3 seconds to start 40+ routes & all dependencies. Thank you. – Malekai Feb 26 '23 at 00:40
3

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!

Farza M
  • 61
  • 3
2

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.

Ryan Owens
  • 21
  • 1
  • Thanks, this led me to review my dependencies in package.json. I removed an unused dependency and the server reloads very quickly again instead of taking ~15s. – fvd2 Sep 28 '21 at 08:21
0

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.

shmuels
  • 1,039
  • 1
  • 9
  • 22
0

Using docker and having a volume mounted for node_modules caused the server restart to be very slow.

Removing the mounted volume on node_modules sped up the restart by about 60 seconds.

See the following links for more details on this.

  1. https://stackoverflow.com/a/47564342/9530790
  2. https://stackoverflow.com/a/49081609/9530790
shmuels
  • 1,039
  • 1
  • 9
  • 22