I have a node app that serves a static webpage. It uses express to serve the page:
var express = require('express');
var app = express();
app.use(express.static('public'));
app.listen(3000);
this is the public/index.html
<html>
<head>
<script src=app.js></script>
</head>
</html>
This is the app.js
function connect() {
var options = {
hostname: 'testapi.com',
port: 9443,
path: '/api/v1/Values',
method: 'GET',
headers: {
}
}
const req = http.request(options, (res) => {
res.on('data', (d) => {
var content = new TextDecoder("utf-8").decode(d);
console.log(content)
})
})
req.on("error", (e) => {
console.log(e)
});
req.end()
}
connect()
How can I import a the http node module so that is it usable in app.js. When using import I get Cannot use import statement outside a module. When I use require() I get require is not defined