-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathartparser.js
48 lines (36 loc) · 1.24 KB
/
artparser.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
/**
* Using Express as server
*/
const { extract } = require('./node_modules/article-parser/dist/cjs/article-parser.js')
//include express
const express = require('express')
//include cors, to allow all external domains to access
const cors = require('cors')
//initialize express with cors
const serv = express();
serv.use(cors())
//GET request at '/' route
serv.get('/', function(req, res) {
//get article url parameter from request
let articleUrl = req.query.url
console.log('retrieving full article content for url --->')
console.log(articleUrl)
//call library to extract article
extract(articleUrl).then((article) => {
//log extaction output
// console.log('output >>>>')
// console.log(article)
//return extaction output as json
res.json(article)
}).catch((err) => {
console.trace(err)
})
})
//server params
const hostname = '127.0.0.1';
const port = 3008;
//start server
serv.listen(port, function(req, res) {
console.log(`---> Article Parser Server running at http://${hostname}:${port}/`);
console.log('---> Sample request to the server will be >> http://127.0.0.1:3008/?url=article_url_beginning_with_http');
})