How to run separate node server in electron app - node.js

I'm building an Electron app using React.
I couldn't get the native node module "printer" to work in electron. There were problems while rebuilding native node module. I need the list of printers that are connected to the device in my app. Then print text using specific printer.
So I decided to run an express server separate from electron. Express app needs to have its own node_modules and package.json. And client side will connect the local node server via http request to localhost.
Is it possible to do so? How can I add express app to the dist folder which is created by electron-builder and make it run when electron app is launched?

There is already a way to way the native printing functionality in electron.
Please follow the below link.
https://www.electronjs.org/docs/api/web-contents#contentsgetprinters

Related

How can I integrate a nodejs server in my react-native app?

I'm creating an app with react-native. I also have a node server that can get data from a PostgreSQL database. Now I have to launch the app and the server with two different commands on two different terminals (npm start, node server.js).
Is there a way to run the node server on the react-native app in a way that I don't have to launch both the app and the server every time?

Is Create-React-App (CRA) a Node App in the same way that Express is a Node app?

I used to think that Node was only used in the server-side app because of the use of the npm command and the ensuing generation of the node_modules folder.
But I noticed that CRA also uses node, so does that make the front-end a Node app?
I appreciate any clarity on this!
Are you talking about the resultant web application created by CRA? No, it's not a Node app. It's a web app. It doesn't need Node. The resulting development environment uses Node as the backend http server. For production generally any http server can be used.

Can I use node 'child_process' in a React App?

I'm building a native app with React (I plan to use it inside Electron.js later), and I need to run some local scripts and other things which are common in a native app.
This is easy with NodeJS and it's back-end abilities, but even if mine is not a web app, it seems I just can't use Node with React.
Is using 'web-like' requests and messages, even so it's a local app, the only way to do this?
If your app is running in a browser, you will not be able to use child_process or any other node goodies like that.
Electron uses a browser, but is managed by a node process, so you will have access to all node functions: https://ourcodeworld.com/articles/read/106/how-to-choose-read-save-delete-or-create-a-file-with-electron-framework

Different ways to use react inside node and their pros/cons

I'm working on a project and using nodejs as backend. I want to use react for the frontend. And currently, the way I know to use react is by creating a client folder inside it and using create-react-app and then running both the server separately and using the proxy to connect with the node backend. The other way I came to know is via this link which basically involves installing react, reactdom, webpack etc, and using it directly inside the node app without having a separate server for react as in the case of create-react-app. So which way is better and what are their pros and cons.
The usual way is to run both react and node in separate servers.
Create the react app using npx-create-react-app
Create the node app using npm init
If both the folders are in the same directory you can use a npm package called concurrently and run both the servers with a single command. Also don't forget to install the npm package cors in your node app. If you don't , you'll get CORS errors from your API calls.
Imo using create react app is better than manually trying to configure webpack. Saves a lot of time and it's more easy to deploy.

Create a build for Node.js (fastify) server to electron app

I am using node js 10.15.0 along with fastify server int it.
I am also using normal public folder shared in the project.
Below is the project hierarchy.
NOTE: This code when started, starts as a standalone server which also servers UI.
I tried electron-packager/ electron-builder but I am not getting desired build as executable like .exe etc.
Question:
Can anyone please guide me through how can I achieve creating a build from node.js pure server code using fastify.

Resources