__filename
添加于:v0.0.1
当前模块的文件名。这是当前模块文件的绝对路径,符号链接已解析。
对于主程序,这不一定与命令行中使用的文件名相同。
当前模块的目录名称参见 。__dirname 
例子:
从/Users/mjr 运行node example.js
console.log(__filename);
// Prints: /Users/mjr/example.js
console.log(__dirname);
// Prints: /Users/mjr
给定两个模块: a 和 b ,其中 b 是 a 的依赖项,目录结构为:
/Users/mjr/app/a.js/Users/mjr/app/node_modules/b/b.js
在 b.js 中对 __filename 的引用将返回 /Users/mjr/app/node_modules/b/b.js 而在 a.js 中对 __filename 的引用将返回 /Users/mjr/app/a.js 。
相关用法
- Node.js __dirname用法及代码示例
 - Node.js ServerHttp2Stream http2stream.pushStream(headers[, options], callback)用法及代码示例
 - Node.js http2.Http2ServerRequest request.url用法及代码示例
 - Node.js request.socket用法及代码示例
 - Node.js assert.notEqual(actual, expected[, message])用法及代码示例
 - Node.js tlsSocket.authorized用法及代码示例
 - Node.js zlib.deflateRaw()用法及代码示例
 - Node.js http.IncomingMessage message.rawHeaders用法及代码示例
 - Node.js Console用法及代码示例
 - Node.js GM transparent()用法及代码示例
 - Node.js URL.protocol用法及代码示例
 - Node.js http.Agent.reuseSocket(socket, request)用法及代码示例
 - Node.js fs.filehandle.datasync()用法及代码示例
 - Node.js socket.bind()用法及代码示例
 - Node.js v8.getHeapSpaceStatistics()用法及代码示例
 - Node.js http2session.destroyed用法及代码示例
 - Node.js http.ServerResponse response.statusCode用法及代码示例
 - Node.js Buffer buf.writeBigUInt64BE(value[, offset])用法及代码示例
 - Node.js Http2ServerResponse.finished用法及代码示例
 - Node.js Http2Stream close用法及代码示例
 - Node.js readStream.isRaw用法及代码示例
 - Node.js diffieHellman.getGenerator()用法及代码示例
 - Node.js util.types.isInt16Array(value)用法及代码示例
 - Node.js certificate.verifySpkac(spkac[, encoding])用法及代码示例
 - Node.js util.types.isNativeError(value)用法及代码示例
 
注:本文由纯净天空筛选整理自nodejs.org大神的英文原创作品 __filename。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
