How to call Node JS CLI command from web app? - node.js

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

Related

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.

Docker vs node.js

I'm fairly new to React-native. Im sorry about quite a convoluted question but I have dilemma. I am building an API that communicates with a server app that Im working on, I have been using Docker successfully to run containers BUT I'm constantly being told that I don't need to run Docker at all. I understand the principles of Docker and Node.JS but in all honesty I cant imagine how I would run server side without Docker. Ive tried Node.js and seemed to require a PHP server, which I was also told I did not need. Is this true? which is better Docker or Node.JS? and If Node JS is better how to run it without a php server as it is my understanding that php serves the pages and React consumes the pages.
'You can just install Node, frequently through your OS's package manager. It doesn't require PHP or other language interpreters. I find working directly with Node much easier than using Node in Docker: it is actually a local development environment that my IDE is comfortable with, and not a path to run a Node interpreter "somewhere else" that's isolated from my desktop tooling. '
1)After a few weeks of research I found that I didn't need docker at all. Within Node is the ability to run a server using either fastify or express. I just needed to check on the relevant documentation for usage
2) I linked fastify to ngrok and exposed my local IP address to a public facing direction
3) I linked the ngrock url to my freedns and voila! it worked!
4) I had a small problem with the port which was resolved by using
the command ngrok http 127.0.0.1:5000

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.

Connect to MongoDB remote server with Ionic

I'm trying to develop an application in phonegap/ionic and I want to use a remote database to store my data. I want to use MongoDB.
I already tried lots of ways such as this quick start guide.
By using this I can connect to DB but this is pure node.js and the require() function cannot be recognized when I try to add this code to an ionic starter app. Maybe require is not supported in ionic
Is there a way that can achieve it in Ionic?
Please let me know if you want some more information.
The thing is; you can't connect Ionic to MongoDB directly. No, there's not workaround, no magic involved, it's just not the way this is supposed to work. Ionic works on top of Angular and Angular is a frontend framework.
However, the way you should do it is that you basically create a (RESTful) API on your server side.
Most likely this will be made with Node.js which will talk directly to MongoDB and query it. A framework very well suited for this (you actually may be using it already) is Express.
After you write your (RESTful) API then you can consume it through your services in Angular by using Angular's $resource object.
Sure, this is not a step by step answer, and it seems you're just starting in this area, so you have some learning do to on your part (REST, RESTful, $resource, services...), but I wish you good luck and if you'll have any more specific questions, don't hesitate to ask them.

How do I access a node.js script through a web browser?

I'm trying to use lesscss server side. It requires node.js for that, I've installed it and looked at some tutorials but now I have no idea how to use it. After you create a server/tcp or whatever how to you get to it from your website?
I wanna be able to do like mywebsite.com/css and when I go there it'll output the css that node.js tells it to.
What about this solution:
http://arguments.callee.info/2010/04/20/running-apache-and-node-js-together/

Resources