Rendering templates at the root 

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, add server code to listen 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)})

Get Full-Stack React Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.