-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
executable file
·72 lines (61 loc) · 1.6 KB
/
app.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* Created by cvallenilla on 12-04-17.
*/
// FIRSTS STEPS WITH NODE
// require('./instantHello.js');
// var goodbye = require('./talk/goodbye.js');
// var talk = require('./talk');
// var question = require('./talk/question.js');
//
// talk.hello('Cocuba');
// talk.intro();
//
// var answer = question("Q = What is the meaning of life?");
//
// console.log(answer);
//
// goodbye();
// FIRSTS STEPS WITH NODE
// var fs = require('fs');
//
// console.log("Going to get a File...");
//
// fs.readFile('sync-blocking.js',function (err, file) {
// console.log('got the file');
// fs.readFile('async-non-blocking.js', function (err, file) {
// console.log('Got the other file');
// });
// });
//
// console.log("Meanwhile, app continues");
var express = require('express');
var path = require('path');
var app = express();
//set vars
app.set('port', 3000);
// middleware to see requests and responses from the web
app.use(function (req, res, next) {
console.log(req.method, req.url);
next();
});
//set the root folder
app.use(express.static(path.join(__dirname, 'public')));
//get method to index
app.get('/', function (req, res) {
console.log("GET the Homepage");
res
.status(200)
.sendFile(path.join(__dirname, 'public', 'index.html'));
});
// get method to json
app.get('/json', function (req, res) {
console.log('GET the json');
res
.status(200)
.json( {"jsonData" : true} );
});
//where port listen requests
var server = app.listen(app.get('port'), function () {
var port = server.address().port;
console.log('active in port ' + port);
});