I am using NodeJS. I am receiving error while running the Node Server. I am running Node from server.js and calling a function which is present in status.js .
server.js :-
const express = require('express');
const bodyParser = require('body-parser');
const http = require('http');
const getHttpsRequests = require("./status");
const app = express();
const server = new http.Server(app);
let interval;
server.listen(3000, () => {
console.log("Server is listening on port 3000");
});
server.on('listening', () => {
interval = setInterval(() => {
getHttpsRequests(); // call the function getHttpsRequests from status.js
}, 1000);
});
status.js :-
var https = require('https');
module.exports = function getHttpsRequests (https) {
https.get('google.com', function (res) {
console.log("statusCode: ", res.statusCode);
console.log("headers: ", res.headers);
res.on('data', function (d) {
process.stdout.write(d);
});
}).on('error', function (e) {
console.error(e);
});
}
I have installed the required packages :-
npm install express body-parser http --save
I am running the node server like,
node server.js
It is giving me error :-
https.get('google.com', function (res) {
^
TypeError: Cannot read property 'get' of undefined