在Node.js中找不到模块 [英] Cannot find module in Nodejs

查看:86
本文介绍了在Node.js中找不到模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

module.js:340
    throw err;
          ^
Error: Cannot find module './models/todo'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (C:\Users\Basel\Desktop\Todo List\routes\api.js:1:74)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)

C:\Users\Basel\Desktop\Todo List>

为什么该应用程序无法启动?我已经尝试了全局npm安装.

Why this application won't start up? I've already tried a global npm install.

推荐答案

./models/todo中,句点表示节点将在与api.js所在的 same 文件夹中查找,看起来像对于\Todo List\routes\models\todo.js.这不是从应用程序的根目录开始的.为此,您需要两个时间来升级一个级别,并指定应用程序路径:

In ./models/todo, the period indicates that node will look in the same folder that api.js is in, which would look for \Todo List\routes\models\todo.js. This does not start from the root of the application. To require this, you'll need to us two periods to jump up a level, and specify the app path as well:

var todo = require('../app/models/todo');

这篇关于在Node.js中找不到模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆