Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

node.js express app jade templates not rendering

node.js express app jade templates not rendering

Problem

I'm trying to create a cluster server with socket.io and express.js I'm following various tutorials on the internet as well on youtube. What I have at the moment is this code in my app.js:

var cluster = require('cluster');

if (cluster.isMaster) {

    var cpuCount = require('os').cpus().length;
    var workers = [];   

    for (var i = 0; i 

When I go to http://localhost:3000/ I get the response:

Welcome to socket.io.

In my previous test scripts I didnt have this issue and my jade templates were being rendered fine. Could someone explain why is this happenning?

Furthermore in my routes directory I have the script: index.js with this code:

/*
 * GET home page.
 */

exports.index = function(req, res){
  res.render('index', { title: 'Express' });
};

Finally in my views folder I have layout.jade with:

doctype 5
html
  head
    title= title
    link(rel='stylesheet', href='/stylesheets/style.css')
  body
    block content

and index.jade with:

extends layout

block content
  h1= title
  p Welcome to #{title}
Problem courtesy of: Syd

Solution

It seems that the problem was in the final lines of app.js

this fixes the issue:

var server = http.createServer(app);
var io = require('socket.io').listen(server);
server.listen(app.get('port'));

Sorry for any inconvenience.

Solution courtesy of: Syd

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

node.js express app jade templates not rendering

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×