Hacker News new | ask | show | jobs
by blondin 2574 days ago
that's some beautiful javascript code and great project structure here. got me thinking about a few things: 1. is the "index.js" in subfolders a nodejs thing? 2. does that turn subfolders into modules? 3. can you write and run that kind of javascript without nodejs?
1 comments

1. The "index.js" thing is due to how module resolution is handled with CommonJS and ES modules. If you have a file at "./lib/index.js", then you can omit the "index.js" and just write "require('./lib')" from another file.

2. Not exactly. In JS, every file with an "import" or "export" statement somewhere is its own module.

3. You can write code like this for the browser. Most browsers support ES modules now. However, you do need a bundler tool like Webpack if your code depends on other node modules.