April 2020
Intermediate to advanced
716 pages
18h 55m
English
When the server receives a request at the root URL /, we will render template.js in the browser. In server.js, add the following route-handling code to the Express app to receive GET requests at /:
mern-simplesetup/server/server.js:
import template from './../template'app.get('/', (req, res) => { res.status(200).send(template())})
Finally, configure the Express app to start a server that listens on the specified port for incoming requests:
mern-simplesetup/server/server.js:
let port = process.env.PORT || 3000app.listen(port, function onStart(err) { if (err) { console.log(err) } console.info('Server started on port %s.', port)})
With this code, when the server is running, it will be able to accept requests ...
Read now
Unlock full access