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

Implent below tasks in one npm project. Do not create separate project for each task mentioned below. Add appropriate links in header to make moving from page task to another, easy. These may not be used in real world scenerio as-is, as they are designed to understand working of cookies along with forms, ajax, query string, etc. 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 in next HTTP request e.g. /display-cookies , 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...