0
0
Expressframework~30 mins

Query string parsing in Express - Mini Project: Build & Apply

Choose your learning style9 modes available
Query String Parsing with Express
📖 Scenario: You are building a simple Express server that reads user preferences sent as query strings in the URL.For example, a user might visit /settings?theme=dark&fontSize=16 to set their theme and font size.
🎯 Goal: Create an Express server that parses query strings from the URL and responds with a JSON object showing the parsed preferences.
📋 What You'll Learn
Create an Express app instance
Set up a GET route at /settings
Parse the query string parameters theme and fontSize
Respond with a JSON object containing theme and fontSize values
💡 Why This Matters
🌍 Real World
Web servers often need to read user preferences or filters from query strings to customize responses.
💼 Career
Understanding query string parsing is essential for backend developers building APIs or web applications with Express.
Progress0 / 4 steps
1
Set up Express app
Create a variable called express that requires the express module. Then create a variable called app by calling express().
Express
Need a hint?

Use require('express') to import Express and then call it as a function to create the app.

2
Add GET route for /settings
Add a GET route handler on app for the path '/settings' using app.get('/settings', (req, res) => { }).
Express
Need a hint?

Use app.get to define a route for /settings.

3
Parse query string parameters
Inside the /settings route handler, create two variables: theme and fontSize. Assign them the values from req.query.theme and req.query.fontSize respectively.
Express
Need a hint?

Access query parameters using req.query.

4
Send JSON response with parsed values
Inside the /settings route handler, send a JSON response using res.json() with an object containing theme and fontSize properties.
Express
Need a hint?

Use res.json() to send a JSON response with the parsed query values.