Showing
1 changed file
with
7 additions
and
1 deletions
| ... | @@ -31,7 +31,7 @@ var tempArr = []; | ... | @@ -31,7 +31,7 @@ var tempArr = []; |
| 31 | app.set("views", __dirname + "/views"); | 31 | app.set("views", __dirname + "/views"); |
| 32 | app.set("view engine", "ejs"); | 32 | app.set("view engine", "ejs"); |
| 33 | 33 | ||
| 34 | -app.get("/", function (req, res) { | 34 | +function init() { |
| 35 | request.get(requestUrl, (err, res, body) => { | 35 | request.get(requestUrl, (err, res, body) => { |
| 36 | if (err) { | 36 | if (err) { |
| 37 | console.log("err => " + err); | 37 | console.log("err => " + err); |
| ... | @@ -84,6 +84,10 @@ app.get("/", function (req, res) { | ... | @@ -84,6 +84,10 @@ app.get("/", function (req, res) { |
| 84 | } | 84 | } |
| 85 | } | 85 | } |
| 86 | }); | 86 | }); |
| 87 | +} | ||
| 88 | + | ||
| 89 | +app.get("/", function (req, res) { | ||
| 90 | + init(); | ||
| 87 | // Send data from nodejs to ejs | 91 | // Send data from nodejs to ejs |
| 88 | res.render("data.ejs", { data: tempArr }, function (err, html) { | 92 | res.render("data.ejs", { data: tempArr }, function (err, html) { |
| 89 | if (err) { | 93 | if (err) { |
| ... | @@ -95,5 +99,7 @@ app.get("/", function (req, res) { | ... | @@ -95,5 +99,7 @@ app.get("/", function (req, res) { |
| 95 | res.sendFile(__dirname + "/views/data.ejs"); | 99 | res.sendFile(__dirname + "/views/data.ejs"); |
| 96 | }); | 100 | }); |
| 97 | 101 | ||
| 102 | +init(); | ||
| 103 | + | ||
| 98 | const port = 8080; | 104 | const port = 8080; |
| 99 | app.listen(port, () => console.log("Listening on port " + port)); | 105 | app.listen(port, () => console.log("Listening on port " + port)); | ... | ... |
-
Please register or login to post a comment