2016-10-27 8 views
0

app.localsを使用すると定義されません。私は設定変数としてapp.localを使用しています。どのように私は聞いて(PORT)の内側にそれを使うのですミドルウェア/ルータの外部でapp.locals変数を使用する方法

app.js

app.locals = { 
    socket_io_host: 'http://localhost:3001', 
    socket_io_port: "3001", 
}; 

ルート/ index.js

var express = require('express'); 
var router = express.Router(); 
var server = require('http').Server(express).listen(app.locals.socket_io_port); 
var io = require('socket.io')(server); 

console.log("["+app.locals.socket_io_port+"]"); 

router.get('/', function(req, res, next) { 
    res.render('index', { title: 'Express',point1: point1,point2: point2 }); 
}); 

答えて

0

あなたがそれを必要とする必要があります。

app.jsを:

module.exports = { 
 
    socket_io_host: 'http://localhost:3001', 
 
    socket_io_port: "3001", 
 
}

index.js:

// put as the first line 
 
var app = require('./app');

関連する問題