I think if you use
yarn develop or
npm run develop it should refresh the server when controllers etc are changed.
If this is the frontend you are on about it might be that you need
yarn develop --watch-admin
npm run develop -- --watch-admin
Thanks for the answer.
Yes, I start Strapi with: npm run develop.
But every time I change something on the code in the controller and save it, the server refreshes automatically, and I can only access the Strapi URL again after 1-2 minutes to see whether my changes were correct. I just wanted to know if there is a workaround for testing that I can see my changes immediately and not only after 1-2 minutes.
Should work straight away after server restart not sure why it would take 1-2 min. Or does the restart take 1-2 min?
No matter what I change in the controller - each time after I save the code, Strapi is not available for about 1-2 minutes. Neither the admin, nor the endpoints work during that time.
When you change the controller, is that on a remote server, or on your local machine?
Hmm. Then I really don’t have an explanation for why the server restart is taking so long. Shouldn’t take more than 30 seconds.
I agree with @boaz here,
Only thing i can think of is that you have plenty of things in
boostrap.js that would increase the time ?
Yeah that seems plausible
probably causes could include:
- Lots of models
- Slow or improperly configured database
- Remote high latency database
- Low machine specs
Most explanations would be environmental in nature.
I agree with the others, there seems to be something slowing down the startup. You might want to look into that, as it can be an issue with your setup.
But to answer your question, if the files you change don’t affect the database structure and are not part of the bootsraping, I believe you can add them to strapi’s watch ignore list via the option
See Configurations - Strapi Developer Documentation for more information.
But again, this is not the best option, and you really should check why the server takes so long to restart. It only takes 10 seconds on my setup with docker!
How long does it take for the initial start when using
npm run develop? you can also set the environment variable DEBUG=* and then run
npm run develop you should be able to see which operation is taking a long time. on a decent machine with a local database, it should be < 10 seconds
Indeed on normal projects it should be < 3 seconds, but I’ve seen much larger projects going around 10 to 15 seconds (these are very large projects)
Thanks for the answers. But my question was not why my server takes so long to restart, but whether there is something existing to check the results in real-time - like with GraphQL - without having to restart the server. Even 20 seconds are annoying when you are trying to learn the syntax for the DB query.
The development server with the GraphQL plugin exposes the /graphql endpoint that you can use to inspect and test GraphQL queries. It’ll usually be located at http://localhost:1337/graphql.
On the other hand, I also had a very slow server restart cycle until I began to experiment with running my server in Windows 10 Powershell instead of using virtualized Ubuntu in WSL2. For some reason running a node app in WSL2 can take 5 - 10 times as long as straight Windows. (Probably because of the virtualization, but perhaps there’s another reason.) It took me about a minute to restart the server whenever a change was made in WSL2 but after shifting over to Win10 a restart was only 5 - 10 seconds.
For the record, my react server was also much faster running in native Win10.
Hope this helps,