Jacobmoracha
2 min readMar 24, 2022

--

Working With Express

Express is a Node.js web Framework for building and networking services and applications. Express is a fast, unopinionated minimalist web framework for Node.js. With its various features, it makes it easy to develop web applications that are very fast and shorter build time than node.js It’s based on the Node.js middleware module called connect which in turn uses the HTTP module. So, any middleware which is based on connect will also work Express.js.

Advantages of Express.js

  1. It’s easy to configure and customize.
  2. Makes it easy to develop Node.js applications.
  3. Based on HTTP methods and URLs Express allows for defining application routes
  4. Express has middleware that can be used to perform additional tasks on request and response
  5. It’s easy to integrate with different template engines
  6. Allows defining of error handling middleware Serving static files and resources of the application is easy
  7. Allows for the creation of the REST API server.
  8. Easy database connecting

Installation You can install Express into any project with Npm(node package manager)

*npm install express --save* or 
*yarn add express*

Yarn creates a package.json file when starting a new project from scratch ,to create it run npm init if its a new project from scratch

Sample Express web server

const express = require('express')
const app = express()
app.get('./',(req,res) => res.send ('congratulations you just created your first serve'))
app.listen(3000, () => console.log('Server ready'))

save the above file to index.js file in the root folder, start the server using

node index.js

open the browser on port 3000 on the localhost and you should see “congratulations you just created your first server”

In the above example, we import an express package to express the value

we instantiate an application by calling the app() method we then tell the application to listen for a get request on the / path and port 300

--

--