How to autolaunch node js in background for react native - node.js

I am trying to link my mysql database with my react native application similar to React Native and Mysql Connection. The question I have is probably dumb but I cannot find an answer to it so.... how do I get my backend node js script which makes requests to my database to open automatically and run in the background as soon as the react native application is launched. I don't want the user to need to somehow open this script separately or run it on a computer on the network, I want to be able to use expo go on my phone to run my react native application and the node js script to automatically run in the background so I can grab data from it in my react native application. Is this even possible?

Related

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

Reactjs + Electron + Nodejs

I've been researching for long time but haven't found what I need. Maybe here someone can help me out.
What I want:
I'm trying to create an application that will run inside electron. Both frontend and backend should be encapsulated within a single executable, so I was thinking React js and Nodejs would be a good option.
But it's not as simple as I thought. Found a good boilerplace for reactjs https://github.com/electron-react-boilerplate/electron-react-boilerplate but I have no idea how I could encapsulate nodejs as a backend to it.
It'd also somehow would need to be integrated with the release package and so on...
Additionally I'd need to have a webserver that will run on localhost:[port] when you launch the application.
Technical Summary:
So basically:
Electron with React js - as the application 'face'
Nodejs - as the backend of the application
Webserver running locally - (using react js).
In the application, I would put link to the pages that is served by that locally running reactjs web app.
Hope I was clear. And I really hope someone can help me out.
Thanks!!!
as you know the serverside part is separate from front end.you can lunch react electron together like this article https://flaviocopes.com/react-electron/ .but serverside must start to stand alone . you could use pm2 for launching them.http://pm2.keymetrics.io/
lets talk about electron. what is electron?
according to electronjs.org :
Electron is an open source library developed by GitHub for building
cross-platform desktop applications with HTML, CSS, and JavaScript.
Electron accomplishes this by combining Chromium and Node.js into a
single runtime and apps can be packaged for Mac, Windows, and Linux.
so the electron is a tool for creating desktop applications.it uses chromium engine for accessing resources of the operating system level. but the intention of that is creating apps not a serverside job.
if you have some needs and logics that must handle in a server you should be considering that. otherwise, read about serverless applications.

Can Node.JS integrate inside Flutter mobile application?

I created a mobile application with flutter in front end and back end with node.js but I want it to use node js in offline mode in another meaning I want host this node inside the mobile. can I?
No.
First, you'd need NodeJS itself built for you mobile platform. Only then can you even consider running the node application you've written.
Flutter is Dart and NodeJS is well, JS. You can't put them together. But if you are building a node app that builds into a static js and html, may be you can put it in a webview, which does not seem to be the case here.
You are asking to run server side code on the client itself and offline too. If the application can really be offline, I think you're better off without a backend and store everything static within the flutter app itself.

How Do I Execute System Scripts from Within a Reactjs Project?

I have a React project where I want to execute a server side bash script when a user clicks a button. This script would then run and return some output to be displayed back to the user. I know that NodeJS has a way to spawn or exec a particular command, but I'm not sure how I can take advantage of these features inside my React project.
Does anyone know how to accomplish this?
What you can do is create a web service, that you will call with your React JS application. This web service will execute the script directly on the server and when it's done you can return data to display on your React JS application.
React runs in the browser, and with a purely remotely-served website there is no direct way to run a client-side bash script (that would be a major security issue). To run a bash script you need to run a native application on the client, which could then connect directly to your back end or be triggered via the nativeMessaging API. Alternately you could use a framework like Electron or NW.js to turn your React app into a native app, rather than running in the browser.

Run node.js app with node-webkit?

I have a nodejs app with modules, views etc..
Is it possible to open this app with node-webkit instead of opening it in the browser ?
Thanks.
Yes, it is. Node-WebKit is a package with browser + node web server. But I believe you will probably want to change your architecture, because you don't need the client-server style. If you run your app without any changes, node-WebKit will act just like node server and you still need a browser to access the app. There is no reason to use node-WebKit instead of pure node in this case.
To use node-WebKit embedded browser you should know that there are no need to start node server. The browser's JavaScript environment is already connected to node and you can execute node commands and packages direct from the JavaScript files (eg.: access file system from the browser, a dream to every web developer). It's like you are running a browser inside the server, without the need of make requests and receive responses... For this reason you don't need to use packages as socket.io, cause the communication is already established. But you can use the fact of node is a server to easily establish communication between different machines, for example.

Resources