require(id)
添加於:v0.1.13
參數
用於導入模塊、JSON
和本地文件。模塊可以從 node_modules
導入。可以使用相對路徑(例如 ./
、 ./foo
、 ./bar/baz
、 ../foo
)導入本地模塊和 JSON 文件,這些路徑將針對
命名的目錄(如果已定義)或當前工作目錄。 POSIX 風格的相對路徑以獨立於操作係統的方式解析,這意味著上麵的示例將在 Windows 上以與在 Unix 係統上相同的方式工作。__dirname
// Importing a local module with a path relative to the `__dirname` or current
// working directory. (On Windows, this would resolve to .\path\myLocalModule.)
const myLocalModule = require('./path/myLocalModule');
// Importing a JSON file:
const jsonData = require('./path/filename.json');
// Importing a module from node_modules or Node.js built-in module:
const crypto = require('node:crypto');
相關用法
- Node.js require.cache用法及代碼示例
- Node.js require.main用法及代碼示例
- Node.js require.extensions用法及代碼示例
- Node.js http2.Http2ServerRequest request.url用法及代碼示例
- Node.js request.socket用法及代碼示例
- Node.js http.ClientRequest request.getHeaders()用法及代碼示例
- Node.js http2.Http2ServerRequest request.headers用法及代碼示例
- Node.js http.ClientRequest request.setHeader(name, value)用法及代碼示例
- Node.js request.writableEnded用法及代碼示例
- Node.js http.ClientRequest request.getHeaderNames()用法及代碼示例
- Node.js http.ClientRequest request.removeHeader(name)用法及代碼示例
- Node.js http.ClientRequest request.getHeader(name)用法及代碼示例
- Node.js http.ClientRequest request.reusedSocket用法及代碼示例
- Node.js http2.Http2ServerRequest request.rawHeaders用法及代碼示例
- Node.js http.ClientRequest request.hasHeader(name)用法及代碼示例
- Node.js http.ClientRequest request.getRawHeaderNames()用法及代碼示例
- Node.js http.ClientRequest request.socket用法及代碼示例
- Node.js http.ServerResponse response.statusCode用法及代碼示例
- Node.js readStream.isRaw用法及代碼示例
- Node.js response.writeContinue()用法及代碼示例
- Node.js http2.Http2ServerResponse response.removeHeader(name)用法及代碼示例
- Node.js response.removeHeader()用法及代碼示例
- Node.js http.ServerResponse response.getHeaderNames()用法及代碼示例
- Node.js http2.Http2ServerResponse response.hasHeader(name)用法及代碼示例
- Node.js http.ServerResponse response.removeHeader(name)用法及代碼示例
注:本文由純淨天空篩選整理自nodejs.org大神的英文原創作品 require(id)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。