Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Node.JS Using import vs require?

Malcolm

Administrator
Administrator
Staff Team
Code Plus
Company Plus
Hi folks,

I never thought to ask or look this up before (I mainly just went with whatever works), but when would you use require vs import? I noticed in some videos and code repositories some people use require and some use import. From the bits of pieces that I've gathered import seems like the newer standard, is that right?
 
Solution
import is part of ES6-standard and more used in modern scripts. Require is something you can see a lots of specially in server side, older scripts.

Personally i like require more, but i am gettin old fart here.
import is part of ES6-standard and more used in modern scripts. Require is something you can see a lots of specially in server side, older scripts.

Personally i like require more, but i am gettin old fart here.
 
Solution
import is part of ES6-standard and more used in modern scripts. Require is something you can see a lots of specially in server side, older scripts.

Personally i like require more, but i am gettin old fart here.
Haha, thank you for the help!
 
For a more detailed explanation 🙂 :
Require is nodejs built-in which allows for the flexibility to be able to use custom modules as well as the npm installed modules. Import, on the other hand, is indeed an ES-standard function that only calls npm based modules.

courtesy of:
 
For a more detailed explanation 🙂 :
Require is nodejs built-in which allows for the flexibility to be able to use custom modules as well as the npm installed modules. Import, on the other hand, is indeed an ES-standard function that only calls npm based modules.

courtesy of:
Thats excatly what i would have said, if i would not be a old fart lol
 

New Threads

Buy us a coffee!

Back
Top Bottom