如何在expressjs项目中安装新的nodejs模块?

时间:2015-06-12 19:08:32

标签: node.js express yaml

目前我正在使用在线yaml代码编辑器。我使用expressjs框架。我想安装yamljs模块。我该如何安装?因为下面的代码行会导致错误。

var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');


var routes = require('./routes/index');
var users = require('./routes/users');

var YAML = require('yamljs');

var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

这是代码段

Error: Cannot find module 'yamljs'
    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> (/home/tharindu/Documents/projects/Group project2/CuubezFinal/app.js:12:12)
    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)

这是错误

npm install yamljs

我使用webstorm进行编码。我已经使用

安装了yamljs模块

&#13;
&#13;
{{1}}
&#13;
&#13;
&#13; 如果我从ubuntu终端手动运行我的代码,这个库就完全可以使用了。但是当我运行expressjs项目时,它会给出上述错误。

2 个答案:

答案 0 :(得分:1)

您能提供更多信息,例如错误文本吗?

你试过吗

&#13;
&#13;
npm install yamljs
&#13;
&#13;
&#13;

使模块可以访问节点环境吗?

答案 1 :(得分:0)

This library is perfectly using if I run my code manually from the ubuntu terminal. But When I run the expressjs project, It gives above error.

Make sure your node_modules folder is available in the same or a more outer directory than the folder of your executing script.