Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

Thomas Maw
Thomas Maw
2,111 Points

Can't get Node.js and Express working on the Code Racer Project.

Video: http://teamtreehouse.com/library/code-racer/how-to-build-a-server-with-express

I followed the videos and did everything Jim said but I couldn't get past this error after setting up my views:

TypeError: Property 'engine' of object #<View> is not a function at View.render (/NODE/USocial/node_modules/express/lib/view.js:75:8) at Function.app.render (/NODE/USocial/node_modules/express/lib/application.js:501:10) at ServerResponse.res.render (/NODE/USocial/node_modules/express/lib/response.js:719:7) at /NODE/USocial/server.js:5:7 at callbacks (/NODE/USocial/node_modules/express/lib/router/index.js:160:37) at param (/NODE/USocial/node_modules/express/lib/router/index.js:134:11) at pass (/NODE/USocial/node_modules/express/lib/router/index.js:141:5) at Router._dispatch (/NODE/USocial/node_modules/express/lib/router/index.js:169:5) at Object.router (/NODE/USocial/node_modules/express/lib/router/index.js:32:10) at next (/NODE/USocial/node_modules/express/node_modules/connect/lib/proto.js:190:15)

I decided to delete coffeescript and changed the server.coffee file to server.js and converted it back to javascript to see if that was the issue, but i keep getting the same error. This is the contents of my server.js file:

var express = require('express'); var app = express();

app.get('/', function(req, res){ res.render('index.eco',{layout:false}); });

app.listen(3000);

Please Help :) Thomas

12 Answers

Jim Hoskins
STAFF
Jim Hoskins
Treehouse Guest Teacher

Express has undergone a lot of changes since this code was made, it may be you need to do a "require('eco');" at the top of the file to make sure express knows about that format.

You also need to make sure eco is specified in the dependencies section of the package.json file

I'm having the same problem. I have required eco and it is in my dependencies, but I keep getting the following error:

TypeError: Property 'engine' of object #<View> is not a function

Seems like there's a missing bit of configuration or something?

So.. after a bit of digging around I found this article on migrating from express 2 to express 3 which says that the signature which templating languages must export in order to work with express has changed. So, guessed that that was the problem. I found out about consolidate.js which is a library designed to solve this problem. The readme has an express example, and I managed to solve the problem by adding consolidate to the dependencies:

 "dependencies": {
      "coffee-script": "1.5.0",
      "express": "3.x",
      "eco": "*",
      "consolidate": "*"
  }

(run npm install after this - thanks Richard) and then requiring consolidate and using it to set app.engine, such that my code looks like this:

require 'coffee-script'
express = require 'express'
cons = require 'consolidate'

app = express()
app.engine 'eco', cons.eco

app.get '/', (req, res) ->
  res.render 'index.eco', layout: false

app.listen(3000)
console.log "Server is listening"

The CodeRacer express script now works as expected

Thanks a lot :D

Thank you!

I tried this and it got me passed that same error you had but it doesn't render using eco. I'v attached a screenshot of my server.coffee

http://cl.ly/image/1R2g093W2t0x

Richard Terrell
Richard Terrell
3,728 Points

Thanks Hannah. That totally worked.

@otherPeopleReadingThis - don't forget to run "npm install" after updating your JSON file. After doing that Hannah's code worked exactly as written above.

@Sebastien Barrau,

Did you ever get it to work? Did you try with exactly the same code as in the snippet I provided? If not.. what error did you get?

@Sebastien Barrau,

Did you ever get it to work? Did you try with exactly the same code as in the snippet I provided? If not.. what error did you get?

Richard Terrell
Richard Terrell
3,728 Points

Another solution to this problem is to just use an older version of express. For example in the package.JSON file you just replace: "express": "*"

with: "express": "2.5.7"

This made all of my problems go away.

Yes that will make all the problems go away except that it's a really old version of express and this is the old way of doing things.

Using the latest express and consolidate to make template systems which use a non-standard interface compatible is the current way of doing things :)

Tet Chan
PLUS
Tet Chan
Courses Plus Student 1,669 Points

But it didn't render layout.eco as a default view....anyone overcome it ?

You're right indeed. I'm looking for a solution right now.

Tet Chan
Tet Chan
Courses Plus Student 1,669 Points

This is caused by Express 3 update. I change to use ejs and require('express-partials'); I changed the code by following,

app.set('view engine','ejs'); app.use(partials());

I've decided to use .ect template. It's 4 times faster than .eco and syntax compatible, I highly suggest it: https://github.com/baryshev/ect