Linux Ubuntu - local coding environment

Posted on June 30th 2019 by Zarko

Local coding environment setup for Linux Ubuntu

Our coding environment for this course should have the following important pieces:

  1. Node.js
  2. MongoDB
  3. Command line terminal
  4. Code editor

1. Node.js setup 

Node.js is the JavaScript engine that we use to run our backend applications.

To install Node.js on your system, open up your bash terminal and type the commands for Ubuntu, which can be found here: https://github.com/nodesource/distributions/blob/master/README.md#debinstall

Alternatively, you can install and manage different Node.js versions using NVM (Node Version Manager). To get that set up, you can follow Ian’s video tutorial for Mac OS X (which will also work for Linux because of the similar underlying architecture of the two systems): https://www.youtube.com/watch?v=lGKf_7ugFUQ

2. MongoDB setup

MongoDB is the database software that we use to store data from our Node.js applications.

The procedure to install MongoDB on your Ubuntu system is largely going to follow the same pattern like in the tutorial Ian recorded for Cloud9 (because Cloud9 is actually based on Linux Ubuntu): https://www.youtube.com/watch?v=b089GmAvUyQ

You can find the MongoDB installation commands that you can follow in your terminal here (to get MongoDB version 4 installed): https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/#install-mongodb-community-edition-using-deb-packages

After you install MongoDB via apt, you can follow the same instructions to set up the ./mongod terminal shortcut and the data folder which Colt covers in the YouTube video tutorial linked above.

If you get permission issues when creating the /data folder in the root directory, try running the following command (and research the issue online if needed): sudo chown -R mongodb:mongodb /data

If you are having further issues with the process, you can research YouTube for tutorials on how to install MongoDB on your Linux distribution, to get more walkthroughs.

3. Command line terminal

We use the terminal as a quick and efficient way to execute tasks and programs on our computer, navigate through the file system and use different web development tools.

The built-in command line software for Linux is the bash terminal, which is the exact same terminal software which Colt is using in the Cloud9 online coding platform (since it’s based on Linux Ubuntu, as mentioned above).

Therefore, we will be able to follow the same exact commands that Colt uses in the lecture videos (and follow him directly when working in the terminal).

At this point, you could also install Git on your system because we will learn and use it later in the course: https://linuxize.com/post/how-to-install-git-on-ubuntu-18-04/#installing-git-with-apt

4. Code editor

Fortunately, we already learned how to use a code editor called Sublime Text in the frontend part of the course. In the backend sections you can continue using Sublime Text (or the code editor of your choice) to create project files, write your code and save everything to your specific project folder (you can arrange project folders and files exactly the same like Colt does using the Cloud9 online environment in the course).

Sublime Text installation instructions for Linux Ubuntu: https://linuxize.com/post/how-to-install-sublime-text-3-on-ubuntu-18-04/

Another very popular code editor option worth considering is Visual Studio Code, which Colt actively uses nowadays (he recorded a video on his YouTube channel about it, click here to watch it).

Visual Studio Code installation instructions for Linux Ubuntu: https://linuxize.com/post/how-to-install-visual-studio-code-on-ubuntu-18-04/

A great advantage of using Visual Studio Code is that it supports an integrated terminal inside of the editor out of the box. This allows us to use the bash terminal directly inside the VS Code editor window. Read more here: https://code.visualstudio.com/docs/editor/integrated-terminal

Connecting the dots

To make things clear, we will compare the tools that Colt uses in his Cloud9 online environment, and the tools that we are using in our Linux Ubuntu local coding environment.

When you start the backend lectures, you will notice that Colt has a command line (terminal) on the bottom of his Cloud9 browser interface. In our local coding environment, we will use the same bash terminal which is installed on our local system, by default.

The biggest portion of the screen is going to be taken up by Cloud9’s built-in code editor. In our local environment, we are going to use Sublime Text, VS Code (or a code editor that you prefer) to write our code, save our project files, etc.

On the left-hand sidebar, you will notice a file view in Cloud9. Our Linux Ubuntu equivalent of this graphical user interface is going to be the default Linux Ubuntu file manager, which you can find from your app drawer.

Finally, when we install Node.js we will be able to use node and npm commands in our terminal, very similarly like Colt uses them in the video lectures.

Starting our MongoDB database server and shell can be slightly different, depending on the approach we take when setting it up. Therefore, make sure to reference step #2 to find instructions on how to utilize MongoDB on your operating system.

Running and previewing our apps locally

To run and preview your projects/applications, you need to use your system terminal, change directories to navigate to your project folder and then run node app.js to start the application (just like Colt does in Cloud9) - you can revisit step #1 above to find detailed instructions.

Also, make sure to first start your mongod database server, if your node app is connecting to it (reference step #2).

One important change that we need to make in our app code to be able to run and preview apps locally is to manually define the port that the app is listening to (this is handled differently in Cloud9, hence the differences in the app.listen code blocks).

Instead of using Colt’s app.listen() code in your apps, make sure to set it up like this:

var port = process.env.PORT || 3000;
app.listen(port, function () {
  console.log("Server Has Started!");
});

Then, you will be able to preview your app by going into your browser and typing localhost:3000 in the address bar.

Sharing your project code on the Q&A Boards

When you need help with your application, you will need to follow Ian’s GitHub video tutorials in order to be able to share your project code with us, which allows us to directly view and test your application in order to help troubleshoot your issues.

You can find those video tutorials here: https://www.youtube.com/watch?v=wTHPBO28nYQ&list=PL86ehqHzxhy4XX_qZZE_5mrp38WGZRzTO

After you push your code to GitHub, you can copy your repository link and share it on the Q&A Boards (always make sure to remove sensitive/private data like passwords from your code, before publishing it publicly on GitHub).

Additional notes

Heroku

Heroku is a service which we use to publish our Node.js application on the internet, towards the end of the course. It’s installed by default on the Cloud9 online environment that Colt uses in the lecture videos, however we will need to install it manually in our local coding environments.

Make sure to select follow Linux/Ubuntu installation instructions from this page: https://devcenter.heroku.com/articles/heroku-cli#download-and-install

Postman

Postman is a useful development tool that Colt uses and explains later in the course. However, you can set it up right now (so it’s ready for later usage) using the instructions here: https://linuxize.com/post/how-to-install-postman-on-ubuntu-18-04/