I have nodejs project running on centos 7.
I'm trying to run my nodejs project with the command node start.js
aswell tried sudo node start.js
but tends to be hanging up, i included a screenshot too, which you can find there: http://prntscr.com/g4ogcf
Can anybody help me with this? I'm quite clueless about that because it doesn't return any errors aswell.
My start.js application code:
const app = require('express')();
const fs = require('fs');
const server = require('http').Server(app);
const cors = require('cors');
const express = require('express');
const Database = require('./Database.js');
const db = new Database();
const cfg = require('./config/config.json');
const io = require('socket.io')(cfg.client.socket_port);
const Router = require('./Router')(db, io);
app.listen(cfg.client.server_port);
app.use(cors());
app.get('/', (req, res) => {
fs.readFile(`${__dirname}/../public/client/app/index.html`, (err, data) => {
if (err)
throw err;
res.send(data.toString())
});
});
app.get('/media', (req, res) => {
if (req.query.cfg) {
res.set('Content-Type', 'application/javascript');
fs.readFile(`${__dirname}/config/config.json`, (err, data) => {
if (err)
throw err;
res.send(`export default ${JSON.stringify(JSON.parse(data).client)}`);
});
}
res.set('Content-Type', 'image/jpeg');
if (req.query.avatar) {
db.getAvatarImg(req.query.avatar).then(x => {
var img = x[0] ? x[0].img : '';
const data = img.replace(/^data:image\/\w+;base64,/, "");
const buf = new Buffer(data, 'base64');
res.send(buf);
});
}
if (req.query.background) {
db.getBackgroundImg(req.query.background).then(x => {
var img = x[0] ? x[0].img : '';
const data = img.replace(/^data:image\/\w+;base64,/, "");
const buf = new Buffer(data, 'base64');
res.send(buf);
});
}
if (req.query.post) {
db.getPostImg(req.query.post).then(x => {
var img = x[0] ? x[0].img : '';
const data = img.replace(/^data:image\/\w+;base64,/, "");
const buf = new Buffer(data, 'base64');
res.send(buf);
});
}
});
app.use(express.static(`${__dirname}/../public/`));
答案 0 :(得分:0)
把
console.time('app started');
在所有require语句和
之前console.timeEnd('app started');
在start.js代码的末尾。借助此功能,您可以检查您的应用程序是否已成功挂起或初始化。
答案 1 :(得分:0)
程序没有任何问题。
只需将app.listen(cfg.client.server_port);
更新为
app.listen(cfg.client.server_port, ()=>{
console.log("server started at port "+cfg.client.server_port);
});
这将在控制台上登录,告诉您服务器已启动。