-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamplenode.js
58 lines (48 loc) · 1.33 KB
/
examplenode.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
//npm install express --save
const express = require('express')
const jsonbag = require('jsonbag_serverside')
const app = express()
const port = 8000
function makejsonbag(request,response,usebin,tofile)
{
var jb = new jsonbag.JSONBagBuilder()
jb.setInlineMode(!usebin)
{
var r = [];
r.push({name: "image1", url: ""})
jb.assignFile(r[0],"url","/0/url","image/png","logo.png",false)
r.push({name: "image2", url: ""})
jb.assignFile(r[1],"url","/1/url","image/png","logo.png",false)
}
if(!tofile)
{
jb.serialize_express(response)
}
else
{
jb.serialize_file(tofile)
}
}
app.get('/json', (request, response) => {
response.send('Hello from Express!')
makejsonbag(request,response,false,"")
})
app.get('/jsonbin', (request, response) => {
response.send('Hello from Express!')
makejsonbag(request,response,true,"")
})
app.get('/jsonlocal', (request, response) => {
response.send('Hello from Express!')
makejsonbag(request,response,false,"output.json")
})
app.get('/jsonbinlocal', (request, response) => {
response.send('Hello from Express!')
makejsonbag(request,response,true,"output.jsonbag")
})
app.use(express.static('.'))
app.listen(port, (err) => {
if (err) {
return console.log('something bad happened', err)
}
console.log(`server is listening on ${port}`)
})