Note: Adjust the Firewall, it's to be re-configured to allow port 5000 for testing purposes, if the port has not already been opened.
Node.js on a Debian Server
Javascript Environment on the Server
Note:Currently Node.js ver:16.x is most stable series and is to be installed rather using the Debian default version. To do this, execute the followin instructions (reference guide: How To Install Node.js on Debian 10) :
Install Node.js
Logon the server, via PuTTY, and enter the following commands:
sammy@imega:$ curl -sL https://deb.nodesource.com/setup_16.x -o nodesource_setup.sh // get the latest in the version 16 series.
sammy@imega:$ sudo bash nodesource_setup.sh // setup the installation
sammy@imega:$ sudo apt install nodejs // to the actual install
sammy@imega:$ node -v // check the version
Installing the 'Stack'- ExpressJS app
With node.js up properly installed, Express and the 'stack' project then can be installed exactly in the same manner described in the previous page, starting with the creation of the 'js' directory in (sammy's) home directory and completing the two steps -- but by using FileZilla or other means, to upload stack.zip (containing the complete website) to the 'js' directory and in the final step, unzipping it there.
sammy@imega:/js $ unzip stack2024.zip
sammy@imega:/js $chmod -R 775 stack/ // set permissions
sammy@imega:/js $cd stack
sammy@imega:/js/stack/$npm install
sammy@imega:/js/stack/$npm run dev // Go to browser via link at:- http://[MyServerIP]:5000
Enter in the browser, one's domain at port:5000 (eg. http://[MySeverIP]:5000), the result should the appearance of this project website. Type in the PuTTY console: 'ctl'+c to exit
Deploying ExpressJS-Project 'Stack'
Step1: Serving the project on the local port:8080
Assumption: one has made this setting in the config.env file: PORT=8080
Method1: PM2 PM2 Offers a quick and effective method to deploy a node.js based application. To install, do the following:
sammy@imega:$ sudo npm install pm2@latest -g // accept the defaults
sammy@imega:$ nano /js/stack/config/config.env // enter the line: 'PORT=8080'
sammy@imega:$ cd js/stack // 'ctl'+c to exit
sammy@imega:/js/stack$ pm2 start app.js // to start the service
sammy@imega:/js/stack$ curl http://localhost:8080/ // to check and see the first page (text-form)
Method02: Establishing the 'Stack' Systemd Service
sammy@imega:$ nano /js/stack/config/config.env // enter the line: 'PORT=8080'
sammy@imega:$ sudo nano /etc/systemd/system/stack.service //see below **
sammy@imega:$ sudo systemctl start stack
sammy@imega:$ sudo systemctl status stack // 'ctl'+c to exit
sammy@imega:$ sudo systemctl stop stack // to stop the service
The express app is now being served at port:8080 (eg. http://[MySeverIP]:8080). Note: Usually the Firewall will not permit 'outside' access to this port but one can check the output with this bash command: curl http://localhost:8080/
** Copy & paste this text within file: stack.service
Should the 'stack' service be properly functioning, one can establish its automatic startup at every reboot with the following command:
sammy@imega:$ sudo systemctl enable stack
Warning: There are in the Debian environment, slight differences with regard to that of the Win-PC. Take note of these:
- File names are case-sensitive. Example: myphoto.jpg and myphoto.JPG are seen as different files. If the image is not appearing in your website, check this issue.
- Permissions and Ownerships are concepts deeply implemented in the Linux environment. To ensure correct permissions and ownership for the above-example:
sammy@imega:~/js/stack$ cd ~
sammy@imega:~$ chmod -R 775 stack/ //all files executetable
sammy@imega:~$ chown -R sammy:www-data stack/ // all files under one ownership.