-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathother.js
24 lines (23 loc) · 823 Bytes
/
other.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
const http = require('http');
const fs = require('fs'); // is file-handling
const port = 3000;
const server = http.createServer(function (req,res) {
// handle different activity on our server
res.writeHead(200, { 'Content-Type': 'text/html'}) // Content-Type will be the text from the html file
fs.readFile('index.html', function (error, data) {
if(error){
res.writeHead(404)
res.write('Error: File Not Found')
} else{
res.write(data) // data is all the information inside index.html
}
res.end();
})
})
server.listen(port, function(error){ // gives us info on whether this was successful
if(error){
console.log('Something went wrong', error)
} else{
console.log('Server is listening on port ' + port)
}
})