We are on our first step to become a DevOps expert. We will begin setting up a Linux Server (NodeJS) on a Virtual Machine. I recommend VirtualBox, it is open source and very easy to set up.
- Download VirtualBox here https://www.virtualbox.org/wiki/Downloads
- Choose a Linux distribution, I picked Ubuntu Desktop, you can get it from here https://www.ubuntu.com/download/desktop
Preparing VirtualBox for running Ubuntu
Launch VirtualBox and select «New», the next prompt will appear. Make sure you select Linux and Ubuntu (32|64-bit) version.
Set the RAM
Select the Hard Drive Type
Your VM is almost ready, when you boot it from the first time, it prompts you to select the bootable file, make sure you select the *.iso file you downloaded from the Ubuntu webpage.
Follow the instructions prompted by the OS like creating an Username and Password, when it finished, we’re going to install the required packages for running Node.
Installing NodeJS & Git
First we need the curl package, open the Terminal app and type
sudo apt-get install curl
Next step is to download Node source, type the following command
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
Once finished, let’s install NodeJS by running the next command
sudo apt-get install -y nodejs
Finally, verify that node and npm are correctly installed by checking the version of each one
Our next step is to install git, so we run the next command
sudo apt-get install git
And like node and npm, let’s verify the installation by checking the version
In the package.json file, add a new script for running our development server.
"start": "node src/index.js"
Run the script typing npm run start and open the browser in http://localhost:8080, you should see the following
Remember to add git to the project.
Now, we’re going to write a small cron job in our Virtual Machine, type the following
Select your desired terminal editor and you’ll be able to edit or add cron jobs
At the end of the file we will write the cronjob, add something simple like this
* * * * * echo 'Hello Cron!' > $HOME/cron.txt
This task will be running every minute and overwrite the file with ‘Hello Cron!’, close the file and save it. Next go to your home directory in one minute and see that the file is created
Amazing! We wrote our first cronjob in Linux. This is the part II of a series of five posts