Posts

Showing posts from December, 2024

Express JS - Track Recently Visited Pages in Session

When a user visits any web page, save the page name and URL in the session as an array of objects. Each object should contain the page name and URL. Create a footer.ejs file to display the list of the 10 most recently visited pages in the footer of every EJS page. Each page should appear as a clickable hyperlink in a separate row. If the user clicks on a link, the corresponding page should open. At the end of the list, include a "Remove All" link to clear the list of recently visited pages in the session. Add an "X" next to each link to allow the user to remove that specific page from the session. After removing a page or clearing the list, redirect the user to the /home page. If a user visits a page that is already in the list, move it to the top and remove the previous occurrence to avoid duplicates.

Express JS - Cookies Handling

Task 1: Define and Handle /cookie1 Create a route /cookie1 that sets two cookies, token and last_visit_timestamp , in the user's browser. When the browser sends these cookies back to the server, display their values using the cookie1.ejs template. Additionally, calculate and display the time (in seconds) since the user's last visit by subtracting the last_visit_timestamp cookie value from the current time. Ensure that the last_visit_timestamp cookie is updated with the current timestamp on each request. Refresh the page at random intervals to test its functionality. Task 2: Add Cookie Form at /add-cookie Develop a route /add-cookie with a form containing two input fields: Cookie Name and Cookie Value . When the form is submitted, store the specified cookie in the user's browser and redirect them to /home . Include a link to the "Add Cookie" form on the homepage for easy navigation. Task 3: Remove Cookie Form at /remove-cookie Implement a route /remove-cooki...