Avoid using relative paths on require()

前端 未结 2 1779
情话喂你
情话喂你 2021-01-26 06:57

I\'m new with NodeJs, my project is growing and i dont want make relative imports, i want imports like these installed from npm.

I have the following directory structure

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-26 07:29

    This topic is extensively discussed here. My conclusion is mostly:

    1. The idea of putting tests in a separate directory is ineffective. Put tests right alongside the main code: app/users/user.js and app/users/user.test.js.
    2. I create a symlink at node_modules/app that points to ../app so I can require('app/users'); from anywhere in the code base.

提交回复
热议问题