Reputation: 93
I have this code currently:
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var sessionManager = require("./SessionRaterBL");
sessionManager.CreateTestData();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
var port = process.env.PORT || 8080;
var router = express.Router();
var sessionRouter = express.Router();
router.get('/', function(req, res) {
res.json({ message: 'API Session Rater Backend' });
});
sessionRouter.get("/",function(req,res){
res.json(sessionManager.GetSessions())
});
sessionRouter.get("/:id",function(req,res){
var session;
try{
session = sessionManager.GetSession(req.param.id);
res.json(session);
}catch(ex){
res.status(404).send(ex);
}
});
app.use('/api', router);
app.use('/api/sessions',sessionRouter);
app.listen(port);
console.log('Magic happens on port ' + port);
When executing the program I get the above named error.
So I did a netstat -anb I get this: all ports
So I tried finding the PORT 8080 or 80 but I just could not find it. If I execute my Node.js Program with a different Port for example: 1000. It works!.
Upvotes: 5
Views: 13648
Reputation: 2204
Using WSL can cause this issue.
Check this answer - it worked for me
net stop winnat
netsh int ipv4 set dynamic tcp start=49152 num=16384
netsh int ipv6 set dynamic tcp start=49152 num=16384
net start winnat
Upvotes: 0
Reputation: 492
Just run
serve --port=80
where 80 is the port you want to launch the program.
Upvotes: 0
Reputation: 172
I had the same problem.
What I did was I changed the port of the default website in the IIS-Manager from 8080 to 80 and than I reseted the IIS-Manager. It worked!
Upvotes: 4