You're familiar with the concept of modularity from OOPS, right? So, my introduction is not in this post. π
Article No Longer Available
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 π±
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
- Get VS Code
- Get Node.js
- Download Simple Express App by clicking here : β¬οΈ
dspsolves / Simple-Express-App
A very simple Express app for demonstration purposes.
Simple Express App
Use this app with this article to understand each line of code it takes to set up a basic API with an Express App on Node.js
π± Usage
An
npm install
is all it takes.Tutorial - Check out this dev post!
Explanation - Check out this gist!
Documentation
These are the available open routes.
- Unzip it and open the folder in VS Code for a convenient experience π
Linux
- Install VS Code
sudo snap install --classic code
- Install Node.js and npm
sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install npm
- Clone this repo
git clone https://github.com/dsp9107/Simple-Express-App.git
- Open the directory with VS Code for a convenient experience π
cd Simple-Express-App
code .
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 π
Article No Longer Available
- 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. π
Article No Longer Available
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.
Top comments (0)