6

Hi I'm trying to use jade and express together. But it is giving me TypeError. I made npm init, npm install express -save and then node app.js. But it is giving me same error "TypeError: express is not a function"

// Module dependencies
var express = require('express')
  , nib = require('nib')
  , mysql = require('mysql')

 var app = express();

var app = module.exports = app.createServer();


app.set('views', __dirname + '/views')
app.set('view engine', 'jade')
app.use(express.logger('dev'))

And package.json :

{
  "name": "reddit-node-mysql",
  "description": "A demo of how to use Express and MySQL together",
  "author": "Clarence Leung <github@clarle>",
  "version": "0.0.1",
  "private": true,
  "dependencies": {
    "express": "^2.5.11",
    "mysql": "~2.0",
    "nib": "^1.1.2",
    "jade": "^1.0.4"
  },
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "license": "ISC",
  "devDependencies": {}
}

Solution My modules' version outdated so they can't installed well. I updated version of them, now working.

5
  • checked in package.json for installed dependencies? Commented Nov 16, 2017 at 11:48
  • Hi ı checked now { "name": "reddit-node-mysql", "description": "A demo of how to use Express and MySQL together", "author": "Clarence Leung <github@clarle>", "version": "0.0.1", "private": true, "dependencies": { "express": "^2.5.11", "mysql": "~2.0", "nib": "^1.1.2", "jade": "^1.0.4" }, "main": "app.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "license": "ISC", "devDependencies": {} } Commented Nov 16, 2017 at 11:50
  • edit your post instead of adding info in comments pls Commented Nov 16, 2017 at 11:57
  • 1
    I tried it locally, I think the problem is with the version of express u are using, change "express": "^2.5.11" to "express": "latest" and do npm install. Commented Nov 16, 2017 at 12:05
  • Yes i express is outdated . Commented Nov 16, 2017 at 12:07

1 Answer 1

7

You are using outdated express ,

Remove
"express": "^2.5.11", from package json and run

npm install --save express

Sign up to request clarification or add additional context in comments.

1 Comment

The save flag is not needed anymore with npm install because it is the default.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.