Dheeraj
Dheeraj

Reputation: 556

Unable to run Express.js server

I when running the below code, i am getting error. I have attached the error trace and also the express.js server code below:

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

The code:

'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");

Upvotes: 0

Views: 98

Answers (1)

sam100rav
sam100rav

Reputation: 3783

Which version of express you are using? In express4.x, app.configure() method is removed. Consult this github wiki for migrating from express3.x to express4.x.

Upvotes: 1

Related Questions