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.
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.
Click below to sign up and get $100 of credit to try our products over 60 days!
Hello,
If you change the code as follows it should work:
Best,
Bobby