Skip to content

Commit 1891c36

Browse files
committed
added the ejs
1 parent 165922c commit 1891c36

5 files changed

Lines changed: 67 additions & 20 deletions

File tree

app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ var express = require('express')
33
, cons = require('consolidate')
44
, routes = require('./routes');
55

6-
app.engine('html', cons.swig);
7-
app.set('view engine', 'html');
6+
app.engine('html', require('ejs').renderFile);
7+
app.set('view engine', 'ejs');
88
app.set('views', __dirname + '/public');
99

1010
app.use(express.bodyParser());

package.json

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
{
2-
"name": "newsapi",
3-
"version": "0.0.1",
4-
"description": "Fetching the googel API News using Nodejs",
5-
"dependencies": {
6-
"mime": "~1.2.7",
7-
"express": ">=3.x",
8-
"consolidate": "~0.9.1",
9-
"swig": "~0.14.0"
10-
}
11-
}
2+
"name": "newsapi",
3+
"version": "0.0.1",
4+
"description": "Fetching the googel API News using Nodejs",
5+
"dependencies": {
6+
"mime": "~1.2.7",
7+
"express": ">=3.x",
8+
"consolidate": "~0.9.1",
9+
"swig": "~0.14.0",
10+
"request": "~2.27.0",
11+
"ejs": "~0.8.5"
12+
}
13+
}

public/index.ejs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<html>
2+
<html lang='en'>
3+
<head>
4+
<title><%= title %></title>
5+
</head>
6+
<body>
7+
8+
<div id='content' >
9+
<form id='send-form' method="get" action="/getresult/">
10+
<input id='search' type='text' value='' name="search"/>
11+
<input id='send' type='submit' value='Search'/>
12+
</form>
13+
</div>
14+
15+
16+
</body>
17+
</html>

public/restapiresult.ejs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<html>
2+
<html lang='en'>
3+
<head>
4+
<title><%= title %></title>
5+
</head>
6+
<body>
7+
<%resData.forEach(function(res) {%>
8+
9+
<%= res.results %>
10+
11+
<%});%>
12+
13+
</body>
14+
</html>

routes/rest/restapi.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
1-
var http = require('http');
1+
var request = require('request');
22
function Restapi () {
33
this.curlCall = function(req,res){
44
var search = req.query.search;
55
var url = 'http://ajax.googleapis.com/ajax/services/search/news?v=1.0&q='+search;
6-
http.get(url,function(hreq,hres){
7-
//hres.setEncoding('utf8');
8-
//var resNews = JSON.parse(hres);
9-
console.log(hres);
10-
return res.render('index', {
11-
title: 'Search Page',
12-
data:hres
6+
var options = {
7+
host: 'http://ajax.googleapis.com/ajax/services/search/news?v=1.0&q=vivek'
8+
};
9+
request(url, function (error, response, body) {
10+
if (!error && response.statusCode == 200) {
11+
12+
/* response.on("data", function (d) {
13+
data += d;
1314
});
15+
16+
response.on("end", function () {
17+
response.render('index', {
18+
title: 'Index Page',
19+
resData: data
20+
});
21+
});*/
22+
res.render('restapiresult', {
23+
title: 'View Page',
24+
resData: body
25+
});
26+
27+
}
1428
});
1529
}
1630
}

0 commit comments

Comments
 (0)