-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
38 lines (36 loc) · 1.07 KB
/
server.js
File metadata and controls
38 lines (36 loc) · 1.07 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
/**
* Created by vadivel on 27/08/16.
*/
var express = require('express');
var app = express();
var fs = require('fs');
var jsonData = {count:20,message:'hey vel'};
app.get('/',function (req,res) {
//res.sendFile takes an absolute path to a file and
//sets the mime type based on the file extname
//All the node module contains following variables module,exports & __dirname
//Internally res.sendfile will call fs.reafile see the below rest call for example
res.sendFile(__dirname+'/index.html',function (err) {
if(err){
res.status(500).send(err);
}
})
});
app.get('/fs',function (req,res) {
fs.readFile('index.html',function (err,buffer) {
//console.log(buffer);
var html = buffer.toString();
res.setHeader('Content-Type','text/html');
res.send(html);
});
});
app.get('/data',function (req,res) {
res.json(jsonData);
});
app.get('/info',function (req,res) {
res.send(jsonData);
});
var port = 3000;
app.listen(port,function () {
console.log('Listening on http://localhost:',port);
});