0

node.js アプリケーションを実行すると、次のタイプ エラーが発生します。

/Users/khinester/Sandboxes/zeitgeist/Blade/server.js:5
  application = require("./.app/")();
                                  ^
TypeError: object is not a function
    at Object.<anonymous> (/Users/khinester/Sandboxes/zeitgeist/Blade/server.js:5:35)
    at Object.<anonymous> (/Users/khinester/Sandboxes/zeitgeist/Blade/server.js:21:4)
    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:901:3
DEBUG: Program node server exited with code 8

DEBUG: Starting child process with 'node server'
00:55:26 - compiled src/social.coffee

アプリケーションを次のように構成しました。

☺  tree -L 3 .
.
├── Cakefile
├── README.md
├── server.coffee
├── src
│   ├── config
│   │   ├── config.coffee
│   │   ├── errors.coffee
│   │   ├── i18n.coffee
│   │   ├── models.coffee
│   │   ├── passport.coffee
│   │   └── routes.coffee
│   ├── controllers
│   │   ├── api.coffee
│   │   ├── index.coffee
│   │   ├── login.coffee
│   │   ├── map.coffee
│   │   └── user.coffee
│   ├── index.coffee
│   ├── models
│   │   └── user
│   │       └── user.coffee
│   └── utils
│       ├── dbconnect.coffee
│       ├── emailer.coffee
│       ├── i18n.coffee
│       ├── logger.coffee
│       └── passport.coffee
└── views
    ├── 404.blade
    ├── 500.blade
    ├── footer.blade
    ├── forms
    │   ├── federated-form.blade
    │   ├── login-form.blade
    │   └── registration-form.blade
    ├── header.blade
    ├── index.blade
    └── user
        ├── create.blade
        ├── login.blade
        └── user.blade

私のserver.coffeeは次のとおりです。

application = require("./.app/")()
nowjs = require "now"
port = process.env.PORT or process.env.VMC_APP_PORT or process.env.VCAP_APP_PORT or 3000
server = application.listen(port)
everyone = nowjs.initialize(server)
console.log "Server running at http://127.0.0.1: "+ port  + "\nPress CTRL-C to stop server."

これは次のようにコンパイルされます:

// Generated by CoffeeScript 1.6.2
(function() {
  var application, everyone, nowjs, port, server;

  application = require("./.app/")();

  nowjs = require("now");

  if (!process.env.NODE_ENV) {
    process.env.NODE_ENV = "local";
  }

  port = process.env.PORT || process.env.VMC_APP_PORT || process.env.VCAP_APP_PORT || 3000;

  server = application.listen(port);

  everyone = nowjs.initialize(server);

  console.log("Server running at http://127.0.0.1: " + port + "\nPress CTRL-C to stop server.");

}).call(this);

/app/index.coffee:

#Load external dependencies
express = require("express")
stylus = require("stylus")
mongoose = require("mongoose")
i18next = require "i18next"

#Load local dependencies
models = require("./config/models")
i18n = require("./config/i18n")
config = require("./config/config")
routes = require("./config/routes")

#Load database dependencies
dbconnection = require "./utils/dbconnect"

#Load logger
logger = require "./utils/logger"

# Initialize logger
logger.configure()
logCategory = "APP config"

#  Create Server
app = express()
logger.info "---- App server created ----", logCategory

#Exports
module.exports = ->
  #  Load Mongoose Models
  models app

  # Load i18next config
  i18n app
  # Init i18next
  i18next.init(app.i18n)
  i18next.registerAppHelper(app)
  #  Load Expressjs config
  config app

  #  Load routes config
  routes app

  app

logger.info "---- Modules loaded into namespace ----", logCategory
# Connect to database
dbconnection.init (result) ->
  if result
    logger.info "Database initialized", logCategory

そのため、アプリケーションを実行するたびに TypeError が発生しますが、アプリケーションは実行されます!

私は何が欠けていて、ここで理解していませんか?

アドバイスをいただければ幸いです。

4

1 に答える 1