How to launch Quasar using Express js, Mongo, and hot reloading?
-
I’m writing a website using Quasar, and trying to figure out how to launch the quasar website using expressjs or better yet use ‘quasar dev’ to launch both the website and a separate backend. I can launch them separately if needed but I have to start up express anyway and we’re using it to host our current website and launch both the Angular front end and Mongo (plus the code that manages the database) backend.
I’m also loving hot reloading and it occurs to me I might lose that if I launch Quasar that way.
I’m thinking the best way to do it is to split the project into a front end for quasar and back end for expressjs that will handle mongo and launch them separately. My hesitation is that I believe that expressjs can be used in production, so it seems like maybe that’s the way to go here… so why split it in the first place.
I’m not tied to express, just need to be able to run Mongo and our custom node.js code on the backend.
Any advice to point me in the right direction?
Thanks.
-
@ma2i I have no idea if this is “best practice” but I use npm scripts to handle the backend server during development. My quasar project package.jon scripts section look like:
"scripts": { "lint": "eslint --ext .js,.vue ./", "dev-graphql": "cd ../graphql-knex-npvr/ && npm run-script dev ", "server-graphql": "cd ../graphql-knex-npvr/ && npm run-script start ", "server-quasar": "quasar serve dist/spa -p 2000 --cors -o ", "publish-client": "xcopy dist\\spa D:\\Users\\johni\\Projects\\graphql-knex-npvr\\public /s /d /e /y" },
So, if I want to start the backend server in development mode, I open a New Terminal in VS Code and type the following
npm run dev-graphql
This runs the script: dev-grapql that is contained in the quasar project package.json file.
The script(dev-graphql) performs 2 commands. The command are separated by &&. The first command changes the directory to point to the directory that contains the backend server. The second command runs a script call dev that is contained in the backend server project package-json file.
My backend server is nodejs using Express, SQLite, and graphql. Now that I have my backend running, I switch back to my first VS Code terminal and run
quasar dev
When I am finished for the day, I switch back to the second terminal and do ctrl-c to terminate the backend server.