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

336
Views
How can i use requier and import statments in node js , at the same file

my problem when i was working on my node js file , is that im importing readline statments , and using ( 'type': 'module' ) at the same time , wanting to use both ways while no errors how can i use requier on ( readline ) command ?
the type of error im facing is :

SyntaxError: Cannot use import statement outside a module

i tried to use module on ( packag.json) but then the requier statment will face type error i couldnt ( transfare) (import readline, { clearScreenDown } from "readline"; ) as an a requier statement like this (const db = require('./dbConnection');)

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can't, they're mutually-exclusive. import is ESM (JavaScript's native, specified module system), and require is CommonJS (Node.js's older module system).

Instead, you have to use ESM or CommonJS consistently.

If you need to do a dynamic (runtime-determined) import in ESM, you can use the import() pseudo-function, which is a bit like CommonJS require except that rather than making the calling code wait, it returns a promise.

about 4 years ago · Juan Pablo Isaza Report

0

Answer depends on the choice of method you want to use.

  1. Use import ABC from 'ABC' (node core module or packages downloaded via npm)
  2. User const abc = require('./ABC') for your custom modules. below are examples.

ABC.js

const ABC = ()=> {
 return "ABC is called";
}
module.exports=ABC;

now in file you want to call it. index.js

const abc = require('./ABC');
about 4 years ago · Juan Pablo Isaza Report
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!