Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

278
Views
import module from static js file

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

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!