-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelloServer.js
More file actions
31 lines (29 loc) · 989 Bytes
/
HelloServer.js
File metadata and controls
31 lines (29 loc) · 989 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
29
30
31
var http = require('http');
var mongoose = require('mongoose');
var fs = require('fs');
// connecting to mongodb
mongoose.connect ('mongodb://localhost/my_database');
// making http server
http.createServer(function (req, res) {
debugger; // TODO take me out
fs.readFile("index.html", {encoding : "utf8"}, function (err, data) {
res.writeHead(200, {'Content-Type': 'text/html'});
if (err) throw err;
res.write(data);
fs.readFile("body.html", function (err, data) {
res.write(data);
// Find a Cat by name.
Cat.findOne({ name: 'Zildjian'}, function(err, found){
if (err) return console.error(err);
console.log('Zildjian');
if (found) {
res.write("<h2>" +found.name+ "</h2>");
}
res.end("Finished my call back");
});
console.log("File 2 call back finished");
});
console.log("This is end");
});
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');