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.
Disclaimer:
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}`)
})