DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 970,177 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
jebuscraisp
jebuscraisp

Posted on

What is the difference between packages and modules?

Top comments (5)

Collapse
 
rhymes profile image
rhymes • Edited on

In the context of which language? They usually mean slightly different things depending on the context

Collapse
 
ichsanputr profile image
Muhammad Ichsan • Edited on

CONTEXT IN JS

in my opinion, package is all thing in npmjs.com, what you can install for your project

if the package have been installed in your project, i call that module. Because i can import all code from (package installed) to my project.

so package == not yet installed
and module === have been installed, and ready for import to your project

Collapse
 
jebuscraisp profile image
jebuscraisp Author

In the context of javascript

Collapse
 
rhymes profile image
rhymes

Ok then packages is not exactly a JavaScript concept, it's just the name that we give to the unit of distribution through npm/yarn.

Libraries or software that gets "packaged", distributed, indexed in a common website (the npm repository) and then can be installed from a client. npm or yarn are the package managers, the piece of software that you add as a dependency in your application is called a package.

JavaScript modules are instead a recent addition to the standard. They allow you to organize code in files and import them from one another, encapsulated in a namespace (instead of having everything global like in the old days). So you might have a module that contains common behavior and import it from multiple files. Es:

// time.js
export function now() {}
export function yesterday() {}
Enter fullscreen mode Exit fullscreen mode

and then in your app you can import:

import { now, yesterday } from "./time.js"
console.log(now())
Enter fullscreen mode Exit fullscreen mode

I think this is the simplest explanation I can make, if you want to know more, this is a complete overview on how JavaScript modules work: developers.google.com/web/fundamen...

Thread Thread
 
jebuscraisp profile image
jebuscraisp Author

Very nice. Thank you

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.