MaximeHeckel
MaximeHeckel

Reputation: 448

Error: Cannot find module 'html' with /:id

I recently had a problem with express while rendering html pages. I have the following organization for my app :

app/ server.js views/ index.html dashboard.html containers/ show.html ......

In server.js I declared the following route :

app.configure(function(){
   app.use(express.static(path.join(__dirname,'/views')));
});

app.get('/containers/:id',function(req,res){
   console.log("Inspect container");
   res.render('/views/containers/show.html');
});

And in dashboard.html I have a link that looks like this :

<a href="/containers/'+data[i].Id+'">Test</a>

But when I try to access the following link i get this error :

Error: Cannot find module 'html' 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 new View (/root/HarborJS/node_modules/express/lib/view.js:43:49) at Function.app.render (/root/HarborJS/node_modules/express/lib/application.js:488:12) at ServerResponse.res.render (/root/HarborJS/node_modules/express/lib/response.js:759:7) at io.sockets.on.socket.on.exec.user (/root/HarborJS/server.js:32:7) at callbacks (/root/HarborJS/node_modules/express/lib/router/index.js:164:37) at param (/root/HarborJS/node_modules/express/lib/router/index.js:138:11)

I really don't know what to do at this point. Tell me if I'm doing something wrong.

Upvotes: 2

Views: 4945

Answers (1)

loganfsmyth
loganfsmyth

Reputation: 161467

res.render is used for dynamically generating the page HTML server-side for each request. You have passed it the path to an HTML file, but HTML is not a templating language, so it is throwing an error.

If you do not have any template logic in show.html then you should just send the file back without using a template engine, e.g.

res.sendfile(__dirname + '/views/containers/show.html');

If you do have things that need to be rendered server-side, then you should pick a templating engine, of which there are many, and then rename the files to have a template extension.

Upvotes: 6

Related Questions