I am a beginner user of NodeJS and I have a specific request. I need assistance with setting up a page redirect from one page to another upon clicking on a link. Any guidance provided will be greatly appreciated. Here is the code snippet:
app.js
var express = require('express');
var app = express();
app.get('/', function(req,res){
res.status(200).sendFile(__dirname + '/index.html');
});
app.get('/newPage.html', (req, res) => res.redirect('/newPage.html'))
var server = app.listen(process.env.PORT || '3000', function(){
console.log('App listening on Port %s', server.address().port);
console.log('Press Ctrl+C to quit');
});
index.html
<!DOCTYPE html>
<html>
<head>
<title>NodeJS - HTML/CSS</title>
</head>
<body>
<h1>NodeJS HTML and CSS Demo</h1>
<p>
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Maiores saepe quae debitis alias illum, animi sunt iste
</p>
<a href= "newPage.html">new page</a>
</body>
</html>
newPage.html
<!DOCTYPE html>
<html>
<head>
<title>New page</title>
</head>
<body>
<h1>This is the new page</h1>
</body>
</html>