I am using custom server in nextjs. Everytime I make a change in the frontend or backend, nodemon restarts the main process and the child processes. This results in an increased build time.
My expectation is that when I make a change in the pages or other frontend component, the already running server and the database connection should not restart.
How can this be achieved?
I think if I run the custom server seperatly and use rewrites in next.config then I can have the two server running seperatly.
GetStaticProps, GetStaticPaths, GetServerSideProps, and GetInitialProps all execute serverside. Actually, unless the component returns JSX it executes on the server. So you have client side and serverside in each pages file, and all serverside in _app and _document. Nextjs has fast refresh so nodemon isn't necessary with Next. Try removing nodemon and just run with yarn next dev or npm run next dev, fast refresh is built in
Related
I am currently working on using Electron to run two applications: React as the UI app + FastAPI as the local backend server. I am running both applications from Electron using node's child_process.spawn method. However, these processes don't terminate by nature but I am not sure how to be certain that both applications are ready to use so I can allow Electron to launch the renderer window loading the React app.
For the backend server, I am thinking about implementing a method in Electron that keeps sending a GET request (IsTheServerReady call) method till the backend server responds. I am open to hearing better solutions for this. For React, however, I can't seem to find a direct way to do this.
When I make a fetch request from my react front-end (localhost:3000) to my Express back-end, my browser console advises "ERR_EMPTY_RESPONSE" and the network tab of my developer tools advises the connection stalled.
I've done some troubleshooting with my back-end and the problem happens intermittently, only when I try to make a call to my database (postgreSQL). There are no errors logged or caught. the res.end() does not fire.
I figured this out after a day of trial and error and research. My nodemon was restarting my server between calls because some of my middleware was saving new files to my server. This meant the server restarted between sending/receiving calls to my database.
I resolved the issue by adding nodemonConfig to my package.json in order to ignore files and directories when triggering refreshes.
I'm working on a Vue.js application that retrieves some data with ajax calls; in the dev environment I'm playing with the application in the browser using the builtin server and mocking the external resources with an API stubber that runs on its own server. Since both pieces of software are using node I'm wondering if there's a way to run both with a single command, serving the Vue.js application code and some static files for the mocked calls (which are not all GETs and require parameters, so sticking the json files in the app public folder wouldn't work).
Edit: let me try to clarify. The Vue.js application will interact with a backend service that is still being developed. On my workstation I can play with the application by just running the npm run serve command, but since there's no backend service I won't be able to try the most interesting bits. Right now I'm running saray alongside my application, serving some static json files that mock the server responses. It works fine but I'm effectively running two separate http servers, and since I'm new to the whole Vue, npm & javascript ecosystem, I was wondering if there's a better way, for instance serving the mock responses from the same (dev) server that's serving the Vue application.
If there's any. Im not really into web technologies, but have to understand some awful code written by someone else in Node.
All node.js apps are npm modules once you execute npm init. After that point, you can publish the module by executing npm publish assuming you gave it a unique name in the package.json.
If the app isn't meant to return anything, then there is no need to export anything. However, it's almost always worth exporting something to allow for unit testing deeper than just starting the app as an http server and sending it requests.
It is also sometimes useful to modify the way your app runs based on whether it is being required as a module or executed as an app. For example, say i have an express rest api server. I can run it as a standalone server on api.example.com, and then require it into another application and run it from that application directly to avoid CORS issues without having to duplicate code or deal with git submodules, instead I simply npm install the api into the application that needs it and attach it just like you would a router. www.example.com/api
app.use('/api', require('#myusername/api.example.com'))
I am working with node.js and heroku and would like to have more than one webprocess running.
In the Procfile I have it looking like this:
web: node web.js
web: node differentWeb.js
However when I run it it will only run the last of the two. Is there a way to do this?
An application on Heroku can only have one process named web that gets routed HTTP requests. If you need another web process then that would be another application on Heroku.