Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8886055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:27:53+00:00 2026-06-14T21:27:53+00:00

I am trying to learn node and Express 3 with CoffeeScript. I am using

  • 0

I am trying to learn node and Express 3 with CoffeeScript.
I am using Mocha for tests and am trying to reference the port number:

describe "authentication", ->
  describe "GET /login", ->
    body = null
    before (done) ->
      options =
        uri: "http://localhost:#{app.get('port')}/login"
      request options, (err, response, _body) ->
        body = _body
        done()
    it "has title", ->
      assert.hasTag body, '//head/title', 'Demo app - Login'

I’m using that because it’s also what is used in the app.js file:

require('coffee-script');

var express = require('express')
  , http = require('http')
  , path = require('path');

var app = express();

app.configure(function(){
  app.set('port', process.env.PORT || 3000);
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.set('view options',{layout:false});
  app.use(express.favicon());
  app.use(express.logger('dev'));
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(app.router);
  app.use(express.static(path.join(__dirname, 'public')));
});

app.configure('development', function(){
  app.use(express.errorHandler());
  app.locals.pretty = true;
});

app.configure('test', function(){
  app.set('port', 3001);
});

require('./apps/authentication/routes')(app)

http.createServer(app).listen(app.get('port'), function(){
  console.log("Express server listening on port " + app.get('port'));
});

However, when I run this test, I get the error:

TypeError: Object #<Object> has no method 'get'

Could someone please explain why it won’t work in the test and what I could do as an alternative?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T21:27:56+00:00Added an answer on June 14, 2026 at 9:27 pm

    You are getting confused because you have an app.js file and a variable within that module also called app, but you haven’t actually set things up to expose the app variable as a module export. You could do this:

    var app = exports.app = express();
    

    And then in your test you can have require('../app').app.get('port') (assuming your tests are in a subdirectory. Adjust the relative path as needed). You might want to rename app.js to server.js to be a bit less confusing there.

    However, I suggest a dedicated config.js module that holds this type of configuration data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to learn javascript to work with node.js and obviously don't quite get
I'm still trying to learn node.js + express.js to make something... But after many
I am new to programming and I am trying to learn node.js and CoffeeScript.
I am trying to learn how to use Node, Mongoose, and Mongo by looking
I am trying to write a blog engine for myself with node.js/express/mongodb (also a
I was trying learn lex and yacc using the oreilly book. I tried following
I am new to node.js and I'm just trying to learn how to use
I'm trying to learn Node and have the function: this.logMeIn = function(username,stream) { if
I am trying to send a http request to a neo4j database using node.js.
I am trying to get familiar with using the XDocument API to parse XML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.