Deploying Node.js Applications - Deploy Node the right way - as an Upstart Service
Skills:
Backend Performance80%
Key Takeaways
Deploys a Node.js application as an Upstart service for continuous running
Full Transcript
Okay so we've gotten if you watched the last video to the point where we can now run an automated deployment for our node.js app so let's make this better there's there's kind of a problem with forever even though most people that I know use forever for deployments forever has this problem and that for the word forever does not include if your server has to reboot for some reason if your server if digital Ocean or or Rackspace tends to do this whenever they have problems your servers all get rebooted and now your website's down because forever not restart your service and so what we're going to actually do is run our noj app nodejs app as its own system service as its own upstart service and this is kind of like a higher or a midlevel uh Linux thing that we're going to be doing and so this way it'll automatically run whenever it starts so the first thing we're going to do is we're going to ssh in as root so let me exit and let me SSH into my server as Ro Roots actually before I do that I'm going to ssh in as deploy and I'm going to stop my current if I go forever list I've got it running so I'm going to go forever stop all stop my existing forever service now I'm going to log in as root okay so I'm logged in as root and now I'm going to create this file Etsy init node app let me actually go into Etsy init see see on it okay so if I do a file list these are all the services that are starting on boot up um so basically if I create a new docon file a new configuration file then that service will also start so I'm going to copy and paste this code right here and I'm going actually I run this command first I will edit this file with Nano uh I prefer Vim basically Nano and Vim are text editors for your terminal since we don't really have a graphical user interface we have to use a terminal text editor Vim is better but Nano is easier so we'll be using Nano for this example if you're new to that and so now I'm in a file to edit going to copy this code and let's paste it in there we go so this is going to be my configuration file when do we start when file system and networking are started that's when we start our service and then we're going to change directory into home deploy node app that's where we are automatically that's where flight plan is pushing all our stuff to and then we're going to set some environment variables that our node app can listen to so if this is a staging server we would change that to staging and then our Port whatever our node Port is and this is the actual command to run our service uh we're finding node and then we're running bin www so that should make perfect sense to you I'm going to control X say y hit enter and there we go now we have a service so I can go start node app and it's running so let me go back over here hit refresh and you remember I stopped the forever service and it's still running cuz I've started this so I can go stop node app and I can hit refresh and it's dead dead service so start node app again and once again that's because it's called node app.on whatever you call the file is what the service name will be so now my service has been created um my next step is going to be give my deploy user the password or the ability to run that command that's really a root level command controlling services and so since my no since my deploy user is a part of the pseudo group I can run pseudo restart node app but it's going to ask for a password and I don't want to do that because I want this to be automated so I'm going to copy this command and I'm going to paste this command in and that will wh what did I do I guess I didn't copy it did I ah ruining everything there we go so now it is I have added that command in I've added that ability in and what that did is if you type viudo this is all these pseudo permissions and what I did is I just appended that to the end of my file so I'm deploy deploy now has the ability to run restart node app uh if you also want to give your deploy script the ability to run start node app and stop node app you can run Asin start node app and then sbin stop note app or if you want it to give the ability to run all um any Services stop start any Services just leave node app off so I'm not going to save this no don't save I only want my my deploy user to be able to passwordless Le restart the app uh that's as little permissions as I need so now I can exit out let's get out of there and now all I have to do is go adjust my flight plan file my flight plan. JS going to remove these two lines where I'm using forever don't use forever anymore let's use this pseudo restart node app there we go so it's going to EXA pseudo restart node app let's test deploy this fly production and it's moving there you go finish just fine it was actually slightly faster it felt like and my service is still running let's just triple check this and we'll be done for sure let me go to My Views index Jade welcome to title let's shout title yay let's run a deployment fly to production I kind of like the fly command it feels very successful there we go welcome to express and that is deploying with no. JS as a service oh yes let's do the real test um let's log in and reboot our server reboot there you go system is going down for reboot now and then let's go and try this it's not working because my server's down server should be up in about five there we go and now it's back and my service is running and I've deployed as a service so hope this helps you out and have a great day
Original Description
Deploy Node.js Applications the right way - as an upstart service. When you deploy a Nodejs app an upstart system service, it will always be running, EVEN if a server has to reboot for some reason.
This is the best way I've found to deploy Node.js Apps currently.
Watch the other 2 videos in this series:
Part 1: https://www.youtube.com/watch?v=W3rnQbsMb4Q
Part 2: https://www.youtube.com/watch?v=XxRuW1pfGTI
-~-~~-~~~-~~-~-
Also watch: "Responsive Design Tutorial - Tips for making web sites look great on any device"
https://www.youtube.com/watch?v=fgOO9YUFlGI
-~-~~-~~~-~~-~-
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from LearnCode.academy · LearnCode.academy · 56 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
▶
57
58
59
60
Web Development Tutorial for Beginners (#1) - How to build webpages with HTML, CSS, Javascript
LearnCode.academy
Web Development Tutorial for Beginners (#2) - Basic CSS - How to build a website with HTML & CSS
LearnCode.academy
How to create CSS Layouts - Web Development Tutorial for Beginners (#3) - with HTML & CSS
LearnCode.academy
Bootstrap Tutorial For Beginners - Responsive Design with Bootstrap 3 - Responsive HTML, CSS
LearnCode.academy
Angularjs Tutorial for Beginners - learn Angular.js using UI-Router
LearnCode.academy
CSS Tutorial - Web Development Tutorial for Beginners (#5)
LearnCode.academy
Node.js tutorial for beginners - an introduction to Node.js with Express.js
LearnCode.academy
Github Tutorial For Beginners - Github Basics for Mac or Windows & Source Control Basics
LearnCode.academy
Javascript Tutorial - Programming Tutorial for Beginners Pt 1
LearnCode.academy
Javascript Tutorial - jQuery Tutorial for Beginners Pt 2
LearnCode.academy
AngularJS Directives Tutorial - Part 1 - Demystifying Angular Directives
LearnCode.academy
WATCH THIS IF YOU WANT TO BECOME A WEB DEVELOPER! - Web Development Career advice
LearnCode.academy
YEOMAN TUTORIAL - Master Front-End Workflow with Yeoman, Grunt and Bower
LearnCode.academy
BOWER! - Streamline Web Workflow with Bower Package Manager
LearnCode.academy
Chrome DevTools for CSS - Better CSS Coding & CSS Debugging with Developer Tools
LearnCode.academy
GITHUB ATOM - Why Atom.io will be your favorite Text Editor!
LearnCode.academy
GITHUB PULL REQUEST, Branching, Merging & Team Workflow
LearnCode.academy
Pimp that Terminal - Add shortcuts and functions to your .bash_profile to simplify routine tasks
LearnCode.academy
jQuery Tutorial #3 - Writing Smarter, Better Code - jQuery Tutorial for Beginners
LearnCode.academy
jQuery Tutorial #2 - Event Binding - jQuery Tutorial for Beginners
LearnCode.academy
jQuery Tutorial #1 - jQuery Tutorial for Beginners
LearnCode.academy
Node.js MongoDB Tutorial using Mongoose
LearnCode.academy
Node.js tutorial for beginners 2014 - an introduction to Node.js with Express.js
LearnCode.academy
WEB DEVELOPMENT - SECRETS TO STARTING A CAREER in the Web Development Industry
LearnCode.academy
jQuery Tutorial #4 - DOM Traversal with jQuery
LearnCode.academy
jQuery Tutorial #5 - Building a jQuery Tab Panel Widget
LearnCode.academy
jQuery Tutorial #6 - Building a jQuery Image Slider
LearnCode.academy
jQuery Ajax Tutorial #1 - Using AJAX & API's (jQuery Tutorial #7)
LearnCode.academy
jQuery Ajax Tutorial #2 - Posting data to backend (jQuery tutorial #8)
LearnCode.academy
jQuery Ajax Tutorial #3 - Delegating Events & Mustache.js Templating (jQuery tutorial #9)
LearnCode.academy
jQuery Ajax Tutorial #4 - "Edit" modes & Better Mustache.js Templating (jQuery tutorial #9)
LearnCode.academy
How to put your website online - how to FTP to a domain & upload files to a webhost
LearnCode.academy
Basic Terminal Usage - Cheat Sheet to make the command line EASY
LearnCode.academy
SSH Tutorial - Basic server administration with SSH
LearnCode.academy
Vagrant Tutorial - Running a VM For Your Local Development Environment
LearnCode.academy
Sublime Text Favorite Packages and Workflow
LearnCode.academy
What Makes Javascript Weird...and AWESOME - Pt 1
LearnCode.academy
Javascript is Event-Driven - What makes Javascript Weird...and Awesome Pt 2
LearnCode.academy
Javascript Closures Tutorial - What makes Javascript Weird...and Awesome Pt 3
LearnCode.academy
FREE REST API - Practice Developing Javascript AJAX Apps with this API
LearnCode.academy
Javascript Scope Tutorial - What Makes Javascript Weird...and Awesome Pt 4
LearnCode.academy
Javascript Context Tutorial - What makes Javascript Weird...and Awesome Pt5
LearnCode.academy
Nginx Tutorial - Proxy to Express Application, Load Balancer, Static Cache Files
LearnCode.academy
Live Reload Sublime, Chrome, Anything - Fast and easy with Live-Server
LearnCode.academy
Are you bad, good, better or best with Async JS? JS Tutorial: Callbacks, Promises, Generators
LearnCode.academy
Javascript Generators - THEY CHANGE EVERYTHING - ES6 Generators Harmony Generators
LearnCode.academy
Web Development Advice - Interview with Dev Tips
LearnCode.academy
How the Internet Works for Developers - Pt 2 - Servers & Scaling
LearnCode.academy
How the Internet Works for Developers - Pt 1 - Overview & Frontend
LearnCode.academy
HAPROXY vs NGINX - 10,000 requests while killing servers
LearnCode.academy
Node.js Cluster - Boost Node App Performance & Stability with Clustering
LearnCode.academy
Web Dev Training with Treehouse
LearnCode.academy
What is Node.js Exactly? - a beginners introduction to Nodejs
LearnCode.academy
How to deploy node.js applications #1 - spin up a server
LearnCode.academy
Deploying node.js applications #2 - provision server & setup flightplan
LearnCode.academy
Deploying Node.js Applications - Deploy Node the right way - as an Upstart Service
LearnCode.academy
Mobile Web Design - Coding Workflow For Mobile Websites
LearnCode.academy
WHY YOU NEED A BUILD SYSTEM LIKE GRUNT, GULP, BRUNCH FOR YOUR WEBSITE
LearnCode.academy
GRUNT TUTORIAL - Grunt makes your web development better!
LearnCode.academy
STOP USING FTP! - How to Deploy with Flightplan over SSH
LearnCode.academy
More on: Backend Performance
View skill →Related Reads
📰
📰
📰
📰
AI Background Music as a Product: Building and Selling Custom Sound Libraries for Creators and SaaS Teams
Dev.to AI
The ChatGPT Workflow That Saves Me 10 Hours Every Week
Medium · AI
Why Developers Don’t Search Google Like They Used To
Medium · AI
What looks like AI slop from the outside is my accessibility tool
Dev.to AI
🎓
Tutor Explanation
DeepCamp AI