我实际上只是重复了一本书中的代码,但它不会因为某种原因而工作。这是它自己的代码。这很简单nodejs在调用createServer时抛出错误
var express = require('express')
var app = express.createServer();
app.get('/', function(req, res){
res.send('Welcome')
})
app.listen(8000)
当我安装快递。我得到这个屏幕,我认为一切正常
C:\>npm install express
npm http GET https://registry.npmjs.org/express
npm http 304 https://registry.npmjs.org/express
npm http GET https://registry.npmjs.org/type-is
npm http GET https://registry.npmjs.org/accepts
npm http GET https://registry.npmjs.org/buffer-crc32
npm http GET https://registry.npmjs.org/cookie
npm http GET https://registry.npmjs.org/parseurl
npm http GET https://registry.npmjs.org/range-parser
npm http GET https://registry.npmjs.org/cookie-signature
npm http GET https://registry.npmjs.org/escape-html
npm http GET https://registry.npmjs.org/serve-static
npm http GET https://registry.npmjs.org/send
npm http GET https://registry.npmjs.org/utils-merge
npm http GET https://registry.npmjs.org/methods
npm http GET https://registry.npmjs.org/qs
npm http GET https://registry.npmjs.org/path-to-regexp
npm http GET https://registry.npmjs.org/merge-descriptors
npm http GET https://registry.npmjs.org/fresh
npm http GET https://registry.npmjs.org/debug
npm http 304 https://registry.npmjs.org/cookie
npm http 304 https://registry.npmjs.org/parseurl
npm http 304 https://registry.npmjs.org/accepts
npm http 304 https://registry.npmjs.org/type-is
npm http 304 https://registry.npmjs.org/cookie-signature
npm http 304 https://registry.npmjs.org/buffer-crc32
npm http 304 https://registry.npmjs.org/range-parser
npm http 304 https://registry.npmjs.org/send
npm http 304 https://registry.npmjs.org/utils-merge
npm http 304 https://registry.npmjs.org/serve-static
npm http 304 https://registry.npmjs.org/escape-html
npm http 304 https://registry.npmjs.org/qs
npm http 304 https://registry.npmjs.org/fresh
npm http 304 https://registry.npmjs.org/methods
npm http 304 https://registry.npmjs.org/debug
npm http 304 https://registry.npmjs.org/path-to-regexp
npm http 304 https://registry.npmjs.org/merge-descriptors
npm http GET https://registry.npmjs.org/mime
npm http GET https://registry.npmjs.org/negotiator
npm http GET https://registry.npmjs.org/mime
npm http 304 https://registry.npmjs.org/mime
npm http 304 https://registry.npmjs.org/negotiator
npm http 304 https://registry.npmjs.org/mime
[email protected] node_modules\express
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected])
└── [email protected] ([email protected], [email protected])
当我尝试运行它。我收到错误。好像createServer抛出错误 因为它没有定义什么
C:\Users\User\Dropbox\Personal Documents\Staj node\expresstry>node expresstry.js
C:\Users\Sinan\Dropbox\Personal Documents\Staj node\expresstry\expresstry.js:7
var app = express.createServer();
^
TypeError: Object function createApplication() {
var app = function(req, res, next) {
app.handle(req, res, next);
};
mixin(app, proto);
mixin(app, EventEmitter.prototype);
app.request = { __proto__: req, app: app };
app.response = { __proto__: res, app: app };
app.init();
return app;
} has no method 'createServer'
at Object.<anonymous> (C:\Users\Sinan\Dropbox\Personal Documents\Staj node\t
witter\twitterbuild.js:7:19)
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:906:3
感谢
非常感谢。我应该检查在快递网站的文件,这是我的坏 – sinanspd
@sinanspd不是你的错。几周前,我在尝试在node.js中创建博客上的帖子时遇到了同样的问题。这项技术如此迅速地发展,以至于大多数情况都会立即过时。 – alandarev