Ok please tell me if I have got this correct.
1) When I do this…
const express = require(“express”)
I store a “Class” into the express variable.
2) Then when I do this…
express.jason()
Am I accessing the jason() function inside the express class ?
Ok please tell me if I have got this correct.
1) When I do this…
const express = require(“express”)
I store a “Class” into the express variable.
2) Then when I do this…
express.jason()
Am I accessing the jason() function inside the express class ?
1) Yes, using require you store whatever the package exports. It may be the pure Class, or a Class instance or a Function or some other variable.
2) Well, when you call express.json() you are calling .json() function from inside express instance from some class-like structure, yes.
You are likely to use the return of express.json() the following way to set a new express REST api:
const express = require('express')
const app = express()
app.use(express.json())
app.post(
'/test',
(req, res) => res.json(req.body)
)
const PORT = process.env.PORT || 3000
app.listen(PORT, () => {
console.log(`Server listening on port ${PORT}`)
})