node.js - Error: Cannot find module 'res' in server.js -
i'm trying output "hello world" text . i'm using expressjs , using view engine called "ejs" . i'm beginner in nodejs
var express = require("express"); var app = express(); var path = require('path'); var res = require("res"); var port = process.env.port; app.set('view engine'); app.set('views',path.resolve(__dirname,'client','views')); app.get('/',function() { res.render('index.ejs'); }); app.listen(port,function(){ console.log('server running in port '+port); });
here error:
module.js:338 throw err; ^ error: cannot find module 'res' @ function.module._resolvefilename (module.js:336:15) @ function.module._load (module.js:286:25) @ module.require (module.js:365:17) @ require (module.js:384:17) @ object. (/home/ubuntu/workspace/server.js:4:11) @ module._compile (module.js:434:26) @ object.module._extensions..js (module.js:452:10) @ module.load (module.js:355:32) @ function.module._load (module.js:310:12) @ module.runmain [as _ontimeout] (module.js:475:10) process exited code: 1
what problem here?
res
function parameter route handler, it's not module require()
.
try instead:
var express = require("express"); var app = express(); var path = require('path'); var port = process.env.port; app.set('view engine'); app.set('views',path.resolve(__dirname,'client','views')); app.get('/',function(req, res) { res.render('index.ejs'); }); app.listen(port,function(){ console.log('server running in port '+port); });
Comments
Post a Comment