1

I'm interested to know if there is a way for passing custom license urls in NPM's package.json files.

I tried:

{
  "license": {"name": "foo", "url": "http://example.com" }
}

It seems that this format is now deprecated:

// Not valid metadata
{ "license" :
  { "type" : "ISC"
  , "url" : "http://opensource.org/licenses/ISC"
  }
}

Is there another way to pass the license url in package.json?

Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474
  • It does not seem so. I've actually talked to some npm folks and they do not seem open to the idea of supporting a `url`. Instead, they want you to use the license (type) only and put your copyright information in your readme. – mscdex Jun 02 '15 at 12:43
  • @mscdex But then the license link will be a 404: [example](http://opensource.org/licenses/testtest). – Ionică Bizău Jun 02 '15 at 15:45
  • What I mean is that you will have to use `"license": "identifier"` where `identifier` is one from [here](https://spdx.org/licenses/). – mscdex Jun 02 '15 at 15:48
  • @mscdex Exactly, but my license is not listed there. :) – Ionică Bizău Jun 02 '15 at 15:54
  • I think you're out of luck then, unless you are able to convince the people at spdx.org to add the license or you can convince the npm folks to support custom licenses (which I did not have luck with). – mscdex Jun 02 '15 at 15:57

3 Answers3

3

It seems there is another/new way to do it. Recently my npm packages started to complain when I was using:

{ "license" : "LicenseRef-LICENSE" }

I'm now rather using the notation as documented in the npm docs:

If you are using a license that hasn't been assigned an SPDX identifier, or if you are using a custom license, use the following valid SPDX expression:

{ "license" : "SEE LICENSE IN <filename>" }` 

Then include a file named filename at the top level of the package.

MrIsaacs
  • 87
  • 5
Jakob Hohlfeld
  • 1,503
  • 1
  • 17
  • 31
1

On the same page that was linked is the following:

If you are using a license that hasn't been assigned an SPDX identifier, or if you are using a custom license, use the following valid SPDX expression:

{ "license" : "LicenseRef-LICENSE" }

Then include a LICENSE file at the top level of the package.

In the same vein, you chould simply specify your URL in your LICENSE and/or copy/paste your existing license to that location.

Jonathan Bender
  • 1,911
  • 4
  • 22
  • 39
  • Whoups, how didn't I see that? But... does this work for you? I [tested it out](https://www.npmjs.com/package/license-test-pack) -- created a `package.json` and a `LICENSE` file. Still, I'm redirected to [this page](http://opensource.org/licenses/LicenseRef-LICENSE) when I click it. – Ionică Bizău Jun 22 '15 at 17:36
  • If I had to guess, npmjs.com is just hardcoding to a relative path under the assumption that if it's valid there'll be a page there, which obviously isn't the case. This is valid according to their own docs (and will validate), however, it might be worth mentioning to them. – Jonathan Bender Jun 22 '15 at 18:24
0
{
  "name": "fcc-learn-npm-package-json",
  "version": "1.0",
  "dependencies": {
    "express": "^4.14.0"
  },
  "main": "server.js",
  "scripts": {
    "start": "node server.js"
  },
  "engines": {
    "node": "8.11.2"
  },
  "repository": {
    "type": "git",
    "url": "https://idontknow/todo.git"
  },
  "author": "Ganesh",
  "description": "This is an example project",
  "keywords": [
    "freecodecamp",
    "example"
  ],
  "license": "MIT",
}
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 25 '21 at 05:56