The installation guide for my bridge program tells you how to install, start, and stop the program. The purpose of this post is to give you the start and stop instructions without making you wade through all the setup steps. These instructions work on a MacOS and Linux command line.
Before starting the program, make sure it is not already running. Enter the following on a command line to look for an active process with your program name:
ps -ax | grep index
After you press ENTER, if the bridge server is running you will see this:
iMac:bridgeOnTheWeb masterponomo$ ps -ax | grep index
1779 ttys000 0:00.25 node index.js
3574 ttys000 0:00.00 grep index
To stop the program, use the kill command on the process number:
iMac:bridgeOnTheWeb masterponomo$ kill -9 1779
[1]+ Killed: 9 node index.js
To verify that it was really killed, look for the running process again:
iMac:bridgeOnTheWeb masterponomo$ ps -ax | grep index
3614 ttys000 0:00.00 grep index
This result shows that the index.js program is no longer running.
Now navigate to the folder where your index.js program lives:
iMac:~ masterponomo$ cd Documents/Documents/web-projects/bridgeOnTheWeb
iMac:bridgeOnTheWeb masterponomo$
Once there, key in:
node index.js &
You should get a response like this:
[1] 3653
iMac:bridgeOnTheWeb masterponomo$ bridge program is listening on port 3001.
This response shows the new process number, and it confirms that your program is listening on the correct port. If you are running the server program on a remote server, you can now use the application from your browser by putting the remote domain name or IP address followed by “:3001” into the address bar and pressing ENTER. If you are running it on your own computer just put “localhost:3001” into the browser address bar and press ENTER.
The installation guide has additional information on setting up a cron job to revive the bridge program if it crashes or if your server reboots.
Update on November 21, 2023. Wait, there’s more! All of the above how-to is still true and it works just fine. I should note, though, that all of this manual stopping and starting of the Node application is mainly useful for when you’re in a hot and heavy development cycle. I now prefer to stop the thing manually as shown above, but I rely on the cron job to start it back up within 5 minutes. That way, when I test the running program I know it was always started the way it would be started (by cron) if it shut down or crashed in production.
But that’s not why “there’s more!” There’s actually more now because, as documented in the installation guide, on the remote server I now access the bridge deal program through an NGINX web server. When you install nginx, it will automatically restart any time your computer reboots for any reason, so you don’t generally have to do anything to keep it running. But when you are in development mode, you will need to stop, start, or reload the web server at times. That’s all documented in the NGINX help files, but here’s the bare essentials.
To check the status of the server from a Unix command line:
sudo systemctl status nginx
To stop the server:
sudo systemctl stop nginx
To start the server:
sudo systemctl start nginx
To reload the server (make it load up any configuration files you have changed, but without stopping the server from doing other work):
sudo systemctl reload nginx
Note that turning nginx on or off does not start or stop the bridge deal generator program, which is a Node application that runs outside of the web server. That Node program is only started and stopped by the commands or cron job referenced earlier in this post. The nginx server only provides a way for a website to access the Node application via a user-friendly domain name rather than through a raw IP address and port number. You do want both nginx and the Node application running, but just understand that they are two different things.