Practice for deploying Node.js on Heroku

996Worker
996Worker
发布于 2021-07-03 / 262 阅读
0
0

Practice for deploying Node.js on Heroku

1. In app.js:

Import Express framework
Listen to the right port.

    app.listen(process.env.PORT || 8080, () => {
    // process.env.PORT is for Heroku's port
    if (process.env.PORT) {
        console.log('port: ' + process.env.PORT);
    } else {
        console.log('port: 8080')
    }
})

2. Create a file called Procfile

inside: web: npm start

3. Publish it to github, then attach this repository to the Heroku platform. Done.


评论