Reputation: 4537
I am totally new to NodeJS and I wonder what's the difference between those two.
For example, in this project (https://github.com/fikriauliya/hipku), we have index.js
and dist/hipku.js
. They are similar except the last line:
module.exports = publicMethods;
vs return publicMethods;
I guess dist/hipku.js
is generated from index.js
? How is it generated and why does it need to be generated?
Upvotes: 2
Views: 2675
Reputation: 2802
It depends on how you want to use this package, in browser or server side.
index.js
is the entry of NPM package. When you do require('hipku')
, actually NodeJS locates the file module node_modules/hipku
and run index.js
ends up with the object adhere to module.exports
Just load dist/hipku.js
into your browser by <script>
, it will register hipku
into your global namespace, then you can use it's API.
Upvotes: 1
Reputation: 1019
Things in the dist folder are usually the product of building from index.js in this case. You'll notice it gets minified, and that folder would eventually be used on production sites. If you look at the package.json file, you'll notice that index.js is the main file, so if you're doing any edits, that would be the place to do so.
Upvotes: 2