We should try to maintain "separation of concerns" while we build this app. In order to do that we need to determine what those concerns are.
The first step a server needs to do is listen for connections, so we'll make that the sole concern of index.js
and create a separate server.js
file to handle those connections.
mkdir api
touch api/server.js
Now cut everything but the server.listen
line out of index.js
and paste it into server.js
At the top of index.js
add the line
const server = require('./api/server')
and at the bottom of server.js
add the line
module.exports = server
With that complete, our server should be working again. Test by going to localhost:8080/hello in your browser - or even better Postman - and you should get the welcome message again.
git add .
git commit -am 'separate server into api directory'