我的webapp在本地工作,但是当我尝试在Azure Web Apps上发布它时,会弹出以下错误。它显示错误:侦听EADDRINUSE:地址已经在使用::: 8080,但是Web应用程序应该使用端口3000。我是创建Web应用程序的新手,所以对我们的帮助不胜感激。我使用Visual Studio代码按照以下设置发布网络应用-https://docs.microsoft.com/en-us/azure/developer/javascript/tutorial-vscode-azure-app-service-node-03。我选择了linux和节点12 LTS。
谢谢!
#!/usr/bin/env node
/**
* Module dependencies.
*/
var app = require('../app');
var debug = require('debug')('myapp:server');
var http = require('http');
/**
* Get port from environment and store in Express.
*/
var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);
/**
* Create HTTP server.
*/
var server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
/**
* Normalize a port into a number, string, or false.
*/
function normalizePort(val) {
var port = parseInt(val, 10);
if (isNaN(port)) {
// named pipe
return val;
}
if (port >= 0) {
// port number
return port;
}
return false;
}
/**
* Event listener for HTTP server "error" event.
*/
function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}
var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}
/**
* Event listener for HTTP server "listening" event.
*/
function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}
2020-07-16T04:23:44.555179603Z / _ \ __________ _________ ____
2020-07-16T04:23:44.555185003Z / /_\ \___ / | \_ __ \_/ __ \
2020-07-16T04:23:44.555189203Z / | \/ /| | /| | \/\ ___/
2020-07-16T04:23:44.555193303Z \____|__ /_____ \____/ |__| \___ >
2020-07-16T04:23:44.555197403Z \/ \/ \/
2020-07-16T04:23:44.555201303Z A P P S E R V I C E O N L I N U X
2020-07-16T04:23:44.555205203Z
2020-07-16T04:23:44.555208803Z Documentation: http://aka.ms/webapp-linux
2020-07-16T04:23:44.555212503Z NodeJS quickstart: https://aka.ms/node-qs
2020-07-16T04:23:44.555216303Z NodeJS Version : v12.16.3
2020-07-16T04:23:44.555220003Z Note: Any data outside '/home' is not persisted
2020-07-16T04:23:44.555223903Z
2020-07-16T04:23:44.902776147Z Found build manifest file at '/home/site/wwwroot/oryx-manifest.toml'. Deserializing it...
2020-07-16T04:23:44.912621757Z Build Operation ID: |bLCEuDLkBSY=.df68a68e_
2020-07-16T04:23:46.477381888Z Writing output script to '/opt/startup/startup.sh'
2020-07-16T04:23:47.136900207Z Running #!/bin/sh
2020-07-16T04:23:47.137528808Z
2020-07-16T04:23:47.137541508Z # Enter the source directory to make sure the script runs where the user expects
2020-07-16T04:23:47.137547108Z cd "/home/site/wwwroot"
2020-07-16T04:23:47.137551508Z
2020-07-16T04:23:47.137555608Z export NODE_PATH=$(npm root --quiet -g):$NODE_PATH
2020-07-16T04:23:47.138703711Z if [ -z "$PORT" ]; then
2020-07-16T04:23:47.138716311Z export PORT=8080
2020-07-16T04:23:47.138721811Z fi
2020-07-16T04:23:47.138725911Z
2020-07-16T04:23:47.139711413Z echo Found tar.gz based node_modules.
2020-07-16T04:23:47.139723313Z extractionCommand="tar -xzf node_modules.tar.gz -C /node_modules"
2020-07-16T04:23:47.139728913Z echo "Removing existing modules directory from root..."
2020-07-16T04:23:47.139733513Z rm -fr /node_modules
2020-07-16T04:23:47.139737613Z mkdir -p /node_modules
2020-07-16T04:23:47.139741713Z echo Extracting modules...
2020-07-16T04:23:47.141077216Z $extractionCommand
2020-07-16T04:23:47.141089216Z export NODE_PATH="/node_modules":$NODE_PATH
2020-07-16T04:23:47.141094416Z export PATH=/node_modules/.bin:$PATH
2020-07-16T04:23:47.141098616Z if [ -d node_modules ]; then
2020-07-16T04:23:47.142105319Z mv -f node_modules _del_node_modules || true
2020-07-16T04:23:47.142117019Z fi
2020-07-16T04:23:47.142122019Z
2020-07-16T04:23:47.142126219Z if [ -d /node_modules ]; then
2020-07-16T04:23:47.142140519Z ln -sfn /node_modules ./node_modules
2020-07-16T04:23:47.142145419Z fi
2020-07-16T04:23:47.149224835Z
2020-07-16T04:23:47.149263335Z echo "Done."
2020-07-16T04:23:47.149334335Z npm start
2020-07-16T04:23:48.155357951Z Found tar.gz based node_modules.
2020-07-16T04:23:48.155942252Z Removing existing modules directory from root...
2020-07-16T04:23:48.164530572Z Extracting modules...
2020-07-16T04:23:51.370781353Z Done.
2020-07-16T04:23:52.204989273Z npm info it worked if it ends with ok
2020-07-16T04:23:52.206185276Z npm info using npm@6.14.4
2020-07-16T04:23:52.206929677Z npm info using node@v12.16.3
2020-07-16T04:23:52.736398696Z npm info lifecycle myapp@0.0.0~prestart: myapp@0.0.0
2020-07-16T04:23:52.746327019Z npm info lifecycle myapp@0.0.0~start: myapp@0.0.0
2020-07-16T04:23:52.759340349Z
2020-07-16T04:23:52.759356549Z > myapp@0.0.0 start /home/site/wwwroot
2020-07-16T04:23:52.759362549Z > node ./bin/www
2020-07-16T04:23:52.759366849Z
2020-07-16T04:23:54.160267671Z Express server listening on port 8080
2020-07-16T04:23:54.170115279Z events.js:287
2020-07-16T04:23:54.170141079Z throw er; // Unhandled 'error' event
2020-07-16T04:23:54.170147979Z ^
2020-07-16T04:23:54.170152379Z
2020-07-16T04:23:54.170156779Z Error: listen EADDRINUSE: address already in use :::8080
2020-07-16T04:23:54.170161379Z at Server.setupListenHandle [as _listen2] (net.js:1313:16)
2020-07-16T04:23:54.170165779Z at listenInCluster (net.js:1361:12)
2020-07-16T04:23:54.170170179Z at Server.listen (net.js:1449:7)
2020-07-16T04:23:54.170174479Z at module.exports (/home/site/wwwroot/routes/table_routes2.js:63:27)
2020-07-16T04:23:54.170178979Z at Object. (/home/site/wwwroot/app.js:119:37)
2020-07-16T04:23:54.170183679Z at Module._compile (internal/modules/cjs/loader.js:1133:30)
2020-07-16T04:23:54.170187979Z at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
2020-07-16T04:23:54.170192279Z at Module.load (internal/modules/cjs/loader.js:977:32)
2020-07-16T04:23:54.170196679Z at Function.Module._load (internal/modules/cjs/loader.js:877:14)
2020-07-16T04:23:54.170200879Z at Module.require (internal/modules/cjs/loader.js:1019:19)
2020-07-16T04:23:54.170205179Z at require (internal/modules/cjs/helpers.js:77:18)
2020-07-16T04:23:54.170209379Z at Object. (/home/site/wwwroot/bin/www:7:11)
2020-07-16T04:23:54.170213779Z at Module._compile (internal/modules/cjs/loader.js:1133:30)
2020-07-16T04:23:54.170218079Z at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
2020-07-16T04:23:54.170231979Z at Module.load (internal/modules/cjs/loader.js:977:32)
2020-07-16T04:23:54.170236679Z at Function.Module._load (internal/modules/cjs/loader.js:877:14)
2020-07-16T04:23:54.170240879Z Emitted 'error' event on Server instance at:
2020-07-16T04:23:54.170244979Z at emitErrorNT (net.js:1340:8)
2020-07-16T04:23:54.170248979Z at processTicksAndRejections (internal/process/task_queues.js:84:21) {
2020-07-16T04:23:54.170253279Z code: 'EADDRINUSE',
2020-07-16T04:23:54.170257279Z errno: 'EADDRINUSE',
2020-07-16T04:23:54.170261279Z syscall: 'listen',
2020-07-16T04:23:54.170265279Z address: '::',
2020-07-16T04:23:54.170269379Z port: 8080
2020-07-16T04:23:54.170273379Z }
2020-07-16T04:23:54.198841600Z npm info lifecycle myapp@0.0.0~start: Failed to exec start script
2020-07-16T04:23:54.200937601Z npm ERR! code ELIFECYCLE
2020-07-16T04:23:54.201865802Z npm ERR! errno 1
2020-07-16T04:23:54.203466603Z npm ERR! myapp@0.0.0 start: `node ./bin/www`
2020-07-16T04:23:54.203976603Z npm ERR! Exit status 1
2020-07-16T04:23:54.204590604Z npm ERR!
2020-07-16T04:23:54.205116404Z npm ERR! Failed at the myapp@0.0.0 start script.
2020-07-16T04:23:54.211395609Z npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-07-16T04:23:54.346290903Z npm timing npm Completed in 2399ms
2020-07-16T04:23:54.347057103Z
2020-07-16T04:23:54.347655604Z npm ERR! A complete log of this run can be found in:
2020-07-16T04:23:54.436761954Z npm ERR! /root/.npm/_logs/2020-07-16T04_23_54_212Z-debug.log
答案 0 :(得分:0)
尝试不使用normalizeport函数