节点js app.configure不是一个函数

任何人都可以告诉这个代码中有什么问题。我已经安装了所有必要的模块。当我运行这个脚本时,它告诉app.configure不是一个函数。 如果我缺less任何东西,请告诉我。

var express = require('express') , app = express() , server = require('http').createServer(app) , io = require("socket.io").listen(server) , npid = require("npid") , uuid = require('node-uuid') , Room = require('./room.js') , _ = require('underscore')._; app.configure(function() { app.set('port', process.env.OPENSHIFT_NODEJS_PORT || 3000); app.set('ipaddr', process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1"); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(express.static(__dirname + '/public')); app.use('/components', express.static(__dirname + '/components')); app.use('/js', express.static(__dirname + '/js')); app.use('/icons', express.static(__dirname + '/icons')); app.set('views', __dirname + '/views'); app.engine('html', require('ejs').renderFile); /* Store process-id (as priviledged user) */ try { npid.create('/var/run/advanced-chat.pid', true); } catch (err) { console.log(err); //process.exit(1); } }); 

       

网上收集的解决方案 "节点js app.configure不是一个函数"

app.configure()不再是Express 4的一部分。

看到这里: https : //github.com/expressjs/express/wiki/Migrating-from-3.x-to-4.x

您不再需要使用app.configure ,而是可以直接configuration您的快速应用程序。

 var express = require('express') , app = express() , server = require('http').createServer(app) , io = require("socket.io").listen(server) , npid = require("npid") , uuid = require('node-uuid') , Room = require('./room.js') , _ = require('underscore')._; app.set('port', process.env.OPENSHIFT_NODEJS_PORT || 3000); app.set('ipaddr', process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1"); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(express.static(__dirname + '/public')); app.use('/components', express.static(__dirname + '/components')); app.use('/js', express.static(__dirname + '/js')); app.use('/icons', express.static(__dirname + '/icons')); app.set('views', __dirname + '/views'); app.engine('html', require('ejs').renderFile); /* Store process-id (as priviledged user) */ try { npid.create('/var/run/advanced-chat.pid', true); } catch (err) { console.log(err); //process.exit(1); } 

如果您需要环境特定的configuration,请使用if块:

 if(process.env.NODE_ENV === 'production') { app.set('port', 80); // additional prod environemtn configuration }