Question

Deploy my Node App served from my Droplet

Hello, I followed DigitalOcean’s (DO) instructions to deploy a simple “Hello World” app. Please keep in mind:

  1. I got it to work in my DO droplet (I see the rendered content: mydomain.com/my-app/).
  2. I understand it’s server.js code.
  3. I understand it’s sites_available >default code.
  4. I see another DO Community member asked this question, but there’s not solution.
  5. I want my node app to be served from my droplet. Not another service like: http://my-app.dokku.me, or Hreoku The DO “Hello World” app (server.js) only renders text content. I want to use this script (server.js) to start my index.html of my Node app. Side note: my index.html contains links to app.bundle.js, app.css & an image folder. What code do I change/use (in the code, below) to start my Node (Webpack) app ?
http.createServer(function(request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World on port 3001');
}).listen(3001, '999.999.99.999');```
Note: I've spent over 25 hours on this one aspect. 
    I've exhausted all resources I can think of. YouTube, DO, Google, ... 
Thank-you, Michael Rooney 
Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

@MLR Okay, but the title of your question is “Deploy my Node App served from my Droplet” - that was why I thought this was a Node problem. My bad. Supply your Nginx server block and let’s have a look at that. It should look like this:

server {
  listen 80;
  server_name example.com;
  root /var/www/html;
  index index.html index.htm;
  location / {
    try_files $uri $uri/ =404;
  }
  location /myNodeApp {
    proxy_pass http://localhost:3001;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
  }
}

@MLR Starting a new thread, since it got too narrow.

  1. Find a small app and use that as your template. You need to have routes, and usually a folder called public where you place those things. But again, this goes into waaayyy too much coding, so I would probably recommend that you ask in a Node forum like StackOverflow: https://stackoverflow.com/questions/tagged/node.js

  2. localhost is an alias of the IP 127.0.0.1. The 999-IP, well I’m guessing that’s your masked public IP, is still “owned” by the server, but that means Node is publicly available on port 3001 (if the firewall is open). Using 127.0.0.1 means that it’s only services on the server that can see those - and that’s what we want, because we want Nginx to see Node and serve the data to visitors.