我正在尝试使用简单的API登录在Azure中创建一个应用服务,该登录在本地运行良好,但在Azure中失败。
const express= require("express");
const app = express();
const bodyparser = require('body-parser')
const mysql = require("./DbConnect").connection;
const port = process.env.port || process.env.PORT || 3001;
app.use(bodyparser.urlencoded({extended: false}))
app.use(bodyparser.json())
app.post("/login", (req, res) => {
let user = req.param('user',null);
let password = req.param('password',null);
let qry = "select * from user where username ='" + user + "' AND password='" + password + "'";
mysql.query(qry, (err, results) => {
if (err)
res.status(500).send("DB is not available!")
else {
if (results.length > 0) {
res.status(200).send(results);
}else{
res.status(404).send("Email Or Password InCorrect")
}
}
});
});
当我使用postman在本地运行这个程序时,我立即收到“DB is not available!”错误消息。但是当我在Azure应用服务中运行这个程序时,我收到“:(Application Error)”。请注意,构建和部署是成功的。我做错了什么?
应用洞察力说明如下
2022-11-21T06:18:19.890232847Z > nodemon App.js
2022-11-21T06:18:19.890236947Z
2022-11-21T06:18:21.148319009Z node:internal/modules/cjs/loader:942
2022-11-21T06:18:21.148355110Z throw err;
2022-11-21T06:18:21.148360910Z ^
2022-11-21T06:18:21.148372410Z
2022-11-21T06:18:21.148377310Z Error: Cannot find module '../lib/cli'
2022-11-21T06:18:21.148381210Z Require stack:
2022-11-21T06:18:21.148384910Z - /home/site/wwwroot/node_modules/.bin/nodemon
2022-11-21T06:18:21.148388810Z at Module._resolveFilename (node:internal/modules/cjs/loader:939:15)
2022-11-21T06:18:21.148392710Z at Module._load (node:internal/modules/cjs/loader:780:27)
2022-11-21T06:18:21.148396510Z at Module.require (node:internal/modules/cjs/loader:1005:19)
2022-11-21T06:18:21.148400310Z at Module.patchedRequire [as require] (/usr/local/lib/node_modules/applicationinsights/node_modules/diagnostic-channel/dist/src/patchRequire.js:14:46)
2022-11-21T06:18:21.148404310Z at require (node:internal/modules/cjs/helpers:102:18)
2022-11-21T06:18:21.148407911Z at Object.<anonymous> (/home/site/wwwroot/node_modules/.bin/nodemon:3:13)
2022-11-21T06:18:21.148412411Z at Module._compile (node:internal/modules/cjs/loader:1105:14)
2022-11-21T06:18:21.148416111Z at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
2022-11-21T06:18:21.148419811Z at Module.load (node:internal/modules/cjs/loader:981:32)
2022-11-21T06:18:21.148423511Z at Module._load (node:internal/modules/cjs/loader:827:12) {
2022-11-21T06:18:21.148427211Z code: 'MODULE_NOT_FOUND',
2022-11-21T06:18:21.148430811Z requireStack: [ '/home/site/wwwroot/node_modules/.bin/nodemon' ]
2022-11-21T06:18:21.148434611Z }
但是我的package.json没有任何demon。
{
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon App.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.18.2",
"mysql": "^2.18.1",
"nodemon": "^2.0.20"
}
}
1条答案
按热度按时间zvms9eto1#
终于用Docker解决了这个问题!
Package.json应该具有