DEV Community

'Express Middleware' is just a fancy way of chaining a bunch of functions. Explained in 3 mins 😎

TechBos😎 on September 01, 2019

Let's start by creating the world's simplest Express server: import express from "express"; const app = express(); app.get('/hello', (req, res...
Collapse
 
rafaacioly profile image
Rafael Acioly

Nice post! 😃

Tip: you can add this article about Chain of responsability pattern so people that want to learn more about it can find easily

refactoring.guru/design-patterns/c...

Collapse
 
waqar903 profile image
waqar903

Nice Work..!
Can you please tell how can i upload my expressjs API's with mongoDB to live server with my domain hosting?

Collapse
 
techbos profile image
TechBos😎

Thank you for reading!

Where are you deploying your web server and mongoDB?

Collapse
 
waqar903 profile image
waqar903

for now i have it in my PC with localhost:3000
i am also curious about which server is needed for these Api's
lets suppose i have a linux base Hosting and i want to upload these api's there? is it possible? how?

Thread Thread
 
techbos profile image
TechBos😎

There are many ways you can deploy your server, and this comment is not the best place to answer your question. Probably the easiest approach is to copy your js files to the server and node run from there. For mongodb you can either start your own instance on the server, or find some free servers online which are great for dev purpose. Good luck!

Thread Thread
 
waqar903 profile image
waqar903

thanks for help.

Collapse
 
ddsilva profile image
Daniel Silva

Very nice post! Than you for sharing!

Maybe, there is a little bug in the functions returned by BodyParser, on last example. They aren't calling next() inside them. Is this correct? 🤔

Collapse
 
techbos profile image
TechBos😎

Yep. Fixed. Good eye :D

Collapse
 
fsrezende profile image
Filipe S Rezende

Nice work! Contrate!!

Collapse
 
sebbdk profile image
Sebastian Vargr

offtopic, but why do people still use express when Koa is a thing? :D

Collapse
 
gregfletcher profile image
Greg Fletcher

Great post! Looking forward to more breakdowns!

Collapse
 
pcleddy profile image
Paul Charles Leddy

This. is. brilliant!

Collapse
 
shmdhussain12 profile image
Mohamed Hussain

Thanks for the simple and clear explanation on how the chaining works in express.

Collapse
 
jdg23dev profile image
Jamie

This is a treat of a post. Thank you ☺️

Collapse
 
jangjuyeop profile image
JangJuYeop

Good Post!
I'll refer your post my TIL blogging!