Node.js nodejs requirejs检查是否在节点中运行

Node.js nodejs requirejs检查是否在节点中运行,node.js,requirejs,Node.js,Requirejs,我正在使用一个示例创建一个简单的模块。在节点中使用requirejs,我想检查im是否在节点中运行,但似乎无法让它显示我在运行。这是我的密码: define('defTemp', [], function() { "use strict"; var self = {}; self.checkA = function() { if(typeof exports !== 'undefined' && this.exports !=

我正在使用一个示例创建一个简单的模块。在节点中使用requirejs,我想检查im是否在节点中运行,但似乎无法让它显示我在运行。这是我的密码:

define('defTemp', [], 
function()
{
    "use strict";

    var self = {};

    self.checkA = function()
    {
        if(typeof exports !== 'undefined' && this.exports !== exports)
            console.log('a');
        if (typeof module !== 'undefined' && module.exports) 
            console.log('b');
        if (typeof exports === 'object')
            console.log('c');
        if(typeof define === 'function' && define.amd)
            console.log('d');

    }       

    return self;
});
并从app.js运行:

var requirejs = require('requirejs');

console.log(__dirname);

requirejs.config(
{
    baseUrl: __dirname,
    paths:
    {
        'defTemp' : 'template/defTemp'
    },
    nodeRequire: require
});


requirejs(['defTemp'], 
function(defTemp)
{
    defTemp.checkA();

});
控制台(a、b、c)中除了d之外没有显示其他内容,这是有意义的,因为我使用的是requirejs。但我也在节点中运行。我希望在方法checkA()中能够告诉我是否在节点中运行,这样我就可以在浏览器中运行时执行不同的操作。有什么帮助吗

更新日期:2014年4月12日
Leonid Beschastny的建议是检查窗口,而不是工作良好的窗口

我建议检查
窗口

if (typeof window === 'undefined') {
  // node.js
else {
  // browser
}
对于
模块

if (typeof module !== 'undefined') {
  // node.js
else {
  // browser
}

检查窗口实际上是个好主意。谢谢