How to run a command in a node app deployed to Heroku? - javascript

I'm trying to learn how to deploy my apps and the teacher told us to use Heroku. I have a Node.js app that uses readline library to read a and b and outputs the sum of two numbers to the console and the cycle repeats. Is there a way to pass that data to the app when its deployed to Heroku and running? I found only a heroku-cli command heroku ps:exec but i don't know how to "enter" the running node process from there.
I know this exercise doesn't make sense but for me it's a hard question. Thank You for any help.

Related

How to restart a Node.js project?

I'm not a Node.js developer. So I have no idea how it works. I've been a PHP developer for over 8 years.
Because of some reason, I need to make a small change in a Node.js project which is live. All I have to do is changing a payment gateway token. I did it like this:
After pulling it on the server, users still go to the old payment gateway. So I guess I need to do a restart. (I'm saying so because, for PHP projects, when you change a config-related thing, you need to restart PHP).
Not sure should I restart what thing? Noted that, the server is Ubuntu 20.04 and uses Nginx to talk to Node.js. In other word, how can I see Node is running as what service on Linux?
Also, there are two files that I think I need to run the project again after restarting Node through one of them: index.js, server.js. Am I right?
And
Your Node.js script likely runs under a process that restarts the script in case it dies. There are several "run forever" wrappers, the most popular one is pm2. Find out which one is used in your project. Try pm2 list as the user your project executes under. If pm2 type pm2 restart app_name to restart your project.
Please check if it is a node.js project so you can write the command node index.js or node server.js with this command you can start your node server.

What are the solutions for deploying Docker-based app in private production environment?

This is my first post on SO after a long time using it.
In advance, please apologize for my English ;)
Currently, I am working on an app that needs to be Dockerized. This app will be deployed on just one server in a private network. (We assume that the customer will not have access to the internet.)
To sum up, I build my app with a docker-compose.yml file. It consists of 2 nodejs app and a mongodb server.
What are my solutions to deploy this app in a private customer environment with only one server?
Thanks by advance.
finally, my research did great. I think I found a solution to my problem.
Because I'm using 2 node.js apps, and a MongoDB server, I will use PM2.
https://pm2.keymetrics.io
PM2 is a tool that will help to manage, monitor, restart in case of failures multiple node.js process.
I will just use this tool to make my project production ready (just npm and pm2 to install on the server) and talk about Docker for further investigations.
Thank you,

Meteor server crashes very frequently without any error

I am working with the Meteor application and I deployed the same over EC2 instance. It was working fine till a few days back.
But now the server process kill automatically without any error log or
console
I tried to get the error but unfortunately, as there are not any logs I am unable to find out why the server is crashing again and again.
I have a medium EC2 machine on which the application is running.
I am using nohup for running the application in the background.
Below is the command I used to start the server:-
nohup meteor --settings SETTINGS-PRODUCTION.JSON &
I am wondering to know about server crashes due to nohup or some other reason is there.
Please let me know how we can console uncaught exception in the meteor-like we do in express.
What should I use to auto restart the server if the process is killed
by any error or exception?
Any help would be much appreciated!
Thanks
Using nohup is quite a low-tech solution. Things like Phusion Passenger, PM2, or forever do a better job.
Also your docker container can be configured to automatically restart the process.
Even better is a tool called Meteor Up, which makes it really simple to deploy Meteor apps to EC2.
EASILY DEPLOY YOUR APP Meteor Up is a production quality Meteor app
deployment tool.
Install with one command:
$ npm install --global mup
http://meteor-up.com/

Connect to OpenVPN server through Node.js

I’m trying to create a GUI client for connecting to OpenVPN servers using electron and node but I’m struggling to figure out how to actually connect to the servers using the .ovpn files.
My question is what is the best way to connect to an OpenVPN server using node? Would it be best to Tun terminal commands like
“openvpn—config path to config”
Or is there another way applications like tunnelblick do it that might be easier or more efficient?
Hello I have been working with electron and ovpn on my last project, so here are a few tips.
VPNs require admin/root privilege in order to get setup, so running child_process.spawn on openvpn --config <path> will fail unless your electron app is being ran via sudo/admin privilege.
You can also use electron-sudo package, link here. This is basically a child process spawn with sudo/admin. Aka, app runs normally, but vpn command runs with sudo.
However, if your client is sketchy about giving you sudo/admin, the VPN must be ran separately prior to launching your app.
All in all its a admin/sudo thing.
Hope this helps.

Writing a pseudo terminal in python for a web based ubuntu terminal

I am interested in writing a web based terminal which can execute and autocomplete the commands in ubuntu terminal.
I have fiddled with Anyterm http://www.anyterm.org which uses ROTE: "a simple C library for VT102 terminal emulation" at the backend server and javascript/html for the terminal ui. The problem was that I couldn't have it open two terminals in the same window.
After doing some research I've decided to write a terminal server/pseudo terminal (whichever is the right terminology) in python which can:
execute commands in ubuntu terminal (such as ls, grep etc...)
autocomplete the commands (like $gedi (pressed tab) $gedit)
and have multiple instances of terminal open at the same time (when typed ls in one, the other terminal won't recognize ls as the last command since its another terminal session)
I have found that with pty python module I can write a pseudo terminal
however I'm new to python and I couldn't even get the example on that page to work.
I'm planning to have the python script serve a http server with the javascript/html terminal ui I would write (this was the main reason I wanted to choose python for this project). Then I want to let the web ui talk to the backend terminal "server" and get the results back to the web ui.
If you could point me in the right direction, maybe tell me which module I should use -if not pty- and give me some ideas on how to write the python pseudo terminal server I would appreciate it.
I know javascript/php and familiar with bash scripting- At this point I could go for a C based or python based backend server, is python right for this project?
Note: I'm planning to write a ui that uses ajax post or get methods to retrieve the terminal output from backend server.
You need to learn the basic terminology first. The shell is the program that interprets your input command lines, such as grep "foo" abc.txt. A terminal emulator is a program that mimics a terminal. Terminal is a device with display and keyboard that one
used in 1970s to access a UNIX mainframe. A pseudoterminal, pty is the device node supporting terminal emulators, as opposed to "real terminal devices" (tty1) for example.
Now, you could either build a shell, that would work in terminal instead of bash or dash; or you could build a terminal emulator that is usable over the internet; you could run any existing shell in it. Both are challenging tasks by themselves.
Python documentation is not of much use, I recommend you should start by googling more of these concepts first - and not only python references, but C, C++ too.
And lastly, if you want to run Emacs or nano or some other advanced program in your shell, you want to use the pty module.
I had a friends who did something similar but he did it over Google chat, I don't know how much help it will be but take a look at xmpp (python modual) maybe it could help you, or even here is a link to his source code:
chatIO
I didn't work with him on it but it was really easy for him to use
Good Luck

Categories