🔧 Programmierung 🕛 vor 1 Jahr 4 Min Lesezeit
0

Express 5 is here, what’s new?

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

Expressjs is a popular framework for nodejs, you can say its foundation of nodejs. The current version is express 4 which is the most popular and stable version and work on next version Express5 was being done but super slow.



Express5 is finally released after wait of 10 years with some major changes. In this article we are going to cover all these changes.



If you prefers to watch videos, i have created a video with proper explanation and comparision with expressjs4.










Here are 10 major changes in express 5.






1. Support for es6



Express5 now supports es6 which means we can use import instead of require and all other modern ecmascript features. This allows developers to write much cleaner code and use all modern javascript syntax.






2. Promise rejection support



In express4 if you are using promise/async await code and if error happens, you had to manually catch the exception and then pass the error in next middleware.



Express5 automatically handles this which means focus on your logic not handling the exception.






3. Builtin body parser



In Express 4 we had to install seperate library “body-parser” for handling post data.



Express 5 has body-parser integrated internally which means no extra dependency.






4. req.param(name) removed



In earlier version of express — you could extract forms data using




CODE
req.param(name)






This could be data from query, param or even body which confuses the source of data. This was already deprecated.



But in express it has been completely removed. Now you need to explicitly use — req.query, req.body or req.param based on where data is coming from.






5. app.del replaced with app.delete



In express 4 — the HTTP DELETE route was registered using app.del but in express5 it has been replaced with more explicit word delete, so you need to now use app.delete






6. app.param(fn) middleware is removed



In express4 app.param middleware was used to defined middleware that executes whenever the route param was found. This was used to preprocess some data, for example — if a route param has userId then find the user from database and attach to the request which would be needed later.



In express5 this has been removed and developers are encouraged to use more explicit approach that is use a middleware just before the route. This makes the things much clear and easy to debug.






7. res.send(status) replaced with res.sendStatus(status)



In express 4 you could send a response without data using res.send which confused developers like where is the data, is it a bug or something different.



In express5 an explicit method res.sendStatus is introduced for sending response with only status code and no data.






8. res.send sends data only



In express 4, you could send response with status code and data using




CODE
res.send(stauts, data);






but in express5, the send method only accepts one parameter which is data and a method status has been added to send the status.




CODE
res.status(status).send(data);









9. req.query is read only



In express 4 , you could mutate the req.query — add aadditional property or remove.




CODE
req.query.id =5 ;






this creates confusion as source of data was not request but set somewhere explicitly in the code.



In express 5, req.query is read only which means no more changes on the req.query






10. req.body is undefined by default



In express 4, req.body value was empty object {}by default. So if you are in get request or you have not configured body parser the value of req.body will be empty object.



But in express5, it will be undefined. Which will explicitly states that there is no body data.






Conclusion



Express 5 majorly focuses on -




  • Express 5 focuses on making things more clear and explicitly defined.

  • Remove confusing parts

  • Move external dependency to internal dependency

  • Internal optimization

  • Support for modern javascript



👉 Thanks for reading everyone. Please let me know what do you think about express5 in the comments and follow me for more such articles.



💁‍♂ Also if you like to watch tech videos, please subscribe to my youtube channel. Where i share lot of tech tips, news, experiment etc.





Linkedin —

Vollständiger Original-Artikel
Den kompletten Beitrag mit allen Details direkt auf dev.to lesen.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Vlog. Edit. Repeat. | Advanced by AMD Ryzen™ AI series processors
1 Quelle
New Official DC Super Hero Collection Chrome Themes
1 Quelle
How Project HydraFusion reduces the cost of frontier AI
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Express 5 is here, what’s new?

Thematisch verwandte Begriffe: Express, here, whats · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...