Steps to Create Express Application
Let’s implement the URL parameter in an Express Application and see it in action.
Step 1: Create an Express Application with the below commands.
npm init -y
Step 2: Install Express library with npm and add it to dependency list
npm install --save express
Example: Adding server.js
- In the project directory, create a file named index.js.
- Create an express server in the file and listen for connections.
Javascript
// server.js // create an express object const app = require( "express" )(); // server port const PORT = 8080; // listen for connections app.listen(PORT, () => { console.log(`server is listening at port:${PORT}`); }); |
- In the above code, an express app is created by importing the express library.
- Server is listening in the 8080 Port for any incoming request, on successful start server will print a log in the console.
How to handle URL parameters in Express ?
In this article, we will discuss how to handle URL parameters in Express. URL parameters are a way to send any data embedded within the URL sent to the server. In general, it is done in two different ways.
Table of Content
- Using queries
- Using Route parameter
Contact Us