Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
August 31, 2020 06:15 pm GMT

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 dsp9107 / 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
  • Install Node.js and npm
sudo apt-get updatesudo apt-get install nodejssudo apt-get install npm
git clone https://github.com/dsp9107/Simple-Express-App.git
  • Open the directory with VS Code for a convenient experience
cd Simple-Express-Appcode .

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
  • While the dependencies are being installed, let's tweak our VS Code a bit
  • Once done, let's start the server
npm start

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


Original Link: https://dev.to/dsp9107/understanding-the-simple-express-app-node-js-10j5

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To