How can I change the title for each page using NodeJS?
The index.html (not .js file) that is inside public folder is:
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8" />
    <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
  <meta
     name="viewport"
    content="width=device-width, initial-scale=1, shrink-to-fit=no"
   />
   <meta name="theme-color" content="#000000" />
  <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
  <title>Default Titlte for all pages</title>
</head>
<body>
   <noscript>You need to enable JavaScript to run this app.</noscript>
   <div id="root"></div>
 </body>
</html>
How can I change the title dynamically whenever I navigate to any page?
It's nothing else than changing page title in javascript by default like document.title = 'title'; but it depends on your environment.
NodeJS itself lacks the ability to parse and transform HTML.
In express it would be like (a route based approach):
router.get('/', function(req, res, next) {
    res.render('index', { title: 'title' });
}); 
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With