In this post I would like to write getting started steps for Express.js framework.
What is Express? Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications.It’s an easy to use node.js framework for web applications.
How to Write Middleware for Express.js Apps
Let’s begin by installing it(assuming we already have Node.js installed). First, create a directory to hold your application, if you have not already done create a directory.I named my directory as “myapp”.
Now open your terminal, change to it and run npm init. init command will generate a package.json file in the current directory in our case in myapp.
After running ‘npm init’ you’ll be prompted with several questions. You can fill them out or hit enter to get through it. Now our package.json is ready now install Express in the “myapp” directory and save the dependencies and update the package.js file with dependencies list:
To install Express temporarily(don’t save the dependencies list) omit the “–save” option.
To verify our Express installation just create a file named app.js and add the following code:
We have created a new server using ‘app.listen’ and setting the http GET on app to send a ‘Hello World’ message. Other than root URL (/) and For every other path, it will respond with a 404 Not Found.
Now we need to start the server.
Awesome! Open a browser and head for http://localhost:3000 where you should see the ‘Hello World’ message.
I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.
I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.