Skip to content

Instantly share code, notes, and snippets.

@codyogden
Last active October 10, 2016 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codyogden/ca57c29892855068509f231f80a8e792 to your computer and use it in GitHub Desktop.
Save codyogden/ca57c29892855068509f231f80a8e792 to your computer and use it in GitHub Desktop.

‘Hello World’ with a Digital Ocean Node.js droplet.

This walkthrough assumes you have previously setup a public SSH key on your Digital Ocean account. If you have not setup an SSH key. Replace Step 3 with the alternative directions underneath the main tutorial.

  1. Create a New Droplet
    1. Choose “Once-click apps”
    2. “Node on 16.04”
    3. Choose the $5/month option ( $0.007/hour )
    4. Choose the desired SSH Key you’d like to use to login.
    5. Click “Create”
  2. When the droplet has finished being created, click on the IP Address to copy it to your clipboard.
  3. In your terminal, run ssh root@IP_ADDRESS. If it asks for authenticity of host, type ‘yes’ and hit enter.
  4. Next lets update all currently installed packages. Run sudo apt-get update.
  5. Next we’ll need to install Node Package Manager. Run sudo apt-get install npm
  6. Now what we have Node and NPM installed, we can spin up a really basic express server using the nano text editor.
  7. Install express. npm install express
  8. Create a file. touch hello.js
  9. Edit the file with nano. nano hello.js and copy/paste hello.js ( scroll to the bottom of this page ).
  10. Press Control + x. Then type y followed by return to save the file and return to the terminal.
  11. Now let’s run the file through node to see if it works. nodejs hello.js
  12. Visit your server’s IP address ( in the URL bar ).

Next Step: Get MongoDB Installed

Alternative Step 3

If you do not want to use SSH, you can access a virtual console via the Digital Ocean dashboard. Click on your node droplet that you created and you'll see a "Console" link that will open a new window with a virtual console from Digital Ocean. I have personally found this console unreliable and sometimes lags too much.

var express = require( 'express' );
var app = express();
app.listen( 80, function() {
console.log( 'App is listening on port 80');
});
app.get('*', function( req, res ) {
res.send( 'hello world!' );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment