# Benefit of using Hugo modules over node modules

**URL:** <https://discourse.gohugo.io/t/benefit-of-using-hugo-modules-over-node-modules/36968>\
**Category:** support\
**Tags:** modules\
**Created:** [February 4, 2022, 12:26pm UTC](https://discourse.gohugo.io/t/benefit-of-using-hugo-modules-over-node-modules/36968 "2022-02-04T12:26:34Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![pitifi9191](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@pitifi9191](https://discourse.gohugo.io/u/pitifi9191)\
**Post date:** [February 4, 2022, 12:26pm UTC](https://discourse.gohugo.io/t/benefit-of-using-hugo-modules-over-node-modules/36968/1 "2022-02-04T12:26:34Z")

</div>

Hi there,

Why should one use Hugo module over the traditional way of node module?

Are there any added benefits when working in Hugo. I can import git repositories etc but just a comparison to the traditional way what are the benefits of Hugo modules vs node modules in Hugo.

* * *

I find alot about how to use it but cant understand why should I use it instead of traditional node module

thanks

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [February 4, 2022, 1:24pm UTC](https://discourse.gohugo.io/t/benefit-of-using-hugo-modules-over-node-modules/36968/2 "2022-02-04T13:24:06Z")

</div>

> [@pitifi9191](#):
>
> Why should one use Hugo module over the traditional way of node module?

For me the list is long (and longer than this, probably):

1. I don’t like NPM, so I like to avoid it whenever I can. It’s plenty of examples where their current dependency scheme breaks or does unexpected things (example: [Dev corrupts NPM libs 'colors' and 'faker' breaking thousands of apps](https://www.bleepingcomputer.com/news/security/dev-corrupts-npm-libs-colors-and-faker-breaking-thousands-of-apps/))
2. NPM only supports modules published to a NPM registry (you can not depend on a repo/folder on, say GitHub).
3. A little related to 1, but Go Module’s Minimal Version Selection makes a lot more sense to me than the NPM way of doing it. Also related is Go Module’s built-in security which I consider superior to NPM.
4. You get a much better Hugo integration; configure your dependencies and mount folders etc. inside config.toml. List your dependencies (command line and in the templates).
5. You can vendor Hugo Modules and get a project that can be run without network (I guess you can do similar by committing node\_modules to Git, but …)
6. … To be continued. I will add some later when I get some time.

---

<div class="post-metadata">

**Author:** ![pitifi9191](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@pitifi9191](https://discourse.gohugo.io/u/pitifi9191)\
**Post date:** [February 4, 2022, 1:30pm UTC](https://discourse.gohugo.io/t/benefit-of-using-hugo-modules-over-node-modules/36968/3 "2022-02-04T13:30:08Z")

</div>

thanks @bep for taking the time

I realise some benefits but wasn’t sure of how exactly it is better than the node modules. if you can please share the rest it will be really helpful to me and other beginners to understand and compare the benefits and why we should let go the method we normally use.

looking forward to the rest of the benefits of Hugo modules

thanks again

---

<div class="post-metadata">

**Author:** ![pitifi9191](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@pitifi9191](https://discourse.gohugo.io/u/pitifi9191)\
**Post date:** [February 4, 2022, 2:57pm UTC](https://discourse.gohugo.io/t/benefit-of-using-hugo-modules-over-node-modules/36968/4 "2022-02-04T14:57:32Z")

</div>

> [@bep](#):
>
> where their current dependency scheme breaks or does unexpected things

point 1 noted the security against when someone goes mental and intentionally introduce code which break functionality 4.4 million users of color.js alone.

1 main benefit is higher control and security of my project against npm breaks

---

<div class="post-metadata">

**Author:** ![pitifi9191](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@pitifi9191](https://discourse.gohugo.io/u/pitifi9191)\
**Post date:** [February 4, 2022, 3:00pm UTC](https://discourse.gohugo.io/t/benefit-of-using-hugo-modules-over-node-modules/36968/5 "2022-02-04T15:00:02Z")

</div>

> [@bep](#):
>
> NPM only supports modules published to a NPM registry (you can not depend on a repo/folder on, say GitHub).

this is really great in situation where I am waiting for more than an year for the version to be released on npm

2nd main benefit I can quickly add the latest version without having to wait months and years for npm release

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [February 4, 2022, 3:17pm UTC](https://discourse.gohugo.io/t/benefit-of-using-hugo-modules-over-node-modules/36968/6 "2022-02-04T15:17:20Z")

</div>

> [@pitifi9191](#):
>
> this is really great in situation where I am waiting for more than an year for the version to be released on npm

Yea, but the main reason I think this is valuable (and probably the most valuable thing) is that it broadens the “dependency definition”.

To me, an NPM dependency is “code” (aka JavaScript, CSS)

But an Hugo Module is that, too, but it’s also content, images etc.

I have no clue how to publish something to the NPM registry, and I don’t care to learn. Being able to just depend on a GitHub project has tremendous value for me; it’s what I use for everything and I certainly do not want to do this double bookkeeping/releases with NPM …

But NPM is very much the defactor standard for many things, so there are situations where you don’t get around it in Hugo … But I try. I have been toying with the idea of creating this “Hugo Module NPM Adapter” …

Also, not being able (or wanting to) pull in JS dependencies from NPM does make you think twice before adding some tiny little library for some string manipulation – often it’s the best thing to just write that function yourself.

---

<div class="post-metadata">

**Author:** ![pitifi9191](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@pitifi9191](https://discourse.gohugo.io/u/pitifi9191)\
**Post date:** [February 4, 2022, 4:21pm UTC](https://discourse.gohugo.io/t/benefit-of-using-hugo-modules-over-node-modules/36968/7 "2022-02-04T16:21:39Z")

</div>

> [@bep](#):
>
> But an Hugo Module is that, too, but it’s also content, images etc.

point noted, I have to do more demo work to see how it work for me.

> [@bep](#):
>
> I have no clue how to publish something to the NPM registry, and I don’t care to learn. Being able to just depend on a GitHub project has tremendous value for me; it’s what I use for everything and I certainly do not want to do this double bookkeeping/releases with NPM …

I suppose this might be the one reason “double work” for many outdated npm packages. this is really revolutionary for me coming from nextjs as there are many outdated packages which I can’t do anything about but wait for npm release or write manually.

I see now with Hugo module how easily I can add the updated version directly from GitHub in my Hugo project. I try with the [v5 of photoswipe](https://github.com/dimsemenov/PhotoSwipe/tree/v5-beta) which is still in beta 😂 not something I will be doing anytime soon with traditional method.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [February 4, 2022, 5:42pm UTC](https://discourse.gohugo.io/t/benefit-of-using-hugo-modules-over-node-modules/36968/8 "2022-02-04T17:42:09Z")

</div>

To be fair, one can use `npm` with both public and private repositories, regardless of whether they contain code or content.

Feel free to try it with this test repository:

```auto
npm install https://github.com/jmooring/hugo-content

```

Then add this to your site config:

```auto
[[module.mounts]]
source = 'content'
target = 'content'
[[module.mounts]]
source = 'node_modules/hugo-content'
target = 'content'

```

The source repository needs a package.json file, created with `npm init -y`.

---

<div class="post-metadata">

**Author:** ![pitifi9191](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@pitifi9191](https://discourse.gohugo.io/u/pitifi9191)\
**Post date:** [February 5, 2022, 11:05am UTC](https://discourse.gohugo.io/t/benefit-of-using-hugo-modules-over-node-modules/36968/9 "2022-02-05T11:05:55Z")

</div>

Dear @jmooring thanks for sharing this info

I read about this in [Hugo docs](https://gohugo.io/hugo-pipes/js#include-dependencies-in-packagejson--node_modules) but I was wondering since Hugo modules does the same thing(according to my beginner knowledge) why it exist and learn more about in which ways it is better then the traditional method.

Since I am migrating some nextjs projects to Hugo I am also trying to get rid of the node/nextjs/npm way of things because what I realise with Hugo is the ease and minimal exported files and folders comparing to nextjs static export here is an example of default static export.

| | Nextjs | Hugo |
| --- | --- | --- |
| 1 | \_next/jqkr…/ | categoreis/index.xml |
| 2 | \_next/static/chunks/pages/\_app-9c…js | tags/index.xml |
| 3 | \_next/static/chunks/pages/\_error-22…js | index.xml |
| 4 | \_next/static/chunks/pages/\_index-3b…js | sitemap.xml |
| 5 | \_next/static/chunks/framework-6e…js | |
| 6 | \_next/static/chunks/main-101…js | |
| 7 | \_next/static/chunks/polyfills-5c…js | |
| 8 | \_next/static/chunks/webpack-69b…js | |
| 9 | \_next/static/css/27d…css | |
| 10 | \_next/static/css/149…css | |
| 11 | \_next/static/jqkr…/\_buildManifest.js | |
| 12 | \_next/static/jqkr…/\_middlewareManifest.js | |
| 13 | \_next/static/jqkr…/\_ssgManifest.js | |
| 14 | \_next/404.html | |
| 15 | \_next/favicon.ico | |
| 16 | \_next/index.html | |
| 17 | \_next/vercel.svg | |

> **A side note**
>
> - in nextjs I have to get rid of import img before doing static export as otherwise it gives error
> - nextjs image optimisation is not available in statics export
> - in Hugo I can use `webp q80` for basic optimisation in static export.
> - by applying a simple `disableKinds = ["taxonomy", "taxonomyTerm", "category", "sitemap"]` I can reduce the exported files to only 1 in Hugo (I think I can also get rid of index.xml but I haven’t tried this feature yet)

So since I am Hugo beginner instead of doing things the traditional way I will give the Hugo way of things try to see the full benefit of it. The only thing I struggle with is Hugo module comparison to the traditional method. if there was a page with Hugo module vs bla bla that will paint the full picture for beginners like me.

Thanks for taking the time

---

<div class="post-metadata">

**Author:** ![pitifi9191](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@pitifi9191](https://discourse.gohugo.io/u/pitifi9191)\
**Post date:** [March 23, 2022, 7:35pm UTC](https://discourse.gohugo.io/t/benefit-of-using-hugo-modules-over-node-modules/36968/10 "2022-03-23T19:35:47Z")

</div>

After almost two months of utilizing Hugo modules, there is only one thing I dislike about it: when I launch `hugo` or `hugo server`, existing modules are auto-downloaded. The automated downloading then displays JS faults, but those errors disappear after running `hugo mod clean`.

When compared to Npm packages, it appears that the user has little control over Hugo modules. With Npm developer decides on when to update packages, doesn’t seems to be the case with Hugo modules.

I hope it will be useful to anyone who is learning Hugo in the same way that I was two months ago.

Thanks

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [March 23, 2022, 8:11pm UTC](https://discourse.gohugo.io/t/benefit-of-using-hugo-modules-over-node-modules/36968/11 "2022-03-23T20:11:18Z")

</div>

> [@pitifi9191](#):
>
> When compared to Npm packages, it appears that the user has little control over Hugo modules. With Npm developer decides on when to update packages, doesn’t seems to be the case with Hugo modules.

I would argue it’s the other way, but eye is in the beholder.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [March 24, 2022, 4:20pm UTC](https://discourse.gohugo.io/t/benefit-of-using-hugo-modules-over-node-modules/36968/12 "2022-03-24T16:20:27Z")

</div>

Split this topic on March 24, 2022, 4:20pm UTC

A post was split to a new topic: [Problem with Hugo modules](https://discourse.gohugo.io/t/problem-with-hugo-modules/37837)
