Professional Documents
Culture Documents
Express Basic Exercise
Express Basic Exercise
1. Create a new directory for your project and navigate into it.
2. Initialize a new npm project and create a package.json file.
3. Install Express.js using npm.
4. Create an app.js file and write a simple Express server that listens on port 3000.
5. Start the server and visit http://localhost:3000 in your browser to check that the
server is running.
1. Add middleware to your application that logs the request method and URL to the
console every time a request is received.
2. Create custom middleware that blocks access to a new route /secret by sending
a response with a status code of 403 and a message 'Access Denied'.
3. Test your middleware to ensure it is functioning correctly.
1. Create a new route that uses route parameters to capture a user ID and article ID
from the URL. The format should be /users/:userId/articles/:articleId.
2. Modify the route handler to send back a message that includes both the user ID
and article ID extracted from the URL.
3. Test this by visiting different URLs that match this pattern in your browser.