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!
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
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.