Node.js Single File Application using Express Framework

Soni Pandey
1 min readNov 24, 2019

--

To structured our application, simple routing, and support for Connect middleware, allowing many extensions and useful features, we have used Express framework. Please follow below steps to create project and install express module as a dependency.

For example

mkdir expressapp cd expressapp npm init entry point: (index.js) app.js npm install express --save

In the expressapp directory, create a file named app.js and add the following code:

The app starts a server and listens on port 3000 for connections. The app responds with “welcome to home page!” for requests to the root URL (/) or route and responds with “welcome to about page!” for requests to the root URL (/about) or route. For every other path, it will respond with a 404 Not Found. Run the app with the following command:

Then, load http://localhost:9000/ in a browser to see the output. Feel free to download the full code for this post to see the full picture of how everything works together and customize it for your own needs. Have a look at the repository for complete working code.

Gituhub Repository

You can reach out to me for any doubt and suggestions. Please share this with others as well.

Thanks!
Happy Coding!!

Originally published at https://thepandeysoni.org.

--

--

Soni Pandey
Soni Pandey

Written by Soni Pandey

I am a Node.js Developer and eager to learn new technology. I blog, tweet & read whenever I can.

No responses yet