I use Vagrant as a stable environment for giving demos and prototyping mobile apps. Product demo requests can come in without much notice, and there are few things as stressful as having a demo ‘act up’ in the middle of a presentation.
Having a stable and reproducible demo environment for a fast-moving open source Node project can be difficult for many reasons. A developer may accidentally reference a private GitHub version of an npm module requiring local credentials. npm versions may not be explicitly defined or rely on a globally-installed module. Even simple feature updates can make a live demo behave unexpectedly. Any of these issues can detract from the primary goal of providing a pleasant and educational experience for a prospective user.
Vagrant is great for more that just Sysops admins
Vagrant provides easy-to-configure, reproducible, and portable virtual machine environments. Vagrant virtual machines (VMs) are simple to use and easy to share. For developers, Vagrant makes it easy to create development environments from the same configuration. Whether you are working on Linux, Mac OSX, or Windows, you can be confident your virtual machine environment is the same no matter the host OS, enabling you to combat the ever-present “it works on my machine” response. Vagrant VMs are also great for designers, managers, and product stakeholders since Vagrant will automatically setup a demo or staging machine with a simple
vagrant up command.
Vagrant VMs are provisioned on top of VirtualBox, VMware, AWS, or any other provider. You can use configuration tools such as shell scripts, Chef, or Puppet, to automatically install and configure software on the virtual machine.
The Vagrant command wrapper makes it easy to:
- Load existing base boxes
- Create snapshots package your machine configurations
- Fine-tune VM settings such as CPU and RAM
You can find more information at the official Vagrant Site.
Vagrant sub commands
Vagrant sub commands often run from within the folder that contains your Vagrantfile. Below is a list of the most commonly used commands a full list of commands can be found at docs.vagrantup.com
vagrant up: creates and configures a machine according to the Vagrantfile
vagrant ssh: SSH into a running Vagrant machine and give you access to a shell
vagrant suspend: suspend the machine Vagrant is managing
vagrant resume: resume a suspended Vagrant machine
vagrant destroy: stop the running machine and destroy all resources that were created
- An additional VirtualBox command
VBoxManage list runningvmsis handy for listing current Vagrant Boxes. This is useful when you’re jumping from machine to machine and cannot remember the state of your last Vagrant Box.
An example Vagrant VM of the StrongLoop Suite can be found at strongloop-community/vagrant-strongnode. this allows you to try, test and develop StrongLoop with a few commands in a VM environment.
Once you have Vagrant installed (Vagrant 1.3.5 recommended) then getting started with the StrongLoop Vagrant configurations is a simple as:
git clone https://github.com/strongloop-community/vagrant-strongnode
After you have your Vagrant Box instance up via the vagrant up command, you can login to your VM with vagrant ssh. From inside the vagrant VM you can run the preconfigured example using the slc run command.
slc run /var/default-node-app/app.js
The vagrant-strongnode Vagrantfile pre-configures a VM ‘private network’ at http://220.127.116.11/ so you only need to open a browser on your host machine to access the server. Opening http://18.104.22.168/explorer will present you with the LoopBack explorer page, showing the existing model endpoints.
The Vagrantfile creates a Symlink that links
vagrant-strongnode/strongnode-app-folder on your host machine to
var/strongnode-app-folder in the VM. This allows you to create and edit applications with the development tools on your host machine but run the app in the isolated VM environment.
Vagrant makes it easy for anyone to create a stable demo environment.
Get Vagrant installed and
vagrant up your StrongLoop LoopBack mobile backend on your local machine!
- Want to read more articles like this? Check out “Template Systems in Node.js”, “Node.js support in Visual Studio? You bet your IDE”, and “Using a Digital Ocean Droplet for On Demand Node.js Mobile Backend”.
- Do you want to keep up on the latest Node.js news and developments? Sign up for “In the Loop”, StrongLoop’s newsletter.
- Ready to build your next mobile app with a Node backend? We’ve made it easy to get started either locally or on your favorite cloud, with simple npm install. Get Started >>