Home Web Development Full-Stack Web Development with Vue.js and Node

Full-Stack Web Development with Vue.js and Node

By Aneeta Sharma
books-svg-icon Book
eBook $39.99 $27.98
Print $48.99
Subscription $15.99 $10 p/m for three months
$10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
BUY NOW $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
eBook $39.99 $27.98
Print $48.99
Subscription $15.99 $10 p/m for three months
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
  1. Free Chapter
    Introducing MEVN
About this book
Isomorphic JavaScript was the buzzword of the year 2017, allowing developers to utilize a single language throughout their web development stack and build cost-effective and scalable applications. MEVN is a one such modern web development stack consisting of web applications such as MongoDB, Express.js, Vue.js, and Node.js. Hands-On Full-Stack Web Development with Vue.js 2 and Node.js leverages the harmony of these technologies to help you create full-stack web applications. Starting with the core frameworks, this example-based guide explains all the key concepts of frameworks, how to set them up properly, and how to use popular modules to connect them together and make them work cohesively. You will learn all this with the help of real-world examples. In addition to this, you will be able to scaffold web application architecture, add an authentication layer, and develop the MVC structure to support the development of your application. You'll explore how to create data models for your applications and then write REST APIs by exposing your data model to your application. Solely orientated towards building a full, end-to-end application using the MEVN stack, this book will help you understand how your application development grows.
Publication date:
May 2018
Publisher
Packt
Pages
366
ISBN
9781788831147

 

Introducing MEVN

Mongo, Express, Vue.js, and Node.js (MEVN) is a collection of JavaScript technologies just like MongoDB, Express, Angular, and Node.js (MEAN), and like MongoDB, Express, React, and Node.js (MERN). It is a full-stack solution for building web-based applications that use MongoDB as data storage, Express.js as the backend framework (which is built on top of Node.js), Vue.js as the JavaScript framework for the frontend, and Node.js as the main engine for the backend.

This book is for web developers who are interested in learning to build a full-stack JavaScript application using MongoDB, Express.js, Vue.js, and Node.js. It is suitable for beginners and intermediate developers with a basic knowledge of HTML, CSS, and JavaScript.

The term MEVN may be new, but the technologies used in it are not new. The only new technology that is being introduced here is Vue.js. Vue.js is an open source JavaScript framework, and its popularity is growing rapidly. There's not much of a learning curve with Vue.js and it is also a fierce competitor of other JavaScript frameworks such as AngularJS and ReactJS.

Modern web applications need to be fast and easily scalable. In the past, JavaScript was used in web applications only when there was a need to add some visual effects or animations that normal HTML and CSS could not achieve. But today, JavaScript has changed. Today, JavaScript is used in almost every web-based application, from small to large-scale apps. JavaScript is chosen when the application needs to be much faster and more interactive.

Building a full-stack application using JavaScript as the sole programming language has its own benefits:

  • If you are just starting out and learning how to program, you only have to master one language: JavaScript.
  • Full-stack engineers are high in demand. Becoming a full-stack developer means that you have an idea of how databases work, you know how to build both the backend and the frontend, and you also have the skills for UI/UX.

In this book, we will build the application using these technology stacks.

We will cover the following topics in this chapter:

  • An introduction to the MEVN technology stack
  • An introduction to Node.js and its installation on Windows, Linux, and macOS
  • An overview of npm and its installation
  • An introduction to MongoDB and its installation and a few basic commands used in MongoDB
  • An introduction to GitHub version control and how it helps software engineers in terms of easy access to code history and collaboration
 

Evolution of the technology stack in JavaScript

JavaScript is one of the most important programming languages today. Founded by Brendan Eich in 1995, it has done superbly well, not only in maintaining its status, but also in rising above all other programming languages.

The popularity of JavaScript is ever growing with no end in sight. Building web applications with JavaScript as the sole programming language has always been popular. And with this fast growing pace, the need for software engineers to have knowledge of JavaScript is only increasing. No matter what programming language you choose to excel at, JavaScript always crawls its way in to get involved with other programming languages as well, one way or the other.

There are a lot of technologies to choose from for the frontend and backend while developing an application. While this book uses Express.js for the backend, there are other frameworks as well, which you can learn if you want.

The other available backend frameworks are Meteor.js, Sails.js, Hapi.js, Mojito, Koa.js, and many others.

Similarly, for the frontend, the technologies include Vue.js, React, Angular, Backbone, and many more.

For databases, the options, other than MongoDB, are MySQL, PostgreSQL, Cassandra, and others.

 

Introducing MEVN

JavaScript frameworks are rising day by day, both in terms of numbers and their usage. JavaScript used to be implemented only for the client-side logic but, over the years, it has seen significant growth and now it is used both on frontends and backends.

Express.js in the MEVN stack is used to manage all the backend-related stuff and Vue.js handles all the view-related stuff. The advantages of using an MEVN stack are as follows:

  • One language is used throughout the whole application, which means the only language you need to know is JavaScript
  • Understanding the client side and server side is very easy with one language
  • Its very fast and reliable application with the non-blocking I/O of Node.js
  • Its a great way to keep updated on the growing ecosystem of JavaScript
 

Installing Node.js

To get started, we need to add all the dependencies that are required for an MEVN stack application. We can also refer to the documentation on the official website (https://nodejs.org/) for details on how to install Node.js in any operating system.

Installing Node.js on macOS

There are two ways to install Node.js on macOS: using the installer or using the bash.

Installing Node.js using the installer

To install Node.js using the installer, perform the steps:

  1. Install the installer: We can download the installer for macOS from the official website's download page (https://nodejs.org/en/#download). We will be installing the latest node version, which is 10.0.0. You can install any node version you want, but the application that we will be building in this book will require the node version >= 6.0.0. Run the installer and follow the instructions given. When we download and run the installer, we will be prompted with the following dialog box:
  1. Just hit Continue until the installation finishes. Once the installation is complete, we will be able to see the following dialog box:

Just hit Close and we will be done.

Installing Node.js using the bash

Node.js can be easily installed using Homebrew in macOS. Homebrew is a free and open source software package manager that is used to install software on macOS. I personally prefer Homebrew because it makes it very easy to install different software on Mac:

  1. To install Homebrew, type the following command:
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  1. Now, use Homebrew to install Node.js with the following command:
$ brew install node

Installing Node.js on Linux

For Linux, we can either install the default distribution of Node.js or we can download it from NodeSource to use the latest version.

Installing Node.js from the default distribution

To install from the default distribution, we can install Node.js on Linux by using this command:

$ sudo apt-get install -y nodejs

Installing Node.js from NodeSource

To install Node.js from NodeSource, perform the following steps:

  1. First download the latest version of Node.js from NodeSource:
$ curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash 
  1. Then, install Node.js with the command:
$ sudo apt-get install -y nodejs
The apt is a short form of Advanced Package Tool that is used to install software on Debian and Linux distributions. Basically, this is equivalent to the Homebrew command in macOS.

Installing Node.js on Windows

We can install Node.js on Windows by following these steps:

  1. Download the Node.js installer from the official website (https://nodejs.org/en/download/)
  2. Run the installer and follow the given instructions
  3. Click on the Close/Finish button

Installing Node.js for Windows via an installer is almost the same as on macOS. Once we download and run the installer, we will be prompted with a dialog box. Just click on Continue until the installation completes. When we finally see a dialog with a confirmation, we hit Close. Node.js will be installed!

 

Introducing NVM

NVM stands for Node Version Manager. NVM keeps track of all the node versions that we installed and also lets us switch between different versions. This is handy when the application that we built for one version of Node.js does not become compatible with the other versions, and we need that specific node version to make things work. NVM allows us to manage these versions easily. This is also very helpful when we need to upgrade or downgrade the node versions.

Installing Node.js from NVM

  1. To download NVM, use the following command:
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
  1. We can also use the following command:
$ wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.6/install.sh | bash
  1. Check whether nvm has successfully installed using the following command:
$ nvm --version 
  1. Now, to install node via nvm, use this command:
$ nvm install node
 

Introducing npm

The npm is the acronym for Node Package Manager. Basically, it is a tool that takes care of all the packages that we install for Node.js. We can find all the existing packages on the official website (https://www.npmjs.com/). npm makes it easy for developers to keep their code updated and to reuse code shared by many other developers.

Developers are often confused by the terms package and modules. However, there is a clear distinction between these two.

Module

A module is something that can be loaded by Node.js with a require command and has a namespace. A module has a package.json file associated with it.

Package

A package is just a file, or group of files, that is capable of functioning on its own. Every package also has a package.json file that contains all the metadata-related information that describes that package. A combination of modules makes up a node package.

Installing npm

When we install Node.js from the installer itself, npm is installed as a part of the node. We can check whether npm is installed or not by using the following command:

$ npm --version

If npm is not installed, the command displays an error, whereas if installed, it just prints out the version of the installed npm.

Using npm

npm is used to install different packages in our application. There are two ways to install packages: locally and globally. When we want to install a certain package specific to our application, we want to install that package locally. However, if we want to use a certain package as a command-line tool or be able to access it outside our application as well, we will want to install it as a global package.

Installing an npm package locally

To install a package specific to our application only, we can use this command:

$ npm install <package_name> --save

Installing an npm package globally

To install a package globally, we can use this command:

 $ npm install -g <package_name>

Introducing package.json

All the node packages and modules consist of a file called package.json. The main function of this file is to carry all the meta information associated with that package or module. A package.json file requires the content to be a JSON object.

As a minimum, a package.json file consists of the following things:

  • name: The name of the package. This is an important part of a package.json file as it is the main thing that distinguishes it from other packages and, hence, it is a required field.
  • version: The version of the package. This is also a required field. To be able to install our package, the name and version fields need to be given.
  • description: A short summary of the package.
  • main: This is the primary entry point used to look for the package. Basically, it is a file path, so when a user installs this package, it knows where to start looking for the modules.
  • scripts: This field consists of commands that can be run for various states in the application. It has a key-value pair. The key is the event at which the command should be run and the value is the actual command.
  • author/contributors: The author and contributors are the people. It contains an identifier of the person. An author is a single person, whereas contributors can be a group of people.
  • license: The license field, when provided, makes it easy for the users to use our package. This helps in identifying the permissions and restrictions when using the package.

Creating a package.json file

We can manually create a package.json file and specify the options ourselves, or we can use a command to create it interactively from the command prompt.

Let's go ahead and initialize a sample application with a package.json using npm.

First, create a folder in your projects directory using the command:

$ mkdir testproject

To create a package.json file, run the following command in the application that we created:

$ npm init

Running this command will ask us a bunch of questions that we can answer interactively from the command line:

In the end, it will create a package.json file, which will have the following content:

 

Installing MongoDB

MongoDB is the first part of the technology in the MEVN stack. MongoDB is a free and open source document-based database published under a GNU license. It is a NoSQL database, meaning it is a non-relational database. Unlike relational databases, which use tables and rows to represent data, MongoDB uses collections and documents. MongoDB represents the data as a collection of JSON documents. It provides us with the flexibility to add fields in whatever way we want. Each document in a single collection can have a totally different structure. Aside from adding fields, it also provides the flexibility to change the fields from document to document in whatever way we want, something that is a cumbersome task in relational databases.

The benefits of MongoDB compared to Relational Database Management Systems (RDBMS)

MongoDB offers a lot of benefits compared to Relational Database Management Systems:

  • Schema-less architecture: MongoDB does not require us to design a specific schema for its collections. A schema for one document can vary, with another document being totally different.
  • Each document is stored in a JSON-structured format.
  • Querying and Indexing the MongoDB is very easy.
  • MongoDB is a free and open source program.

Installing MongoDB on macOS

Installing MongoDB by downloading

  1. Download the version of MongoDB you want from https://www.mongodb.com/download-center#production.
  2. Copy the downloaded gzipped to the root folder. Adding it to the root folder will allow us to use it globally:
 $ cd Downloads
$ mv mongodb-osx-x86_64-3.0.7.tgz ~/
  1. Unzip the gzipped file:
 $ tar -zxvf mongodb-osx-x86_64-3.0.7.tgz
  1. Create a directory that will be used by Mongo to save data:
 $ mkdir -p /data/db
  1. Now, to check if the installation was done successfully, start the Mongo server:
 $ ~/mongodb/bin/mongod

Here, we have successfully installed and started the mongo server.

Installing MongoDB via Homebrew

To install MongoDB in macOS from Homebrew, follow these steps:

  1. With Homebrew, we just need a single command to install MongoDB:
$ brew install mongodb
  1. Create a directory that will be used by Mongo to save data:
 $ sudo mkdir -p /data/db
  1. Start the Mongo server:
 $ ~/mongodb/bin/mongod

Hence, MongoDB is finally installed.

Installing MongoDB on Linux

There are two ways to install MongoDB on Linux as well: we can either use the apt-get command or we can download the tarball and extract it.

Installing MongoDB using apt-get

To install MongoDB using apt-get, perform the following steps:

  1. Run the following command to install the latest version of MongoDB:
 $ sudo apt-get install -y mongodb-org
  1. Verify if mongod has been successfully installed by running the command:
 $ cd /var/log/mongodb/mongod.log
  1. To start the mongod process, execute the following command in the Terminal:
 $ sudo service mongod start
  1. See if the log file has a line that denotes that the MongoDB connection was made successfully:
 $ [initandlisten] waiting for connections on port            <port>
  1. To stop the mongod process:
 $ sudo service mongod stop
  1. To restart the mongod process:
 $ sudo service mongod restart

Installing MongoDB using tarball

  1. Download the binary file from https://www.mongodb.com/download-center?_ga=2.230171226.752000573.1511359743-2029118384.1508567417. Use this command:
 $ curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-
3.4.10.tgz
  1. Extract the downloaded files:
 $ tar -zxvf mongodb-linux-x86_64-3.4.10.tgz
  1. Copy and extract to the target directory:
 $ mkdir -p mongodb
$ cp -R -n mongodb-linux-x86_64-3.4.10/ mongodb
  1. Set the location of the binary in the PATH variable:
 $ export PATH=<mongodb-install-directory>/bin:$PATH
  1. Create a directory to be used by Mongo to store all database-related data:
 $ mkdir -p /data/db
  1. To start the mongod process:
 $ mongod

Installing MongoDB on Windows

Installing MongoDB from the installer is as easy as installing any other software on Windows. Just like we did for Node.js, we can download the MongoDB installer for Windows from the official website (https://www.mongodb.com/download-center#atlas). This will download an executable file.

Once the executable file is downloaded, run the installer and follow the instructions. Just go through the dialog box, reading the instructions carefully. When the installation is complete, just click on the Close button and you are done.

Using MongoDB

Let's dive a little deeper into MongoDB. As mentioned earlier as well, Mongo consists of a database with collections (tables/groups of data) and documents (rows/entries/records). We will use a few commands provided by MongoDB to create, update, and delete the documents:

First, start the Mongo server with this command:

$ mongod

Then, open the Mongo shell with this command:

$ mongo

Creating or using a MongoDB database

This is the place where we can see all of our databases, collections, and documents.
To display the list of databases that we have, we can use the following:

> show dbs

Now, this command should list all the existing databases. To use the database that we want, we can simply run this command:

> use <database_name>

But if there is no database listed, don't worry. MongoDB provides us with a functionality where, when we run the preceding command, even if that database does not exist, it will automatically create a database with the given name for us.

So, if we already have a database that we want to use, we simply run that command and, if there are no databases yet, we create one using this command:

> use posts

When we run this command, a database named posts will be created.

Creating documents

Now, let's quickly review the commands used in MongoDB. The insert command is used to create new documents in a collection in MongoDB. Let's add a new record to the database that we just created called posts.

Here as well, in order to add a document to a collection, we first need a collection, which we don't have yet. But MongoDB allows us to create a collection easily by running the insert command. Again, if the collection exists, it will add the document to the given collection and, if the collection does not exist, it will simply create a new collection.

Now, in the Mongo shell, run the following command:

> db.posts.insertOne({
title: 'MEVN',
description: 'Yet another Javascript full stack technology'
});

The command will create a new collection called posts in the posts database. The output of this command is:

It will return a JSON object that has the ID of the document that we just created in the insertedId key and a flag that the event was received as acknowledged.

Fetching documents

This command is used when we want to fetch the records from a collection. We can either fetch all the records or a specific document by passing parameters as well. We can add a few more documents to the posts database to better learn the command

Fetching all documents

To fetch all the records from the posts collection, run the following command:

> db.posts.find()

This will return all the documents that we have in the posts collection:

Fetching a specific document

Let's find a post where the title is MEVN. To do that, we can run:

> db.posts.find({ 'title': 'MEVN' })

This command will return only those documents whose title is MEVN:

Updating documents

This command is used when we want to update a certain part of a collection. Let's say we want to update the description of a post whose title is Vue.js; we can run the following command:

> db.posts.updateOne(
{ "title" : "MEVN" },
{ $set: { "description" : "A frontend framework for Javascript programming language" } }
)

The output for this command will be:

We can see here that the matchedCount is 1, which means that as regards the parameter that we sent to update the record with the title MEVN, there was one document in the posts collection that matched the query.

The other key called modifiedCount gives us the count of the documents that got updated.

Deleting documents

The delete command is used to remove documents from a collection. There are several ways to delete a document from MongoDB.

Deleting documents that match a given criteria

To remove all the documents with certain conditions, we can run:

> db.posts.remove({ title: 'MEVN' })

This command will remove all the documents from the posts collection whose titles are MEVN.

Deleting a single document that matches the given criteria

To delete only the first record that satisfies the given criteria, we can just use:

> db.posts.deleteOne({ title: 'Expressjs' })

Deleting all records

To delete all the records from a collection, we can use:

> db.posts.remove({})
 

Introducing Git

Git is a version control system for tracking the code changes in our application. It is a free and open source software used to track and coordinate multiple users when building an application.

To start using this software, we need to install it first. There is a very easy way to install it on every OS.

Installing Git on Windows

We can find the installer for Git for Windows at https://gitforwindows.org/.

Download the executable installer file for Windows and follow the step-by-step instructions accordingly.

Installing Git on Mac

We can easily install Git on Mac via Homebrew. Just type the following command in the command line to install Git on Mac:

$ brew install git

Installing Git on Linux

Installing Git in Linux is as easy as installing Git on macOS. Just type the following command and hit Enter to install Git on Linux:

$ sudo apt-get install git
 

Introducing GitHub

GitHub is a version control service. It is a source code management tool specifically designed to track changes to our code. GitHub also provides features of social networking, such as adding comments, and displaying feeds, which makes it even more powerful because multiple developers can collaborate at the same time in a single application.

Why GitHub?

GitHub is a savior for software engineers. There are several advantages that GitHub provides that make it worthwhile to use. A few benefits that are provided by GitHub are listed here:

  • Tracking code changes: GitHub helps track changes to the code, which means it maintains a history of our code. This enables us to view revisions of our code base made during any time period.
  • Documentation: GitHub provides features for adding documentation, Wikis, and so on to our code bases, and these can be written using the simple markdown language.
  • Graphs and reporting: GitHub provides insight into various metrics, including how many additions and deletions were made to the code, who the top contributors were, and who has the most commits.
  • Bug tracking: Since GitHub tracks all the activities made at every point in time, when something breaks, we can easily backtrack to the point that broke the code. We can also integrate third-party tools such as Travis for continuous integration, which helps us to track and identify bugs easily.
  • Collaboration is easy: GitHub tracks every activity done by every collaborator working on the project and also sends email notifications about the same. It also provides social media features, such as feeds, comments, emojis, and mentions.
  • Hosting our own website: We can also host our own website with GitHub using a feature called GitHub pages. We just need to create a repo for our own project and host it using GitHub pages, which will then make the website applicable to the URL: https://<username>.github.io.

Using GitHub

GitHub is very easy to use. However, to get started using GitHub, we need to least know about a few terminologies that are used in GitHub:

  • Repository/Repo: A repository is a place where all of our code bases are stored. A repository can be either private or public.
  • ssh-key: ssh-key is a way to authorize in GitHub. It stores our identities.
  • Branch: A branch can be defined as multiple states of a repository. The primary branch of any repository is the master branch. Multiple users can work in parallel on different branches.
  • Commit: A commit makes it easy to distinguish between different states of a file at a given time. When we make a commit, a unique identifier is assigned to that commit so what it's easy to check what changes were made in that commit. A commit takes a message as a parameter to describe the type of change that is being made.
  • Push: A push sends the commit that we made back to our repository.
  • Pull: As opposed to pushing, pulling fetches the commit from the remote repository to our local project.
  • Merge: Merging is basically done between multiple branches. It is used to apply changes from one branch to another.
  • Pull requests: Creating a pull request is basically sending the changes that we made to our code base for the approval of other developers. We can start discussions on a pull request to check the quality of code and ensure that the changes don't break anything.
To learn more about the vocabulary used in GitHub, visit https://help.github.com/articles/github-glossary/.

Setting up a GitHub repository

Now that we know the basics of GitHub, let's get started creating a GitHub repository for the project we want to build:

  1. First, create a folder for the application in the root folder. Let's name this application blog:
 $ mkdir blog
  1. Create an account on GitHub at https://github.com/.
  2. Go to your profile. Under the Repositories tab, click New as follows:
  1. Name this repository blog.
  2. Now, on the Terminal, go to the location of this application and initialize an empty repository with this command:
 $ cd blog
$ git init
  1. Now, let's create a file called README.md and write a description for the application and then save it:
 $ echo 'Blog' > README.md
  1. Add this file to GitHub:
 $ git add README.md
  1. Add a commit so that we have a history of this change of code:
 $ git commit -m 'Initial Commit'
  1. Now, to link the local application with the remote repository in GitHub, use this command:
$ git remote add origin https://github.com/{github_username}/blog.git
  1. Finally, we need to push this commit to GitHub:
 $ git push -u origin master

When it's done, visit the GitHub repository where you will find a history of the commits made to our repository, as follows:

That's it. Now, when we want to write changes, we will first create a branch and push the changes to the branch.

 

Summary

In this chapter, we learned what an MEVN stack is. We learned what Node.js, npm, and MongoDB, are as well as receiving a brief summary of GitHub and how it helps software engineers for easy access to code history and collaboration.

In the next chapter, we will learn more about Node.js and Node.js modules. We will learn about the MVC architecture and how to implement it by building an application with Express.js.

About the Author
  • Aneeta Sharma

    Aneeta Sharma is a software engineer from Kathmandu, Nepal who has been in the tech industry for more than seven years. She started her career as a Web Designer, before becoming a PHP Developer and then a Ruby on Rails engineer. She has been working on both frontend and backend aspects of web application development since she started her career and has been developing web applications professionally since 2009. Currently, she is working as a Ruby on Rails Engineer at CloudFactory. She likes to explore new technologies and has learned to work with lots of them over the years. Most recently, she has been working with full-stack solutions with Ruby on Rails, along with frontend frameworks such as Vue.js and React.js.

    Browse publications by this author
Latest Reviews (5 reviews total)
Il manuale è fatto per essere seguito passo passo, ed è una guida chiarissima per chi, come me, parte da (quasi) zero. I concetti sono spiegati molto bene, è un manuale perfetto per studiare in modo pratico l'argomento. Unica osservazione: andrebbero aggiornate le procedure per l'installazione dell'ambiente di sviluppo - bastano due anni per renderle obsolete. Si può comunque ovviare cercando in rete.
The author does a good job of clearly explaining the tech. Few typos so far, and pretty trivial ones. I would recommend this book for someone who wants to really understand things and advance quickly.
The book I bought was not as organised as it should be. At first it was nice but a beginner will have a tough time absorbing with how the book is being narrated.
Full-Stack Web Development with Vue.js and Node
Unlock this book and the full library FREE for 7 days
Start now