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.

emrece
  • 109
  • 1
  • 2
  • 8
  • checked in `package.json` for installed dependencies? – kgangadhar Nov 16 '17 at 11:48
  • Hi ı checked now `{ "name": "reddit-node-mysql", "description": "A demo of how to use Express and MySQL together", "author": "Clarence Leung ", "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": {} }` – emrece Nov 16 '17 at 11:50
  • [edit] your post instead of adding info in comments pls – Suraj Rao Nov 16 '17 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`. – kgangadhar Nov 16 '17 at 12:05
  • Yes i express is outdated . – Himanshu sharma Nov 16 '17 at 12:07

1 Answers1

7

You are using outdated express ,

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

npm install --save express

Michal
  • 459
  • 2
  • 7
  • 25
Himanshu sharma
  • 7,487
  • 4
  • 42
  • 75
  • 1
    The `save` flag is [not needed anymore](https://stackoverflow.com/a/36023013/1705829) with `npm install` because it is the default. – Timo Feb 16 '22 at 10:50