I tried to deploy my app (ReactJs-NodeJs-Mongo) on Heroku.
But i got a problem when i tried to start it, i got a error message with "Something is already running on port ****".
My back is running, but not my front.
It's the first time i try to deploy on Heroku. So i'm missing something about it.
How can i fix this issue ?
Link to my git : https://github.com/romainbor/eteach
here is my index.js in my server folder :
const express = require('express');
const bodyparser = require('body-parser');
const security = require('./middleware/security');
const userRouter = require('./routes/user');
const AnnonceRouter = require('./routes/annonce');
const securityRouter = require('./routes/security');
const commentRouter = require('./routes/comment');
const mailRouter = require('./routes/mail')
const path = require('path');
const isDev = process.env.NODE_ENV !== 'production';
const PORT = process.env.PORT || 5000;
const PORT_CHAT = 3231
const app = express();
//app.use(express.static(path.resolve(__dirname, '../react-ui/build')));
const cors = require('cors');
var chat = require('http').createServer()
var io = module.exports.io = require('socket.io')(chat)
const SocketManager = require('./SocketManager')
io.on('connection', SocketManager)
chat.listen(PORT_CHAT, ()=>{
console.log("Connected to port:" + PORT_CHAT);
})
app.use(cors());
app.use(bodyparser.json());
app.use(security.verifyToken);
app.use('/', securityRouter);
app.use('/annonce', AnnonceRouter);
app.use('/user', userRouter);
app.use('/comment', commentRouter);
app.use('/mail', mailRouter);
// Serve static assets if in production
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html')) // relative path
})
app.listen(PORT, function () {
console.error(`Node ${isDev ? 'dev server' : 'cluster worker '+process.pid}: listening on port ${PORT}`);
});
my package.json at the root :
"scripts": {
"start": "concurrently \"cd server && node index.js\" \"cd client && npm start\"",
"heroku-postbuild": "cd client && npm install && npm run build"
}
I got all my console.log running from my back : "app is listening on port ****" etc. but for my front
2019-08-17T13:16:53.800476+00:00 app[web.1]: [1] Something is already running on port 32879. 2019-08-17T13:16:53.840457+00:00 app[web.1]: [1] cd client && npm start exited with code 0
If you have any idea of what am i doing wrong, i'm listening.
try changing
chat.listen(PORT_CHAT, function () {
console.log("Connected to port:" + PORT_CHAT);
});
to
chat.listen(process.env.PORT_CHAT || PORT_CHAT, function () {
console.log("Connected to port:" + PORT_CHAT);
});
And try to set PORT_CHAT enviroment variable to value you need
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.