Node.js project naming conventions for files & folders

后端 未结 7 1662
清酒与你
清酒与你 2020-12-04 04:41

What are the naming conventions for files and folders in a large Node.js project?

Should I capitalize, camelCase, or under-score?

Ie. is this considered vali

7条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-04 05:18

    There are no conventions. There are some logical structure.

    The only one thing that I can say: Never use camelCase file and directory names. Why? It works but on Mac and Windows there are no different between someAction and some action. I met this problem, and not once. I require'd a file like this:

    var isHidden = require('./lib/isHidden');
    

    But sadly I created a file with full of lowercase: lib/ishidden.js. It worked for me on mac. It worked fine on mac of my co-worker. Tests run without errors. After deploy we got a huge error:

    Error: Cannot find module './lib/isHidden'
    

    Oh yeah. It's a linux box. So camelCase directory structure could be dangerous. It's enough for a colleague who is developing on Windows or Mac.

    So use underscore (_) or dash (-) separator if you need.

提交回复
热议问题