I think when we use var express = require('express');
, express
get a function reference of createApplication()
and when we call express(), it will return app
object.
My doubt is if var express
is a function reference then how to use express.Router()
where express act as an object
Asked
Active
Viewed 44 times
-1

jiz
- 308
- 3
- 7
-
In JS, a function is more than a function. Confusing I know, but you might want to gen up on how JS prototype language works.. – Keith Feb 22 '18 at 10:14
1 Answers
-1
You generally do this with express:
const express = require('express');
const app = express();
const router = express.Router();
router.get('/', (req, res) => res.json("working"));
In JavaScript, everything is an object, even functions. You can add properties to function.

Faizuddin Mohammed
- 4,118
- 5
- 27
- 51