/nodejs-01

Install nodejs on LinuxONE Community Cloud and run applicatoins.

Primary LanguageJavaScript

nodejs-01

Install nodejs on LinuxONE Community Cloud and run applications.

Prerequisites

Request access to LinuxONE Community Cloud. Follow instructions https://github.com/linuxone-community-cloud/technical-resources/blob/master/faststart/deploy-virtual-server.md

Install Visual Studio Code on your workstation. https://code.visualstudio.com/

Install postgres database server on LinuxONE Community Cloud

Install required packages

For RHEL:

$ sudo yum install nodejs -y
$ sudo yum install git -y 
$ sudo yum install vim -y 

Check nodejs version

$ node -v

Sample output

Screenshot 2020-08-17 at 21 01 51

Check npm version

$ npm -v

Screenshot 2020-08-17 at 21 02 36

Create a node js script

$ node 
> console.log(“This is a test”); 

Sample output Screenshot 2020-08-17 at 21 03 39

exit

> .exit

Screenshot 2020-08-17 at 21 04 02

Create test.js

$ vim test.js

Screenshot 2020-08-17 at 21 04 31

Save file and exit.

Run the script

$ node test.js

Screenshot 2020-08-17 at 21 04 51

Create a project folder named project-01

$ mkdir project-01

Change directory to project-01

$ cd project-01

Create an application

$ vim apps.js

Screenshot 2020-08-17 at 21 05 21

Save file and exit.

Check the ip address of the server and copy it.

$ nmcli

Screenshot 2020-08-17 at 21 07 12

Run the application

$ node apps.js

Screenshot 2020-08-17 at 21 08 54

Open web browser, insert ip address port 3000 Screenshot 2020-08-17 at 21 10 00

This was rendered using plain text, we will now render html.

Create index.html using vscode

Type ! and press enter and it will generate the outline on an html document for you. Inside the body insert This is HTML so that you know you are rendering htm instead of plain text. Screenshot 2020-08-17 at 21 10 37

Sample output after pressing enter Screenshot 2020-08-17 at 21 11 00

Create the file on server using vim and copy the contents

$ vim index.html

copy apps.js file content add a function in apps.js to use html instead of plain text and import a library so you can read the file index.html

create file called appshtml.js and change the port to 3001

$ vim appshtml.js

Screenshot 2020-08-17 at 21 11 38

Run application

$ node appshtml.js

Screenshot 2020-08-17 at 21 12 21

Open web browser, insert ip address port 3001 Screenshot 2020-08-17 at 21 12 48

Well done!