Documentation
Parameters
LiteNode utilizes parameters extensively to enhance routing and functionality within applications. Whether it's route parameters or query parameters, they provide a flexible way to handle dynamic data and user input.
Route Params
You can define routes with parameters:
// Define a route to handle GET requests for user details
app.get("/user/:id", (req, res) => {
// Extract the user ID from the request parameters
const userId = req.params.id
// Send a response with the user ID
res.end(`User ID: ${userId}`)
})
Accessing http://localhost:5000/user/123 will respond with "User ID: 123".
Query Params
Query parameters can be accessed via req.queryParams
:
// Define a route to handle GET requests for search queries
app.get("/search", (req, res) => {
// Extract the search query from the request query parameters
const query = req.queryParams.get("q")
// Send a response with the search query
res.end(`Search query: ${query}`)
})
Accessing http://localhost:5000/search?q=LiteNode will respond with "Search query: LiteNode".