У меня есть спокойный API с express и node.js, и он разбился примерно 1 раз за 24 часа.
Я вижу много тем, но не могу найти, как это исправить.
Моя npm версия 6.13.1 Моя версия узла 12.13.1
Я вижу мой журнал ошибок, и он говорит:
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Users\\Admin\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'start'
1 verbose cli ]
2 info using npm@6.13.1
3 info using node@v12.13.1
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle express-api@1.0.0~prestart: express-api@1.0.0
6 info lifecycle express-api@1.0.0~start: express-api@1.0.0
7 verbose lifecycle express-api@1.0.0~start: unsafe-perm in lifecycle true
8 verbose lifecycle express-api@1.0.0~start: PATH: C:\Users\Admin\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\Admin\Desktop\node-express 1.0.3\node_modules\.bin;C:\Python27\;C:\Python27\Scripts;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\ProgramData\chocolatey\bin;C:\Program Files (x86)\Yarn\bin\;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files\nodejs\;C:\Program Files\MySQL\MySQL Shell 8.0\bin\;C:\Users\Admin\AppData\Local\Microsoft\WindowsApps;C:\Users\Admin\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\Admin\AppData\Local\Yarn\bin;C:\Users\Admin\AppData\Roaming\npm
9 verbose lifecycle express-api@1.0.0~start: CWD: C:\Users\Admin\Desktop\node-express 1.0.3
10 silly lifecycle express-api@1.0.0~start: Args: [ '/d /s /c', 'node server.js' ]
11 silly lifecycle express-api@1.0.0~start: Returned: code: 3221225786 signal: null
12 info lifecycle express-api@1.0.0~start: Failed to exec start script
13 verbose stack Error: express-api@1.0.0 start: `node server.js`
13 verbose stack Exit status 3221225786
13 verbose stack at EventEmitter.<anonymous> (C:\Users\Admin\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:210:5)
13 verbose stack at ChildProcess.<anonymous> (C:\Users\Admin\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:210:5)
13 verbose stack at maybeClose (internal/child_process.js:1021:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
14 verbose pkgid express-api@1.0.0
15 verbose cwd C:\Users\Admin\Desktop\node-express 1.0.3
16 verbose Windows_NT 10.0.18362
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Admin\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "start"
18 verbose node v12.13.1
19 verbose npm v6.13.1
20 error code ELIFECYCLE
21 error errno 3221225786
22 error express-api@1.0.0 start: `node server.js`
22 error Exit status 3221225786
23 error Failed at the express-api@1.0.0 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 3221225786, true ]
Я не могу понять, в чем проблема, когда я читаю этот журнал.
Мой код:
// Create express app
var express = require("express")
var app = express()
var mysql = require('mysql')
var express = require("express")
var cors = require('cors')
app.use(cors())
// Server port
var HTTP_PORT = 3000
var con = mysql.createConnection({
host: "192.168.0.1",
port: "1234",
user: "username",
password: "pass"
});
var aladinModel = '';
var aladinModelStations = '';
function formatDate(date) {
var d = new Date(date),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
if (month.length < 2)
month = '0' + month;
if (day.length < 2)
day = '0' + day;
return [year, month, day].join('-');
}
var dateNow = formatDate(Date());
app.route('/')
.get(function (req, res) {
// omitted
res.setHeader('Access-Control-Allow-Origin', '*', 'Cache-Control', 'private, no-cache, no-store, must-revalidate');
//const date = req.query.date;
const id = req.query.id;
const daysForward = req.query.daysForward;
const query = `CALL aladin_surfex.Get_mod_cell_values_meteogram_cell('${dateNow}', ${id}, ${daysForward})`;
con.query(query, function (err, result, fields) {
if (err)
return res.status(500).json({ error: "Грешна заявка. Опитай отново !"})
aladinModel = result;
res.json({ aladinModel })
});
});
app.route('/stations')
.get(function (req, res) {
// omitted
res.setHeader('Access-Control-Allow-Origin', '*', 'Cache-Control', 'private, no-cache, no-store, must-revalidate');
const id2 = req.query.id2;
const query2 = `SELECT Station,Ime FROM aladin_surfex.stations_cells WHERE Station=${id2}`;
con.query(query2, function (err, result2, fields) {
if (err)
return res.status(500).json({ error: "Грешна заявка. Опитай отново !"})
aladinModelStations = result2;
res.json({ aladinModelStations })
})
});
// Start server
app.listen(HTTP_PORT, () => {
console.log("Server running on port %PORT%".replace("%PORT%", HTTP_PORT))
});
con.on('error', function(err) {
console.log(err.code); // 'ER_BAD_DB_ERROR'
});
app.use(function (req, res) {
res.status(404);
});
До Я публикую эту топи c, я использую порт 8000, теперь я меняю порт на 3000.
Я не уверен, но могут ли некоторые из моих приложений использовать этот порт?