[Fixed] Why do we use arrays of middleware functions in express?


can someone explain me why we are using this code in square brackets and why its assign to a const middlewares , Can we use it without const middlewares = [..]

const middlewares = [
    bodyParser.urlencoded({extended: false})

Sorry for the inconvenience, i am new to this field


This code creates an array of 3 elements.

In this case an array of 3 function pointers.

We can’t know exactly why the code you are looking at would have it but my guess is there is a system somewhere that wants to use this array so you create the array.

const is used to indicate that it won’t be changed.

You should read about closure in node in order to understand more about how this works.

Leave a Reply

(*) Required, Your email will not be published