我是node.js和express框架的初学者.我正在关注这些 tutorials. 这是我的代码: var fs = require("fs");var config = JSON.parse(fs.readFileSync(__dirname + "\\config.json"));var host = config.host;var port = config.port;var
这是我的代码:
var fs = require("fs"); var config = JSON.parse(fs.readFileSync(__dirname + "\\config.json")); var host = config.host; var port = config.port; var express = require("express"); var app = express.createServer(); app.get(__dirname + "\\",function(request, response){ response.send("Hello!"); }); app.listen(port,host);
我有这个错误,我无法解决它:
C:\Users\Fabio\Documents\GitHub\NodeJSProjects\ExpressSimpleServer\Server.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\Fabio\Documents\GitHub\NodeJSProjects\ExpressSimpleServer\Server.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:902:3
我正在使用node.js 0.10.26,表达4.0.0和Windows 8
请参阅明确项目的参考.不推荐使用CreateServer.只需执行此操作即可创建服务器并侦听端口 Var app = require(“express”)(); app.listen(3000);