-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
executable file
·37 lines (33 loc) · 930 Bytes
/
server.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
var wsServer = require('./ws');
const fs = require('fs');
var http = require('http');
var {port} = require('./env');
if (process.argv.length > 2){
var filePath = process.argv[2] || "";
if(!fs.existsSync(filePath)){
console.log('Please a valid existing file path!');
process.exit(1);
}
else{
console.log('watching file', filePath);
}
}
else{
console.log('File path missing!');
process.exit(1);
}
var server = http.createServer((request, response) => {
fs.readFile('./index.htm', function(error, content) {
if (error) {
response.writeHead(500);
response.end();
}
else {
response.writeHead(200, { 'Content-Type': 'text/html' });
response.end(content, 'utf-8');
}
});
}).listen(port);
wsServer.start(server, filePath);
console.log('Server started on port: ', port);
console.log(`Paste this link in your browser to monitor the file- http://127.0.0.1:${port}`);