Report this

What is the reason for this report?

Why do I get the 'Cannot GET / ' error on my node.js application when I am trying to run it on my droplet?

Posted on November 4, 2018

I have a droplet created using the one click install for node.js with Ubuntu 18.04.1 LTS. I cloned my git repository from gitlab, and my end goal is to run my app with forever. For now, everytime I run:


sudo node server.js

an error message appears when I got to my ip address saying:

Cannot GET /

The following is my server.js file:

const express = require('express')
const path = require('path')
const history = require('connect-history-api-fallback')

const app = express()

const staticFileMiddleware = express.static(path.join(__dirname + '/d$

app.use(staticFileMiddleware)
app.use(history({
  disableDotRule: true,
  verbose: true
}))
app.use(staticFileMiddleware)

app.get('/', function (req, res) {
  res.render(path.join(__dirname + '/dist/index.html'))
})

var server = app.listen(process.env.PORT || 80, function () {
  var port = server.address().port
  console.log('App now running on port', port);
  console.log(path.join(__dirname + '/dist/index.html'));
})

on my local machine that same command works fine and my app works, but on my droplet I am having a lot of problems.



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!

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.

Hello,

If you change the code as follows it should work:

const express = require('express')
const path = require('path')
const history = require('connect-history-api-fallback')

const app = express()

const staticFileMiddleware = express.static(path.join(__dirname + '/dist'))

app.use(staticFileMiddleware)
app.use(history({
  disableDotRule: true,
  verbose: true
}))
app.use(staticFileMiddleware)

app.get('/', function (req, res) {
  res.render('index')
})

var server = app.listen(process.env.PORT || 80, function () {
  var port = server.address().port
  console.log('App now running on port', port);
  console.log(path.join(__dirname + '/dist/index.html'));
})

Best,

Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.