2015-06-17 4 views
0

При запуске приведенного ниже кода я получаю сообщение об ошибке. Я приложил трассировку ошибки, а также код сервера express.js ниже:Невозможно запустить сервер Express.js

app.configure(function() { 
    ^
TypeError: undefined is not a function 
    at Object.<anonymous> (C:\node\dashboard\server\index.js:17:5) 
    at Module._compile (module.js:460:26) 
    at Object.Module._extensions..js (module.js:478:10) 
    at Module.load (module.js:355:32) 
    at Function.Module._load (module.js:310:12) 
    at Function.Module.runMain (module.js:501:10) 
    at startup (node.js:129:16) 
    at node.js:814:3 

Код:

'use strict'; 

var express = require("express"), 
    contacts = require("./db_interactions"), 
    version = require('./package.json').version, 
    program = require('commander'), 
    app = express(); 

/* cli */ 
program 
    .version(version) 
    .option('-p, --port <n>', 'port number', parseInt) 
    .parse(process.argv); 

var port = program.port || 4000; 

app.configure(function() { 
    app.use(express.bodyParser()); 
}); 

app.use(function(req, res, next) { 
    /* Website you wish to allow to connect */ 
    res.setHeader('Access-Control-Allow-Origin', req.headers.origin || '*'); 
    /* Request methods you wish to allow */ 
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE'); 
    /* Request headers you wish to allow */ 
    res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type'); 

    /* Set to true if you need the website to include cookies in the requests sent */ 
    /* to the API (e.g. in case you use sessions) */ 
    res.setHeader('Access-Control-Allow-Credentials', true); 

    /* Pass to next layer of middleware */ 
    if ('OPTIONS' === req.method) { 
    res.send(200); 
    } else { 
    next(); 
    } 
}); 

app.get("/:appName/users", contacts.index); 
app.delete('/:appName/deletereleases/:id', contacts.deleteReleases); 

app.listen(port, "127.0.0.1"); 

ответ

1

Какую версию экспресс вы используете? В express4.x метод app.configure() удален. Проконсультируйтесь с this github wiki для перехода на express3.x на express4.x.

+0

Привет Сэм, я на экспрессе 3.x только мои зависимостей "зависимость": { "Мангуст": "~ 3.8.8", "Экспресс": "~ 3.0.6", "underscore": "~ 1.6.0", "async": "~ 0.8.0", "node-uuid": "~ 1.4.1", "перезагрузка": "~ 0.1.0", "fs-extra": "~ 0.9.1", "moment": "~ 2.6.0", "commander": "^ 2.2.0" } Заранее спасибо – Dheeraj

+0

Попробуйте использовать app.use вне приложения .configure. – sam100rav

+0

@raman вы можете запустить 'npm ls express', чтобы убедиться, что Express 3.x установлен? – robertklep

Смежные вопросы