I have an Express app running fine locally, whose entry point is index.js, which looks like this:
const express = require('express');
const http = require('http');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const app = express();
const router = require('./router');
const mongoose = require('mongoose');
const cors = require('cors');
try{
const config = require('./config');
}
catch(e){
console.log(e);
}
mongoose.connect(process.env.cosmosConn || config.conn);
//App setup
app.use(morgan('combined'));
app.use(cors());
app.use(bodyParser.json({ type: '*/*' }));
router(app);
//Server setup
const port = process.env.port || process.env.PORT || 3090;
const server = http.createServer(app);
server.listen(port);
console.log('Server listening on:', port);
I have a package.json file which has this section:
"scripts": {
"dev": "nodemon index.js",
"start": "node index.js"
}
I've set up continuous deployment from Gitlab into an Azure Web App.
When I try to run it from the Azure App Service Editor with npm run start, or npm run dev, the server.listen(port) line throws me this error: Error: listen EADDRINUSE \.\pipe\e2d786c0-80d3-4948-92dd-47267c1d84d2
Obviously, this suggests something else is already running on the port.
If I try to run it by clicking the "Run" button in the App Service Editor toolbar, I get a different error:
Mon Oct 16 2017 12:15:55 GMT+0000 (Coordinated Universal Time): Application has thrown an uncaught exception and is terminated:
SyntaxError: Unexpected token ILLEGAL
at Module._compile (module.js:434:25)
at Object..js (module.js:464:10)
at Module.load (module.js:353:31)
at Function._load (module.js:311:12)
at Module.require (module.js:359:17)
at require (module.js:375:17)
at Object.<anonymous> (D:\home\site\wwwroot\index.js:6:16)
at Module._compile (module.js:446:26)
at Object..js (module.js:464:10)
at Module.load (module.js:353:31)
Line 6 of index.js is:
const router = require('./router');
What could be causing this? How should I troubleshoot?
npm run startdirectly is normal for Azure Web App, which run under IIS using iisnode. I suggest rewording your question to focus exclusively on the behavior when you run your app, as right now the two scenarios you describe confuse the issue. - David Ebbo