Skip to content
This repository was archived by the owner on Oct 10, 2026. It is now read-only.

Commit 8ea99ff

Browse files
author
manuel.depaz
committed
Simple Samples
1 parent 7fbb3a6 commit 8ea99ff

5 files changed

Lines changed: 40 additions & 42 deletions

File tree

‎P00_CodeSamples/HelloWorldNode.js‎

Lines changed: 0 additions & 4 deletions
This file was deleted.

‎P00_CodeSamples/async_vs_sync_example_1.js‎

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,26 @@ http = require("http");
22

33
tiempo_inicial = new Date();
44

5-
palabros = ["arbol", "boca", "casa", "dedo", "eco", "fuego", "ganso"]
5+
palabros = [ "arbol", "boca", "casa", "dedo", "eco", "fuego", "ganso" ]
66

7-
function llamaWiki ( host, APIs ) {
8-
var palabro = palabros.shift();
9-
console.log(palabro,"INICIO");
10-
http.get({ host: "es.wikipedia.org", path: "/wiki/"+palabro }, function(res) {
11-
res.on('end', function () {
12-
console.log(palabro,"FIN");
13-
if( palabros.length ) {
14-
llamaWiki();
15-
}
16-
else{
17-
tiempo_final = new Date();
18-
console.log("Tiempo total:",tiempo_final.getTime() - tiempo_inicial.getTime());
19-
}
7+
function llamaWiki(host, APIs) {
8+
var palabro = palabros.shift();
9+
console.log(palabro, "INICIO");
10+
http.get({
11+
host : "es.wikipedia.org",
12+
path : "/wiki/" + palabro
13+
}, function(res) {
14+
res.on('end', function() {
15+
console.log(palabro, "FIN");
16+
if (palabros.length) {
17+
llamaWiki();
18+
} else {
19+
tiempo_final = new Date();
20+
console.log("Tiempo total:", tiempo_final.getTime()
21+
- tiempo_inicial.getTime());
22+
}
23+
});
2024
});
21-
});
2225
}
2326

2427
llamaWiki();

‎P00_CodeSamples/async_vs_sync_example_2.js‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@ http = require("http");
22

33
tiempo_inicial = new Date();
44

5-
palabros = ["arbol", "boca", "casa", "dedo", "eco", "fuego", "ganso"]
5+
palabros = [ "arbol", "boca", "casa", "dedo", "eco", "fuego", "ganso" ]
66

77
total_respuestas = palabros.length;
88

9-
palabros.forEach(function (value, index) {
10-
console.log(value,"INICIO");
11-
http.get({ host: "es.wikipedia.org", path: "/wiki/"+value }, function(res) {
12-
res.on('end', function () {
13-
console.log(value, "FIN");
14-
total_respuestas--;
15-
if( total_respuestas == 0 ) {
16-
tiempo_final = new Date();
17-
console.log("Tiempo total:",tiempo_final.getTime() - tiempo_inicial.getTime());
18-
}
19-
});
20-
});
9+
palabros.forEach(function(value, index) {
10+
console.log(value, "INICIO");
11+
http.get({
12+
host : "es.wikipedia.org",
13+
path : "/wiki/" + value
14+
}, function(res) {
15+
res.on('end', function() {
16+
console.log(value, "FIN");
17+
total_respuestas--;
18+
if (total_respuestas == 0) {
19+
tiempo_final = new Date();
20+
console.log("Tiempo total:", tiempo_final.getTime() - tiempo_inicial.getTime());
21+
}
22+
});
23+
});
2124
});
22-
23-
24-
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
/*
2-
* http://howtonode.org/hello-node
3-
*/
41

52
// Load the http module to create an http server.
63
var http = require('http');
74

85
// Configure our HTTP server to respond with Hello World to all requests.
9-
var server = http.createServer(function (request, response) {
10-
response.writeHead(200, {"Content-Type": "text/plain"});
11-
response.end("Hello World\n");
6+
var server = http.createServer(function(request, response) {
7+
response.writeHead(200, {
8+
"Content-Type" : "text/plain"
9+
});
10+
response.end("Hello World\n");
1211
});
1312

1413
// Listen on port 8000, IP defaults to 127.0.0.1
1514
server.listen(process.env.IP);
1615

1716
// Put a friendly message on the terminal
18-
console.log("Server running at "+process.env.IP+':'+process.env.PORT);
17+
console.log("Server running at " + process.env.IP + ':' + process.env.PORT);

0 commit comments

Comments
 (0)