Introduction to Node Development in a Virtual Environment

VirtualBox Installation

NAT Network Configuration

Creating and Setting Up Two CentOS VMs

Installing Node.js (On Terminal Only VM)

Configuring the P5.SerialServer

 Install and Setting Up HTTPD Server

Running the P5.SerialServer

Reverting Changes to VM (Creating Snapshots)


For this installation we will be setting up two VMs, one that has a GUI (Graphical User Interface) and one without a GUI. The VM without a GUI will run the P5.SerialServer as well as an Apache Web Server. The VM without a GUI will access the Web Server though a web browser. Both VMs will be running the CentOS 7 distribution although the VM with a GUI could be running any Linux distribution that has a GUI.

In this guide I will show you how to install VirtualBox, CentOS 7 on both of the VMs, Node.js, P5.SerialServer and a HTTPD Apache Web Server on the VM without a GUI. 

VirtualBox Installation


Step 1:  

To download VirtualBox go to:

Choose the OS host that you are using. For this example, I am on a mac running the Mojave OS so I will choose the OS X hosts.

Drag the .dmg file to your desktop for ease of use, then double click the icon to start.


Step 2:  

Now double click the package icon to start the installation process.

Click Continue.

Click Continue. If prompted enter the username and password of the account you are signed into.

Click Install.

Click Close.


Step 3:  

Go back to the .dmg file and double click the Applications folder icon

Double click the VirtualBox icon to start VirtualBox.


NAT Network Configuration


Step 1:  

We will now create a NAT Network where both VMs will be able to communicate with one another.

Now go to your VirtualBox and select the preferences tab


Step 2:  

Select the Network tab

Click the green NIC with the plus to create a NAT Network.


Step 3:

If you have previously created a NAT Network then you should either rename it or edit the IP address of the subnet by pressing the green NIC with the orange gear. The default settings for the NAT Network will be sufficient enough for this guide to work

Click OK to continue.


Creating and Setting Up Two CentOS VMs


Step 1:  

To install the ISO for both the Terminal Only VM and the VM with the GUI go to:

Then select the DVD ISO

Select any of the links in the top section. Some links may take longer than others so try the different mirrors for different speeds.

Drag the .iso file to your desktop for ease of use.


Step 2:  

At the VirtualBox welcome screen click the New tab to create the VM.

Enter the name of your VM. If you enter CentOS then the Type and Version should auto update to Linux and Red Hat (64-bit). Click Continue.

Select the amount of memory (RAM) you want your VM to use

Click Create to create a virtual hard disk.

Select a Hard Disk File Type. VDI is suitable for this installation. Then Click Continue.

Select the storage on physical hard disk type. Dynamically allocated is suitable for this installation. Then Click Continue.

Select the size and location of the hard disk. 8GB is more than enough for just the Node.js installation, if you are planning to do more with this VM then expand the size of the hard disk. Then Click Create.


Step 3:  

After the VM is created select the Network option.

Under the Adapter 1 header select NAT Network in the Attached to: drop down list. The Name should update to the Nat Network you created previously.

Under the Advanced arrow set Promiscuous Mode: from Deny to Allow All. Then click OK to finish.

Now Start the VM.


Step 4:  

After pressing start you will be prompted to select an .ISO file. Click the file folder to find the .ISO. From the previous steps, the .ISO file is on the desktop.

After selecting the file press Start to continue.


Step 5:  

Now instead of going through those steps again we can just create a clone of the VM. This clone will have the right parameters to work for the CentOS with a GUI. If you want to create the VM again follow Step 2-4.

Rename the GUI VM to whatever you wish. Then click Continue.

Select a Clone type then continue. If you want to preserve disk space a Linked Clone would help but I will be using a Full Clone.


Step 6:  

Now go back to the running VM and use the arrow keys to select the Install CentOS 7 option, then press enter to Continue.

Wait for the installer to launch the select your language options. Then click Continue.

Select the Installation Destination tab.

Nothing needs to be done in this section so click done.

Then select Begin Installation.


Step 7:   

Click on User Creation to create an Administrator user.

A root password does not have to be set if the User Account is an administrator. Make sure the check box is marked and then fill out the Full Name, User Name and Password.

Wait for the installation to be completed then click Reboot to get into the OS.


Step 8:   

Enter the username and password you just made in Step 7.

Then connect the Arduino Uno to your host machine and then to your VM.


Step 9:   

Go back to the VM welcome screen and start the GUI VM.

Now follow all the parts in Step 6 but DON'T press Begin Installation. Instead click on the Software Selection tab.

Then select the GNOME desktop to create an environment with a GUI. Then click Done to continue.

Now select Begin Installation.

Now follow Step 7.


Step 10:   

Click the License Information tab and accept the License.

Make sure the check box is marked and then press Done.

The click Finish Configuration.


Step 11:    

Sign in to your account. 

Select your language and the click Done.


Installing Node.js (On Terminal Only VM)


Step 1:    

In the CentOS VM without a GUI, you first need to enable the dhclient by entering the following command in the terminal:

          sudo dhclient   

This will allow your VM to get an IP address and internet connectivity

Then update the OS by entering:

        sudo yum -y update  


Step 2: 

Install the repository by entering first:

         sudo yum install -y gcc-c++ make     


       curl -sL | sudo -E bash -    



Step 3: 

Now install Node.js by entering: 

       sudo yum install -y nodejs    

If Node.js installed correctly then the following commands should produce the same results.


Step 4: 

In the terminal application type the following to install SerialPort:

       sudo npm install serialport --unsafe-perm -g  

Wait for the download to complete.


Step 5: 

In the terminal application type the following WS:

       sudo npm install ws -g     

Wait for the download to complete.


Step 6: 

In the terminal type the following P5.SerialServer:

         sudo npm install p5.serialserver --unsafe-perm -g     

Wait for the download to complete.


Configuring the P5.SerialServer


Step 1: 

Change your directory to the following by typing:

     cd /usr/lib/node_modules/p5.serialserver/examples/echo    


Step 2: 

Then enter:

         ls /dev/tty*   

To find which port the Arduino Uno is connected to. The device should end in ACM.


Step 3: 

Now enter:

       ip a   

To find the IP address of this VM.


Step 4

In a text editor (I will be using nano) open the sketch.js file and change the port name and SerialPort to what is listed above.

       sudo nano sketch.js      

Use the command below to install nano.

      sudo yum install -y nano       

Exit and Save.


Step 5

Then edit the index.html file and remove the ../../lib/ from the fifth line by entering:

      sudo nano index.html   

Save and Exit.


 Install and Setting Up HTTPD Server

To access this P5.SerialServer you will have to host the p5serial on a Web Server.


Step 1: 

Install HTTPD by entering:

     sudo yum install -y httpd    


Step 2

After installation allow ports 80 (http) and 8081 (p5serial) through your firewall

     sudo firewall-cmd --add-port=80/tcp --permanent   

     sudo firewall-cmd --add-port=8081/tcp --permanent   

     sudo firewall-cmd --reload   


Step 3

Then start and enable the HTTPD service 

      sudo systemctl start httpd   

      sudo systemctl enable httpd   


Step 4

Then change into the html directory by using the command:

     cd /var/ww/html   

Now copy the echo folder into the current directory by entering:

    sudo cp -r /usr/lib/node_modules/p5.serialserver/examples/echo .   

Be sure to include the period. 

Then copy the p5.serialport.js file into the echo folder using the following command 

     sudo cp /usr/lib/node_modules/p5.serialserver/lib/p5.serialport.js echo     


Running the P5.SerialServer


Step 1

Once in the echo folder type the following to start the p5.serialserver:

      sudo p5serial    

The server should launch.

If you are not already in the echo folder enter the command:

      cd /var/www/html/echo    


Step 2

Now in the VM with a GUI, start a terminal and enter

      sudo dhclient          

This will enable your VM to get an IP address and internet connectivity

Start up the Firefox browser and enter the IP address of the VM with no GUI. If your web server is running you should get this screen.


Step 3

Then add /echo at the end of the IP in the search bar and you should have the P5.SerialServer page updating


Reverting Changes to VM (Creating Snapshots)

After your installation of Node.js an error may occur or an installation might go wrong and that could cause your Node.js to not work as intended. Rather than uninstalling and reinstalling Node.js or making a brand new VM, we can create Snapshots of the VM after the Node.js download and now if an issue arises you can restore your VM to a previous state.


Step 1:

Make sure the VM that you want a snapshot of is shutdown. In the Vm without a GUI enter:



Step 2:

Now go to the VirtualBox Manager and click on the three dotted list and then select Snapshots.


Step 3:

Now select Take to take a Snapshot.


Step 4:

Choose a name for your Snapshot and the Press OK. I will be keeping the default.


Step 5:

Now if you need to restore back to the Snapshot created then select the name of the Snapshot and then press Restore.

Now that you have a Snapshot (and you know how to create them) in place you can alter the VM and if any problems occur you can restore back to a previous Snapshot.