In Express JS does app.listen need to be at the end of the file?

150
April 29, 2019, at 12:00 PM

In most tutorials using Express JS the app.listen function is always added at the end of the file. I want to understand if this is essential as all middleware is run in sequence.

Most examples show:

const express = require('express)
const app = express()
app.get('/', (req, res) => {
  res.send('Test')
}
app.listen(3000, () => {
  console.log('Server running on port 3000')
}

Is there any reason this shouldn't be done:

const express = require('express)
const app = express()
app.listen(3000, () => {
  console.log('Server running on port 3000')
}
app.get('/', (req, res) => {
  res.send('Test')
}
Rent Charter Buses Company
READ ALSO
ESP8266 / Arduino modbus RTU Buffer data conversion

ESP8266 / Arduino modbus RTU Buffer data conversion

I am using ESP8266 and ModbusMasterh library to communicate with RS485 enabled power meter

135
Easy to implement payment gateway that works in Pakistan?

Easy to implement payment gateway that works in Pakistan?

I am a beginner in front end development and I need help regarding payment gateway easiest to implement

128
How to set an Alarm Using an Intent Selecting the full date of the alarm (including day, month)

How to set an Alarm Using an Intent Selecting the full date of the alarm (including day, month)

So I'm trying to add a feature in my app to launch the alarm clock and set one, I tried it using the usual code:

143