Skip to content

Commit c2f1ae3

Browse files
committed
add examples for 2.5 2.6
1 parent 653f532 commit c2f1ae3

File tree

10 files changed

+2194
-0
lines changed

10 files changed

+2194
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
constexpress=require("express");
2+
constDatastore=require("nedb");
3+
4+
constapp=express();
5+
app.listen(3000,()=>console.log("listening at 3000"));
6+
app.use(express.static("public"));
7+
app.use(express.json({limit: "1mb"}));
8+
9+
constdatabase=newDatastore("database.db");
10+
database.loadDatabase();
11+
12+
app.get("/api",(request,response)=>{
13+
database.find({},(err,data)=>{
14+
if(err){
15+
response.end();
16+
return;
17+
}
18+
response.send(data);
19+
});
20+
});
21+
22+
app.post("/api",(request,response)=>{
23+
constdata=request.body;
24+
consttimestamp=Date.now();
25+
data.timestamp=timestamp;
26+
database.insert(data);
27+
response.json(data);
28+
});

0 commit comments

Comments
(0)