I have a main file - index.js:
var express = require('express');
var app = express();
var request = require('request');
var demo = require('demo');
app.get('/scrape', function (req, res) {
var url = "http://www.l.com";
request(url, function (error, response, html) {
if (!error) {
demo(html);
}
});
});
var server = app.listen(3000, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});
and my module is demo.js:
module.exports = function (html) {
....
return JSON.stringify(json);
}
Mistake:
TypeError: demo is not a function
I am new to node.js, I would like to know why this did not work. Maybe I do not understand the true principle of the module? Thanks for answering me first.
source
share