Getting Started with Express.js

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.

This post is part of a series called – Getting Started with Express.js
How to Write Middleware for Express.js Apps

Getting Started with Express.js

Installing Express.js

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.

0 0 vote
Article Rating
Notify of
Newest Most Voted
Inline Feedbacks
View all comments Protection Status
Would love your thoughts, please comment.x