nodejs express ejs4.0x 用ejs妫傻腶pp.js没有app.configure,怎么弄

javascript - Express has no method configure error - Stack Overflow
to customize your list.
Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
J it only takes a minute:
I'm trying to get started with the MEAN stack. And I'm following this tutorial:
I have made it until the Test Our Server section. Here
// modules =================================================
var express = require('express');
= express();
var mongoose= require('mongoose');
// configuration ===========================================
// config files
var db = require('./config/db');
var port = process.env.PORT || 8080; // set our port
mongoose.connect(db.url); // connect to our mongoDB database (uncomment after you enter in your own credentials in config/db.js)
app.configure(function() {
app.use(express.static(__dirname + '/public'));
// set the static files location /public/img will be /img for users
app.use(express.logger('dev'));
// log every request to the console
app.use(express.bodyParser());
// have the ability to pull information from html in POST
app.use(express.methodOverride());
// have the ability to simulate DELETE and PUT
// routes ==================================================
require('./app/routes')(app); // configure our routes
// start app ===============================================
app.listen(port);
// startup our app at http://localhost:8080
console.log('Magic happens on port ' + port);
// shoutout to the user
exports = module.exports =
// expose app
When I run
nodemon server.js
I get this error
app.configure(function() {
TypeError: Object function (req, res, next) {
app.handle(req, res, next);
} has no method 'configure'
at Object.&anonymous& (C:\Users\Yuksel\Desktop\node\test\server.js:14:5)
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
5 Mar 17:27:20 - [nodemon] app crashed - waiting for file changes before startin
It simply says app has no method configure(I guess). But when I delete the configure part and run it again, it works.(This mean app has .listen method, so it is an express object.)
I have tried with both node and nodemon. And I couldn't figure it out. Thank you for your time.
3,36711438
The configure method has been removed from express as of version 4.0.0 (including 4.0.0-rc2). See the changelog at
2,36621227
Tom in his blog post
provides examples of how to convert from using app.configure in express version 3.x to removing it in express version 4.0.
For convenience I added the code example below.
Version 3.x
// all environments
app.configure(function(){
app.set('title', 'Application Title');
// development only
app.configure('development', function(){
app.set('mongodb_uri', 'mongo://localhost/dev');
// production only
app.configure('production', function(){
app.set('mongodb_uri', 'mongo://localhost/prod');
Version 4.0
// all environments
app.set('title', 'Application Title');
// development only
if ('development' == app.get('env')) {
app.set('mongodb_uri', 'mongo://localhost/dev');
// production only
if ('production' == app.get('env')) {
app.set('mongodb_uri', 'mongo://localhost/prod');
6,093114568
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
rev .24712
Stack Overflow works best with JavaScript enabled}

我要回帖

更多关于 nodejs express ejs 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信