-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
100 lines (61 loc) · 1.09 KB
/
server.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Adding express library
var express = require('express');
var app = express();
var server;
var products = [
{
name:"product 1",
price:10,
stock:14
},
{
name:"product 2",
price:19,
stock:3
},
{
name:"product 3",
price:123,
stock:5
},
{
name:"product 3",
price:26,
stock:5
}
];
/*
module.exports = {
startServer:function(){
var server = app.listen(3000, function(){
console.log('server started');
});
}
}
//You can also do like this
exports.startServer = function(){
var server = app.listen(3000, function(){
console.log('server started');
});
}
*/
// or you can also
function startServer(cb){
server = app.listen(3000, function(){
console.log('Server started');
cb();
});
}
function startRouter(){
//app.get('/', express.static('public'));
//app.get('/products', express.static('public'));
app.get('/products', function(req, res){
res.send(products);
});
// expose whole folder tree to the internet
app.use('/', express.static('public'));
}
module.exports = {
startServer: startServer,
startRouter: startRouter
};