NodeJS with Vagrant
On the previous post i showed how to have docker and docker-compose with Vagrant. In this post i will show how to have a simple NodeJS environment with Vagrant.
I will show how to install the most common solutions and frameworks for node like: npm, express, qunit, yo and much more.
It`s very easy, you need to have vagrant installed, them just copy my Vagrantfile and create a directory called shared on the same folder you have copied my Vagrant file. After that you are ready to rock.
The Vagrantfile
Inside the shared directory you will need create a file called, hello.js
Now you ready, just run $ vagrant up && vagrant ssh
Vagrant will download and install all nodejs stack and enter on the box via ssh, once it finished you can type on linux box:
$ cat ~/shared/hello.js | node
NodeJS will bootup a server and you can access in your web browser on: http://55.55.55.101:8000/
If you want all the files you can get on my github here: https://github.com/diegopacheco/Diego-Pacheco-Sandbox/tree/master/DevOps/vagrant-with-nodejs
Cheers,
Diego Pacheco
I will show how to install the most common solutions and frameworks for node like: npm, express, qunit, yo and much more.
It`s very easy, you need to have vagrant installed, them just copy my Vagrantfile and create a directory called shared on the same folder you have copied my Vagrant file. After that you are ready to rock.
The Vagrantfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
Vagrant.configure(2) do |config| | |
config.vm.box = "ubuntu/trusty64" | |
config.vm.network "private_network", ip: "55.55.55.101" | |
config.vm.synced_folder "shared", "/home/vagrant/shared/" | |
config.vm.provision "shell", inline: <<-SHELL | |
sudo apt-get update | |
sudo apt-get install -y wget | |
sudo apt-get install -y curl | |
sudo apt-get install -y vim | |
sudo apt-get install -y git | |
sudo apt-get install -y build-essential | |
sudo curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash - | |
sudo apt-get install -y nodejs | |
sudo curl -L https://npmjs.org/install.sh | sudo sh | |
sudo npm install -g express | |
sudo npm install -g angular | |
sudo npm install -g bower | |
sudo npm install -g grunt | |
sudo npm install -g gulp | |
sudo npm install -g gulp-cli | |
sudo npm install -g yo | |
sudo npm install -g browserify | |
sudo npm install -g karma | |
sudo npm install -g jasmine | |
sudo npm install -g qunit | |
SHELL | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'); | |
var server = http.createServer(function (request, response) { | |
response.writeHead(200, {"Content-Type": "text/plain"}); | |
response.end("Hello World\n"); | |
}); | |
server.listen(8000); | |
console.log("Server running at http://127.0.0.1:8000/"); |
Vagrant will download and install all nodejs stack and enter on the box via ssh, once it finished you can type on linux box:
$ cat ~/shared/hello.js | node
NodeJS will bootup a server and you can access in your web browser on: http://55.55.55.101:8000/
If you want all the files you can get on my github here: https://github.com/diegopacheco/Diego-Pacheco-Sandbox/tree/master/DevOps/vagrant-with-nodejs
Cheers,
Diego Pacheco