if I change something in the JavaScript code of my controller, I always have to restart the server to see the effect - which always takes quite a long time. Is there a way to edit the code ‘live’ for testing purposes (as it is possible with GraphQL, for example)?
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.
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.
Hello @Richard_Lederer,
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 admin.watchIgnoreFiles in config/server.js
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!
@Richard_Lederer -
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
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.