I have created a node server that scrapes through a certain website and then returns a nicely formatted json data. Everything works perfectly fine on my localhost. But now I want to upload it to a server and get a link that returns the json data (just like an api).
How do I do that?
Below is the code outline:
var express = require('express');
var fs = require('fs');
var request = require('request');
var cheerio = require('cheerio');
var app = express();
app.get('/', gotdata);
function gotdata(req, res){
url = 'myurlhere';
request(url, inside_request);
function inside_request(error, response, html){
if(!error){
var $ = cheerio.load(html);
var title, date, permalink;
var obj = { title : "", date : "", permalink : ""};
// ALL MY CODES HERE
res.send(obj);
}
}
}
app.listen('8081');
console.log('Visit http://localhost:8081/');
exports = module.exports = app;
OUTPUT from my localhost:8081/
You can use an nginx server instead if you have a public IP on the server where you want to deploy your API.
Define a virtual host to your API from nginx configuration.
Please follow the tutorial in the following link for virtual host creation
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.