-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
52 lines (45 loc) · 1.35 KB
/
server.js
File metadata and controls
52 lines (45 loc) · 1.35 KB
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
var express = require('express');
const { json } = require('express/lib/response');
var app = express();
var fs = require("fs");
app.get('/listUsers', function (req, res) {
fs.readFile( __dirname + "/" + "database.json", function (err, data) {
console.log( data );
res.end( data );
});
})
const user={
"user4" : {
"name" : "mohit",
"password" : "password4",
"profession" : "teacher",
"id": 4
}
}
app.post('/addUser',function(req,res){
fs.readFile( __dirname + "/" + "database.json", function (err, data) {
data=JSON.parse(data)
data["user4"] = user["user4"];
res.end(JSON.stringify(data))
});
})
app.get('/:id',function(req,res){
fs.readFile(__dirname+"/","database.json", function(err,data){
var users = JSON.parse( data );
var user = users["user" + req.params.id]
console.log( user );
res.end( JSON.stringify(user));
});
})
app.delete('/Delete',function(req,res){
fs.readFile(__dirname+"/","database.json", function(err,data){
data = JSON.parse( data );
delete data["user" + 2];
res.end(JSON.stringify(data))
})
})
var server = app.listen(5000, function () {
var host = server.address().address
var port = server.address().port
console.log("Example app listening at http://%s:%s", host, port)
})