NodeJs Using ExpressJs : TypeError: string is not a function at Function.app.render

Kris Hollenbeck

I just started learning Node and I am trying to build a web application using Node and Express. And I have the following code in my app.js file, with the following directory structure.

Directory Structure:

app
   assets
   controller
   model
   view
      index.jade
global
node_modules
app.js
package.json

-js-

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

app.configure(function() {
  app.set('view', __dirname + '/app/view');
  app.set('view engine', 'jade');
  app.use(app.router);
});

app.get('/', function(req, res){
    res.render('index', {title: 'express'});
});

app.listen(3000);
console.log('Listening on port 3000');

After running the command node app and going to localhost:3000. I get the following error. I am assuming it doesn't like the string on this line -> res.render('index', {title: 'express'});. However from everything I have found on Google this seems right. So I must be missing something else.

ERROR MESSAGE:

TypeError: string is not a function at Function.app.render (C:\myapp\express\node_modules\express\lib\application.js:488:12) at ServerResponse.res.render (C:\myapp\express\node_modules\express\lib\response.js:803:7) at C:\myapp\express\app.js:19:6 at callbacks (C:\myapp\express\node_modules\express\lib\router\index.js:164:37) at param (C:\myapp\express\node_modules\express\lib\router\index.js:138:11) at pass (C:\myapp\express\node_modules\express\lib\router\index.js:145:5) at Router._dispatch (C:\myapp\express\node_modules\express\lib\router\index.js:173:5) at Object.router (C:\myapp\express\node_modules\express\lib\router\index.js:33:10) at next (C:\myapp\express\node_modules\express\node_modules\connect\lib\proto.js:190:15) at Object.expressInit [as handle] (C:\myapp\express\node_modules\express\lib\middleware.js:30:5)

Peter Lyons

I think this is just a typo/mistake setting 'view' (singular) instead of 'views' (plural). Check out this example. I think the express application object has both 'view' and 'views' settings but they mean different things.

https://github.com/visionmedia/express/blob/master/examples/jade/index.js

Here's your fix to be clear:

  app.set('views', __dirname + '/app/view');

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

expressjs - using middleware function

From Java

NodeJs : TypeError: require(...) is not a function

From Dev

Nodejs TypeError: undefined is not a function

From Java

React Context: TypeError: render is not a function

From Dev

React error: TypeError: render is not a function

From Dev

How do you call a second "external" function using Nodejs, Expressjs and bluebird

From Dev

TypeError: Callback is not a function with asyncJS in nodeJS

From Dev

TypeError: object is not a function+nodeJS

From Dev

TypeError: undefined is not a function at pipe in nodejs

From Dev

TypeError: Callback is not a function with asyncJS in nodeJS

From Dev

TypeError: .find(...) is not a function nodejs mongoose

From Dev

NodeJS: TypeError: Buffer is not a function (but it's a function!)

From Dev

Error using `should` to test nodeJS app ( undefined is not a function )

From Dev

Using RedisStore in nodejs / expressjs

From Dev

Error in render function: “TypeError: Cannot read property of undefined”, using Vuex and Vue Router

From Dev

Call function from string in nodejs

From Dev

TypeError: string is not a function Angularjs, PHP

From Dev

Javascript - Uncaught TypeError:string is not a function

From Dev

Backbone Uncaught TypeError: string is not a function

From Dev

How to invoke app.js function from html page in expressjs?

From Dev

middleware function error in expressjs

From Dev

'TypeError: undefined is not a function' using Protractor

From Dev

Express render function with callback return string and not HTML

From Dev

Express render function with callback return string and not HTML

From Dev

"TypeError: req.flash is not a function" using passport with nodejs, username and password auth

From Dev

I'm trying to send emails using sendgrid in nodejs.But am getting "TypeError: object is not a function" error

From Dev

Using eval on a function string

From Dev

Using string as parameter for function

From Dev

How to do the comparison using if inside the render function

Related Related

  1. 1

    expressjs - using middleware function

  2. 2

    NodeJs : TypeError: require(...) is not a function

  3. 3

    Nodejs TypeError: undefined is not a function

  4. 4

    React Context: TypeError: render is not a function

  5. 5

    React error: TypeError: render is not a function

  6. 6

    How do you call a second "external" function using Nodejs, Expressjs and bluebird

  7. 7

    TypeError: Callback is not a function with asyncJS in nodeJS

  8. 8

    TypeError: object is not a function+nodeJS

  9. 9

    TypeError: undefined is not a function at pipe in nodejs

  10. 10

    TypeError: Callback is not a function with asyncJS in nodeJS

  11. 11

    TypeError: .find(...) is not a function nodejs mongoose

  12. 12

    NodeJS: TypeError: Buffer is not a function (but it's a function!)

  13. 13

    Error using `should` to test nodeJS app ( undefined is not a function )

  14. 14

    Using RedisStore in nodejs / expressjs

  15. 15

    Error in render function: “TypeError: Cannot read property of undefined”, using Vuex and Vue Router

  16. 16

    Call function from string in nodejs

  17. 17

    TypeError: string is not a function Angularjs, PHP

  18. 18

    Javascript - Uncaught TypeError:string is not a function

  19. 19

    Backbone Uncaught TypeError: string is not a function

  20. 20

    How to invoke app.js function from html page in expressjs?

  21. 21

    middleware function error in expressjs

  22. 22

    'TypeError: undefined is not a function' using Protractor

  23. 23

    Express render function with callback return string and not HTML

  24. 24

    Express render function with callback return string and not HTML

  25. 25

    "TypeError: req.flash is not a function" using passport with nodejs, username and password auth

  26. 26

    I'm trying to send emails using sendgrid in nodejs.But am getting "TypeError: object is not a function" error

  27. 27

    Using eval on a function string

  28. 28

    Using string as parameter for function

  29. 29

    How to do the comparison using if inside the render function

HotTag

Archive