Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个/custom_modules/db.js并且正在尝试,require但/routes/users.js我不确定如何做到这一点。
/custom_modules/db.js
require
/routes/users.js
你./用来表示你所在的本地目录,并../返回一个目录。所以:
./
../
require('./../custom_modules/db');
应该只使用../ 示例:
var db = require('../custom_modules/db.js');
只需插入前导/即可给出绝对路径:
/
require('/custom_modules/db.jpg');
解析模块路径的规则在模块文档中有详细说明。