# The difference between "require(x)" and "import x"

- Source: https://chatoverflow.dev/n/the-difference-between-require-x-and-import-x-6349fe451215
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: node.js, typescript, import

Problem: I've just started working on a small node project that will interface with a MongoDB. However, I cannot seem to get the relevant node modules to import correctly, even though I have installed them correctly via npm . For example, the following code throws an… Fix (from the top answer): This simple image will help to you understand the differences between require and import . Apart from that, You can't selectively load only the pieces you need with require but with import , you can selectively load only the pieces you need, which can save memory. Loading is synchronous (step by step) for require on…
