DEV Community

Cover image for Understanding the Simple Express App | Node.js
Dhawal Singh Panwar
Dhawal Singh Panwar

Posted on

Understanding the Simple Express App | Node.js

You're familiar with the concept of modularity from OOPS, right? So, my introduction is not in this post. 😆


Introduction

Express is a framework which makes it quite easy to build an API rapidly.

Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications.

With a myriad of HTTP utility methods and middleware at your disposal, creating a robust API is quick and easy.

The agenda is to understand each line of code it took to develop the Simple Express App 🌱

GitHub logo dspsolves / Simple-Express-App

A very simple Express app for demonstration purposes.

Contents

Setup

Before getting down to the development part, let's set up our development environment.

Windows

Linux

  • Install VS Code
sudo snap install --classic code
Enter fullscreen mode Exit fullscreen mode
  • Install Node.js and npm
sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install npm
Enter fullscreen mode Exit fullscreen mode
git clone https://github.com/dsp9107/Simple-Express-App.git
Enter fullscreen mode Exit fullscreen mode
  • Open the directory with VS Code for a convenient experience 😁
cd Simple-Express-App
code .
Enter fullscreen mode Exit fullscreen mode

Usage

We'll get the server running and then move to the interaction part.

Starting the Server

  • Once VS Code opens, open the integrated terminal with Ctrl + ` if you do not see it at the bottom
  • Install the dependencies
npm install
Enter fullscreen mode Exit fullscreen mode
  • While the dependencies are being installed, let's tweak our VS Code a bit 😀
  • Once done, let's start the server
npm start
Enter fullscreen mode Exit fullscreen mode

We can see Listening At somenumber ..., in the terminal, which we'll call PORT from here on.

Interacting with the Server

  • Open any browser
  • Go to localhost:PORT/pathVars/helloWorld

You can see the response on the page. Try replacing helloWorld with somethingElse in the URL. Those are path variables that are explained below.

Using the URL bar of browsers, you can only make GET requests.

  • In this post, I've explained how you can use Postman to interact with our Simple Express App. 😄

Check out Postman for a broader set of HTTP methods and API testing functionalities.

Explanation

There are comments which explain the most basic stuff.

This is api.js explained!

There are links down below which you can use to explore further. 😄

And whenever you save either of the files with or without any changes, the server will restart, thanks to nodemon 🔥

Conclusion

It's easier to catch up with a framework when you are familiar with its base programming language than to directly jump to the framework.

References

Further Reads

Top comments (0)