DEV Community

[Comment from a deleted post]
Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt • Edited

Depending on what kind of NPM package you are looking for.

If you just want to create a library, then export functions properly, and remove main function. In package.json, you use main field.

If you want to create a CLI script, and header #! to the script, and bin the script name in package.json in bin field.

Either way, you should write a good documentation on why you would want to share it, and how to use it.

Collapse
 
syn profile image
norman

I followed tutorials but they dont work. I put the header #! into it and add the bin. I dont know how to test if it works without publishing it, so i published it. It doesnt work and gives this error.

npm ERR! code ENOENT
npm ERR! syscall chmod
npm ERR! path C:\Users\namar\AppData\Roaming\npm\node_modules\subscrapetest\node subscrape.js
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, chmod 'C:\Users\namar\AppData\Roaming\npm\node_modules\subscrapetest\node subscrape.js'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\namar\AppData\Roaming\npm-cache\_logs\2020-02-13T22_11_56_826Z-debug.log```


Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

You can try npm link first, and run with npx, before publishing it.

About the error, make use package.json is

{
  "bin": {
    "<SCRIPT_NAME>": "subscrape.js"
  }
}

Or

{
  "bin": "subscrape.js"
}