How Do I Execute System Scripts from Within a Reactjs Project? - node.js

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.

Related

How to autolaunch node js in background for react native

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?

How to call Node JS CLI command from web app?

I'm using this Node JS script to scrap videos from tiktok. To use this script you have to run command via terminal.
Nothing done for the moment apart using the script via CLI as i'm still trying to figuring this out.
Now i'm wondering how could I could implement this into a webapp as UI.
I've been thinking
installing the library on a webserver
making an api to to communicate with this webserver to run the command.
make my html/js or whatever to call the api
I dont if it's the best approach, i mean nodejs is supposed to be use from webserver but i dont know anything about ..
Thanks

Electron like node integration in nodejs web server

I'm new to web servers in nodejs and i'd like to know if there is possible to have an electron like node integration in a web server (to be able to use nodejs in index.js script file linked to index.html)
Thx for all :)
It's not possible. Browsers control the way that client side JavaScript is executed, so it's just technically impossible to connect both runtimes in any way that works on client machine, you'd need a customized browser, which is what Electron basically is. And neither should you want to - if the runtimes were connected in that way, any user could execute arbitrary commands on your server.

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.

Building Single Page Application without doing any Server Side Development

I am new to any JS framework and hence I am planning to build a SPA without using any Server Side Development using Ebmer.js. Since everything need to be done at the client side, can it be done without using node.Js which does provide some server side functionality ?
Basically I would like to build a login page functionality so that user can login only when they have provided correct credentials.
To build a SPA, you can go through different framework like jQuery Mobile, Sencha Touch which are AJAX based completely and needs a server. To simulate a server and to handle AJAX request you need to host a local server. Sencha has provided Sencha CMD 5.x which you can install in any system (Windows, MAC, Linux). After installing this software you just have to browse to the folder which you want to deploy on the server.
.
Open Command prompt or terminal,and type the command sencha web start.
After this you can access your application through a local server hosted on port:1841.
You will get an access to your file system as shown below.
And the result is like

Resources