No body wants to update each year their websites copyright manually. And most of beginner runs away from JavaScript. Fortunately, JavaScript isn't required for this task.(Though we can do it using JavaScript too).
phpCopy code
**</body>**
tag:This code uses the **new Date()**
constructor to create a new **Date**
object, which represents the current date and time. The **getFullYear()**
method is then used to extract the current year from the date object. Finally, the value of the year is inserted into the HTML element with the ID of "year" using the **innerHTML**
property.
Now, whenever your website is loaded, the current year will be automatically inserted into the HTML element, updating the copyright year on your website.
You can also add this JavaScript code to an external .js file and include it in your HTML file to keep your code organized and reusable.
**copyright.ejs**
in your views directory and add the following HTML code:This code uses Embedded JavaScript (EJS) to insert the value of the **year**
variable into the HTML.
javascriptCopy code
This code creates a new GET route for the root URL of your application. When the route is accessed, the **render**
method is used to render the **copyright.ejs**
file and pass the current year to it as a local variable.
Now, whenever your Node.js application is loaded, the current year will be automatically inserted into the HTML element, updating the copyright year on your website.