0

I am following this previously asked question but am receiving this error:

usera@usera-VirtualBox:~/Desktop/test/sample$ nodejs smallNode.js /home/usera/Desktop/test/sample/smallNode.js:3 var app = express(); ^ TypeError: object is not a function at Object.<anonymous> (/home/usera/Desktop/test/sample/smallNode.js:3:11) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Function.Module.runMain (module.js:497:10) at startup (node.js:119:16) at node.js:902:3

What am I missing?

Server side code:

var express = require('express');
var bodyParser = require('body-parser');
var app     = express();

//Note that in version 4 of express, express.bodyParser() was
//deprecated in favor of a separate 'body-parser' module.
app.use(bodyParser.urlencoded({ extended: true })); 

//app.use(express.bodyParser());

app.post('/myaction', function(req, res) {
  res.send('You sent the name "' + req.body.name + '".');
});

app.listen(8080, function() {
  console.log('Server running at http://127.0.0.1:8080/');
});

Here are the results from running npm install. It looks like there is a warning during the install process so maybe that's the issue...

usera@usera-VirtualBox:~/Desktop/test/sample$ npm install express
npm http GET https://registry.npmjs.org/express/2.5.8
npm http 304 https://registry.npmjs.org/express/2.5.8
npm WARN engine express@2.5.8: wanted: {"node":">= 0.4.1 < 0.7.0"} (current: {"node":"v0.10.25","npm":"1.3.10"})
npm http GET https://registry.npmjs.org/connect
npm http GET https://registry.npmjs.org/mime/1.2.4
npm http GET https://registry.npmjs.org/qs
npm http GET https://registry.npmjs.org/mkdirp/0.3.0
npm http 304 https://registry.npmjs.org/connect
npm http 304 https://registry.npmjs.org/qs
npm http 304 https://registry.npmjs.org/mime/1.2.4
npm http 304 https://registry.npmjs.org/mkdirp/0.3.0
npm http GET https://registry.npmjs.org/formidable
npm http 304 https://registry.npmjs.org/formidable
express@2.5.8 node_modules/express
├── qs@0.4.2
├── mime@1.2.4
├── mkdirp@0.3.0
└── connect@1.9.2 (formidable@1.0.17)
Community
  • 1
  • 1
JRR
  • 327
  • 3
  • 16

1 Answers1

0

Thats an old version of express... you should at least use v3, or better v4 to have it export a function. – migg

JRR
  • 327
  • 3
  • 16