Pass Node.js commands while running the file - node.js

I'm building a small application that will be running 24/7. I need to be able to give the app Node.js's commands from the console.
Currently, if i want to give an additional command to the app i have to edit it's files, kill it then start it again. I want to start it once and be able to run commands from the console.

Related

Manage terminal with node Powershell : start, interact and stop them

I'm developping an desktop app with electron, where I need to run dynamically many server in the backend :
My solution is to use node-powershell, to run powershell command in the backend application.
I need to start and stop dynamically terminal and interact with them, push command inner them then get the output in my xterm.js interface.
I found how start and stop it, with Start-Process but I still have no ideas how intrect with thoses, once there are running

how can I run gatsby serve as a service in centos?

or is there a third framework to deploy it? Now I use gatsby serve to run it in centos, but the server shuts down after I exit console window.
Generally for this sort of thing there are a few ways to do it, among which are:
the simplest one is appending an & after the command and running disown before exiting your terminal session, & makes it so that the process runs in the background and disown separates the process from it's parent so that it doesn't close when you exit. If you use this method I would recommend forwarding the output of the command to a file so that you can later review it after your session has closed, for example gatsby serve & > access.log
a better solution is using programs such as screen or tmux which create a terminal session that can be "closed" and reopened after, please take a look at the linked man page, or run man screen (or man tmux) on your system to see how to use them as this is beyond the scope of this question.
The best solution however is however something integrated in gatsby: the build command. This generates a standalone node.js application that can be deployed on a remote server, you would build your application and setup a server such as nginx for this

Node.js - Any way to Recover a Saved-Over Script that is Currently Running?

I've accidentally saved over an existing node.js script-file making it completely blank on the file system. I'm not using any type of version control, so this long script file seems unrecoverable.
However, the app is currently running via pm2 (because it was started before I made this mistake).
Is there any way to recover this file from the running app via the node.js command prompt?

How to Save Images from A Program Ran from Ubuntu Application Start-up Command

We're trying to run a program at start with Ubuntu's Application Start-up command. We're successfully starting the camera and viewing the images. But the images are not saving to the folder we expect them to be saved too.
The program works flawlessly when started manually from the terminal. Saving into the appropriate folder.
Does anyone have any idea of how to get the images saved but when started from the Application Start-up command upon start-up?
Thanks.
You're not providing a whole lot of details, so my answer may be totally off. To me it sounds like you've created an app that takes a picture with the webcam and saves it to disk. Now you want the app run it when the user logs in, so you've added your app to the list of Startup Applications. The app starts, takes a picture, but can't write it do disk. If that's the case, I'd consider:
Try adding debug logging to your app, so you can see why it fails opening the file. What ever language this app is written in, if opening a file fails, the API will tell you. This information is vital. The easiest is to print to stdout and then, when starting the app, forward it to a log .e.g. /usr/local/bin/myapp &>> /tmp/myapp.log.
Try writing to a location like /tmp where permissions aren't that much of an issue.
Try adding a delay before starting the app, see this list of various approaches on how to do this, the most simple being using this a the command: sleep 10 ; /usr/local/bin/myapp &>> /tmp/myapp.log
If this is all rubbish you need to add more details in your question.

node.js forever arguments for background

I am trying to run my node.js app using forever on windows 64 bit.
I have tried the followed, i installed foreman from npm . App is started with foreman start app.js. I observe that the node is running with my account.
When logged out of the box the process stops. Is there away to start foreman and node to run with a system account so that its always running with out associating node to a specific user.
Any help would be greatly appreciated. TIA
You would need to run your app or forman either as a service or a scheduled task triggered to run at startup.
I found this package that will replace forever and install pm2 as a service.
https://www.npmjs.com/package/pm2-windows-service
Using forever:
There is at least this Stackoverflow question covering creating a service and probably others.
Question about creating a service from an exe
Creating a scheduled task tutorial
Open Task scheduler:
Use windows search or control panel/administrative tools/Task Scheduler
You can also open a cmd console and copy %windir%\system32\taskschd.msc /s into it and hit enter.
From there you can create a new task, set a schedule that triggers on startup, point it to forever and set it to run if your logged in or not.
The link above, or other google results, will give you good tutorial info to work through it step by step.

Resources