Skip to content

Some general improvements to the getting started guide #347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: npm start
web: node index.js
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# node-js-getting-started

A barebones Node.js app using [Express 4](http://expressjs.com/).
A barebones Node.js app using [Express](https://expressjs.com/).

This application supports the [Getting Started on Heroku with Node.js](https://devcenter.heroku.com/articles/getting-started-with-nodejs) article - check it out.

Expand All @@ -15,7 +15,7 @@ $ npm install
$ npm start
```

Your app should now be running on [localhost:5001](http://localhost:5001/).
Your app should now be running on [localhost:5006](http://localhost:5006/).

## Deploying to Heroku

Expand Down
32 changes: 24 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
const express = require('express')
const path = require('path')

const PORT = process.env.PORT || 5001

express()
.use(express.static(path.join(__dirname, 'public')))
.set('views', path.join(__dirname, 'views'))
.set('view engine', 'ejs')
.get('/', (req, res) => res.render('pages/index'))
.listen(PORT, () => console.log(`Listening on ${ PORT }`))
const port = process.env.PORT || 5006

const app = express()

app.use(express.static(path.join(__dirname, 'public')))
app.set('views', path.join(__dirname, 'views'))
app.set('view engine', 'ejs')

app.get('/', (req, res) => {
res.render('pages/index')
})

const server = app.listen(port, () => {
console.log(`Listening on ${port}`)
})

process.on('SIGTERM', async () => {
console.log('SIGTERM signal received: gracefully shutting down')
if (server) {
server.close(() => {
console.log('HTTP server closed')
})
}
})
Loading