-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExpress.js
More file actions
28 lines (21 loc) · 733 Bytes
/
Express.js
File metadata and controls
28 lines (21 loc) · 733 Bytes
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
//creating a server from express
var express = require('express');
var http =require('http');
var fs =require('fs');
var app = express();
var server = http.createServer(app);
app.get('/',function(req,res){
//this message is shown in the main page of the server
res.send('express works')
});
app.get('/tasks',function(req,res){
//this will show in the tasks page of the server
//we can call the task page by putting/tasks after the localhost addres
fs.readFile('./db.json',function(err,data){
var tasks = JSON.parse(data.toString()).tasks;
res.json(tasks);
});
});
server.listen(3000,function(){
console.log("server is listening in the port 3000");
})