-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
51 lines (37 loc) · 949 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// routes.js from inside a service
const express = require("express");
let router = express.Router();
router.use("/", function(req, res, next) {
console.log("in router");
next();
});
router.get("/", function(req, res, next) {
res.send("in router nothing");
});
router.get("/home", function(req, res, next) {
res.send("in router home");
});
// module.exports = router
// --------------------------------------------------------
// app.js or index.js from the main folder
let app = express();
let PORT = 3001;
app.use("/", function(req, res, next) {
console.log("--------------\nin app");
next();
});
app.get("/", function(req, res, next) {
res.send("in app nothing");
});
app.get("/home", function(req, res, next) {
res.send("in app home");
});
// let router = require("./router");
app.use("/router", router);
app.listen(PORT, function(err) {
if (err) {
console.log(err);
} else {
console.log("up on port " + PORT)
}
});