Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to install new nodejs modules to expressjs project?

Currently I am working on online yaml code editor. I use expressjs framework for it. I want to install yamljs module to it. How do I install it? Because following code line cause to an error.

var YAML = require('yamljs');

This is the code segment

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');

This is the error

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)

I use webstorm for coding. I have installed yamljs module using

npm install yamljs
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.
like image 403
TharinduKetipe Avatar asked Mar 07 '26 21:03

TharinduKetipe


1 Answers

could you provide more information like the error text?

Have you tried

npm install yamljs

to make the module accessible to the node environment?

like image 123
Andreas Avatar answered Mar 10 '26 16:03

Andreas