I installed nodejs and express but it cannot run my Main.js correctly
it shows:
Cannot GET /Main/
/etc/nginx/sites-available/digitalocean:
location /Main/ {
proxy_pass http://localhost:8080;
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;
}
Main.js:
var express = require('express');
var app = express();
app.listen('8080', function () {
console.log('Test');
});
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.
Hi!
I have a similar problem.
My Nginx Block:
When I use only node (code below) and access MY_SITE/api works perfectly.
When I use Express (below). MY_SITE/api return:
Route 1 => Cannot GET / api / Route 2 works!
How do I get Route 1 to work by changing the Nginx setting?
Hi there @edmundng20062,
In your
Main.js
script, you’ve started the express application but have not defined any routes, which means that when you request/Main/
, you haven’t got a page to serve and so getCannot GET /Main/
.You can define a GET route like this, which will return “Hello World!” when you navigate to
/Main/
.Your full script should then look like this:
You can take a look at the express.js documentation for further information on how you can define routes for your express application.
Hope that helps! - Matt.