What is Express.js?

Screenshot 2022-08-26 at 4.09.23 PM.png

Express is used to make developing web apps and APIs much faster and easier. It is not officially part of node, meaning unlike http it is not built-in. But it is very standard in the market currently to use express with node.

Install using: npm install express —save

Note: —save is just beacause in the earlier node apps if you did not add —save it would not be saved in the package.json.

Express Basics:

To take express and invoke it do:

Screenshot 2022-08-26 at 4.21.12 PM.png

It is similar to http. Where we were taking server and invoking it using createServer().

The same thing can be done using:

Screenshot 2022-08-26 at 4.22.17 PM.png

But we will use the first one more often.

Now, in the app object we get bunch of useful methods:

Screenshot 2022-08-26 at 4.23.20 PM.png

Basic server setup:

Screenshot 2022-08-26 at 4.25.29 PM.png

Lets look into more methods:

app.get()