- Overview
- Transcript
2.6 Autostart the Node.js Application
In this lesson we will utilize the foreman gem to automate the startup of our Node.js app. This tool could be used to run other services as well.
1.Introduction3 lessons, 06:03
1.1Introduction01:16
1.2Installing VirtualBox and Vagrant02:05
1.3Advanced Setup: Vagrant and VMware02:42
2.Setting Up Your Node.js Stack6 lessons, 23:57
2.1Project Overview05:05
2.2The Vagrantfile05:02
2.3Installing Node.js Using NVM02:50
2.4Installing MongoDB and Redis05:43
2.5Node.js Development Workflow02:42
2.6Autostart the Node.js Application02:35
3.Exporting and Sharing2 lessons, 09:16
3.1Exporting and Sharing Your Vagrant Box07:28
3.2Sharing Your Local Vagrant Instance01:48
4.Conclusion1 lesson, 00:54
4.1Final Review00:54
2.6 Autostart the Node.js Application
Hi, and welcome back to easy node.js development environment with Vagrant. In this lesson we will automate our node application so we don't have to manually start it up every time we are booting our Vagrant box. To do this we are going to use the Foreman Ruby Gem. Before we can install Foreman, we need Ruby first. Since it doesn't really matter which version of Ruby we have, we can use the version provided by the package manager. Afterwards install the Ruby gem using pseudo privileges. With Foreman installed, we then we need a prog file that defines the services we want to start. In our case, we only have a single one. But when our app gets more complex, you can add more here. Since using Nodemon as a Unix service is not intended. We have to be a bit tricky. We source the nvm.init script first and then execute Nodemon. I do that in Foreman, although that isn't necessary, so when exporting it in a minute, I don't need to adapt anything manually. Let's try the configuration by running Foreman start. I also said deport environment variable in the command line, since Foreman defaults to port 5000. It seems everything is working fine. Let's export the configuration. Foreman provides the export command to generate various popular service manager files. We're on Ubuntu so we're using Upstart. By using pseudo, we can write indirectly into etc/init. I also specified the vagrant user with -u, the name of the service with -a, and the pod with -p. After starting the service, I can refresh the browser and see everything is running. Great. Now let's try changing our generated samples to Tom again to test the restart functionality of Nodemon. The newly generated contacts have Tom as the first name so this also works. In the next lesson, I'll be showing you how to export and upload your vagrant box to Atlas and share it with others. See you there.







