Programming Tips πŸ’‘
51.5K subscribers
67 photos
10 videos
30 files
354 links
Programming & AI:
Tips πŸ’‘
Articles πŸ“•
Resources πŸ‘Ύ
Design Patterns πŸ’Ž
Software Principles βœ…

πŸ‡³πŸ‡± Contact: @MoienTajik

🎯 Buy ads: https://telega.io/c/ProgrammingTip
Download Telegram
πŸ’Ž <%= EJS %> πŸ’Ž

"E" is for "effective." EJS is a simple Templating Language that lets you generate HTML markup with plain JavaScript. πŸ”₯

No religiousness about how to organize things. No reinvention of iteration and control-flow. It's just plain JavaScript. πŸ€·πŸ»β€β™‚οΈ

[ Website ] : http://ejs.co/

https://t.me/pgimg/8
γ€°γ€°γ€°γ€°γ€°γ€°
#ejs #templating #js #node #express
@ProgrammingTip
Writing middleware for use in Express.js apps πŸ”₯

Overview πŸ”Ž
Middleware functions are functions that have access to the request object (req), the response object (res), and the next function in the application’s request-response cycle.

The next function is a function in the Express router which, when invoked, executes the middleware succeeding the current middleware. ⏭

Middleware can perform πŸ’Ž
β€’ Execute any code.
β€’ Make changes to the request and the response objects.
β€’ End the request-response cycle.
β€’ Call the next middleware in the stack.

πŸ”ΈπŸ”ΉπŸ”ΈπŸ”Ή

Configurable middleware πŸ“₯
If you need your middleware to be configurable, export a function which accepts an options object or other parameters, which, then returns the middleware implementation based on the input parameters.

in my-middleware.js


module.exports = function(options) {
return function(req, res, next) {
// Implement the middleware function
next();
}
}


πŸ”ΈπŸ”ΉπŸ”ΈπŸ”Ή

Usage Middleware πŸ“€
The middleware can now be used as shown below.

const mddleware = require('./my-middleware.js')
app.use(mddleware({ option1: '1', option2: '2' }))


https://t.me/pgimg/77

γ€°γ€°γ€°γ€°γ€°γ€°
#JavaScript #Express #Middleware
@ProgrammingTip