Repository: semmypurewal/node-dev-bootstrap Branch: master Commit: dc5d0bb36a56 Files: 4 Total size: 3.9 KB Directory structure: gitextract_k51vbunq/ ├── .gitignore ├── README.md ├── Vagrantfile └── app/ └── server.js ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ *~ .DS_Store .vagrant ================================================ FILE: README.md ================================================ This is a Vagrant file for building a basic node development environment. It was primarily built as a companion to my book, Learning Web App Development. You can read more about it at http://learningwebappdev.com. If you're not familiar with Vagrant, read more about it at http://www.vagrantup.com. To get this to work, you must have VirtualBox (> 5.1.0) and Vagrant (> 2.0) installed. I've most recently been testing it with VirtualBox 5.1.30 and Vagrant 2.0.2. Please post an issue if you're having problems with other versions, and I'll see if I can track it down. Installers for VirtualBox are available at http://www.virtualbox.org, and installers for Vagrant are available at http://www.vagrantup.com. Once you have the pre-requisites installed, you should be able to clone this repository git clone https://github.com/semmypurewal/node-dev-bootstrap.git my_project and change to your new project directory to start your VM: cd my_project vagrant up Note that the Vagrantfile will download and install the xenial32 vagrant box if you don't already have it. After a few minutes, you should have a virtual dev environment with node, npm, mongodb and redis. The app folder is shared, and port 3000 on the VM is forwarded to port 3000 on the localhost. This is all customizable in the Vagrantfile. You can test out your environment by ssh'ing into your environment and running the sample script: vagrant ssh cd app node server.js Next open localhost:3000 in your web browser. If everything worked correctly, you should see 'Hello World' ## Important note about Installing NPM Packages Later versions of VirtualBox do not support symlinks in shared folders. More info is available here: https://www.virtualbox.org/ticket/10085 This can cause problems when you're attempting to install certain packages via npm. For example, the 'jade' and 'express' packages create symlinks during installation, and therefore the installation will fail in the shared 'app' directory. The best workaround for this is to install node packages in your shared folder with the --no-bin-links flag, e.g. npm install express --no-bin-links If VirtualBox is your provider and you're using MacOS, you may also want to try to uncomment the "setextradata" customization in the VagrantFile to allow symlinks to work. I'm not sure how this affects other Virtual Machine providers. ================================================ FILE: Vagrantfile ================================================ Vagrant::Config.run do |config| config.vm.box = "ubuntu/xenial32" config.vm.forward_port 3000, 3000 config.vm.share_folder "app", "/home/vagrant/app", "app" # Uncomment the following line to allow for symlinks # in the app folder. This will not work on Windows, and will # not work with Vagrant providers other than VirtualBox # config.vm.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/app", "1"] config.vm.provision :shell, :inline => "sudo apt-get update && sudo apt-get -y upgrade" config.vm.provision :shell, :inline => "sudo apt-get install -y build-essential libssl-dev --no-install-recommends" config.vm.provision :shell, :inline => "sudo apt-get -y install nodejs npm" config.vm.provision :shell, :inline => "sudo ln -sf /usr/bin/nodejs /usr/bin/node" config.vm.provision :shell, :inline => "sudo apt-get install -y redis-server --no-install-recommends" config.vm.provision :shell, :inline => "sudo apt-get install -y mongodb --no-install-recommends" config.vm.provision :shell, :inline => "sudo apt-get install -y ruby2.3-dev --no-install-recommends" config.vm.provision :shell, :inline => "sudo apt-get install -y ruby2.3 --no-install-recommends" config.vm.provision :shell, :inline => "sudo gem install cf" end ================================================ FILE: app/server.js ================================================ var http = require("http"), server; server = http.createServer(function (req, res) { res.writeHead(200, {"Content-Type": "text/plain"}); res.end("Hello World!\n"); }); server.listen(3000); console.log("Server running on port 3000");