【问题标题】:html node.js form inputhtml node.js 表单输入
【发布时间】:2016-05-17 05:18:27
【问题描述】:

我正在关注此previously asked question,但收到此错误:

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

我错过了什么?

服务器端代码:

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/');
});

这是运行 npm install 的结果。在安装过程中似乎有一个警告,所以也许这就是问题所在......

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)

【问题讨论】:

  • 在我测试时工作正常。
  • npm install express了吗?
  • 是的,已编辑原始帖子以包含来自npm install express的结果
  • 那是 express 的旧版本...你至少应该使用 v3,或者更好的 v4 来让它导出一个函数。
  • 我猜你的package.json 版本不对。

标签: html node.js


【解决方案1】:

那是 express 的旧版本...您至少应该使用 v3 或更好的 v4 来让它导出功能。 – 米格

【讨论】:

    猜你喜欢
    • 2011-12-10
    • 1970-01-01
    • 2016-08-04
    • 2017-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-19
    • 2019-04-26
    相关资源
    最近更新 更多