loct
loct

Reputation: 367

localhost:3000 still accessible after stopping node process

I used "create-react-app" to create a web server on http://localhost:3000. It is accessible. However, I found that after I terminate the node process, the web server still works unless I reload the page. Why is it the case?

Upvotes: 0

Views: 658

Answers (1)

crls_b
crls_b

Reputation: 720

The server is stopped after you have killed the process. create-react-app applications are client-side applications. That means that when the page is loaded, the browser downloads all the application code (javascript code) from the server, so communication between the browser and the server happens only at first. So that program code will continue to work even if you stop the server.

If you have any internal state in the web application (take a counter app, for example), it will also continue working even after the server is stopped.

As I've said, that is because the browser has downloaded all the program code when it first fetches the webpage.

This is the expected behavior for simple programs. However, more advanced scenarios (code downloaded dynamically, using React Suspense, for example) can stop working after you have stopped the server.

More about client side rendering vs server side rendering

Upvotes: 1

Related Questions