Giter VIP home page Giter VIP logo

get-programming-with-nodejs's Introduction

et Programming with Node.js

This project creates a virtual machine, for setting up the development environment as used in the book Get Programming with Node.js.

Introduction

A nice and easy way to set up a Node.js development environment is by using a virtual machine. It's nice because no applications and tools, are installed on your local machine. It's easy because the virtual machine is created by a configuration file. This makes it easy to create the virtual machine when needed, but also easy to destroy it, once it is no longer needed.

Pros

  • Works all the same on Windows, Linux, OS-X
  • No installation of applications and tools on your local machine
  • The virtual machine contains all the applications / tools as used in the book
    • nodejs
    • npm
    • MongoDB

Cons

  • Takes up more memory and cpu, then running things locally.
  • Takes up disk space, as long as the virtual machine exists.

Environment set up

In case you don't have VirtaalBox or Vagrant, download and install these programs:

Clone this GitHub project, to get the Vagrant configuration file(s).

git clone https://github.com/verhagen/get-programming-with-nodejs.git

Background

The Vagrant configuration file Vagrantfile is based on the Vagrant box ubuntu/xenial64. On this Ubuntu the Node Version Manager (nvm) is being installed. Then nvm is used to install Node Package Manager (npm) and Node.js.

At the top of the Vagrantfile the nvm version and node version are set.

Using the Virtual Machine

Vagrant uses the configuration file Vagrantfile to create a virtual machine. In this scenario it creates a VirtualBox virtual machine.

Launch the virtual machine

vagrant up

Go into the virtual machine (guest)

vagrant ssh

Inside the guest, go to the shared directory which is synchronized with the hosts project directory.

cd /vagrant

Leave the virtual machine (guest)

exit

Stop the VirtualBox machine. But keep it for quick relaunch.

vagrant halt

Destroy the virtual machine. This stops and removes the virtual machine. Less disk space usage. Longer to launch again.

vagrant destroy

To remove all Vagrant boxes, first list the boxes and then remove them.

vagrant box list

vagrant box remove <name>

Adding the Code from the Books Lessons

This will make the source code, as written by the author of the book Jonathan Wexler, direct available in the virtual machine.

On the host machine, goto the git project directory get-programming-with-nodejs. Inside this git project, clone the source code from the book, as git sub-module exercise:

git submodule add https://github.com/JonathanWexler/get-programming-with-nodejs.git exercise

This will create a directory exercise which contains all the books units and lessons.

Use find to see layout of the directory exercise

find exercise -maxdepth 2

Tools needed on local machine

Some tools like a nice text editor Atom for JavaScript or MongoDB Compass for editing MongoDB content, are nice to have on your local (host) machine.

Start Developing

Once the virtual machine, created by Vagrant, is up, get inside it through vagrant ssh and goto the /vagrant directory. This directory is mounted from the host.

So all files created here or on the host machine will persist on the host machine. This makes it also possible to edit files on the host as well as on the guest.

This mount points to the project directory get-programming-with-nodejs on the host.

Inside the virtual machine one can run npm, node and others applications. Try some commands like:

npm --version
node --version

Now start reading the book Get Programming with Node.js or continue where you left off.

Good to Know

Vagrant Port Forwarding is used to make the ports used on the virtual machine available on the host as well.

Application Guest port Host port
Node.js 3000 3000
MongoDB 27017 27017

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.