id
stringlengths
16
145
text
stringlengths
1
179k
title
stringclasses
1 value
Providers/requiringmodulesinno_28_0.txt
~/learn-node $ node > module.paths [ '/Users/samer/learn-node/repl/node_modules', '/Users/samer/learn-node/node_modules', '/Users/samer/node_modules', '/Users/node_modules', '/node_modules', '/Users/samer/.node_modules', '/Users/samer/.node_libraries', '/usr/local/Cellar/node/7.7.1/lib/node' ]
Providers/requiringmodulesinno_133_0.txt
exports = { id: 42 }; // This will not work.
Providers/const_129_0.txt
* [ ` var ` ](/en-US/docs/Web/JavaScript/Reference/Statements/var) * [ ` let ` ](/en-US/docs/Web/JavaScript/Reference/Statements/let) * [ Constants in the JavaScript Guide ](/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#constants)
Providers/requiringmodulesinno_180_0.txt
Those are two different usages. We need a way to determine if the file is being run as a stand-alone script or if it is being required by other scripts.
Providers/howtousethejavascrip_5_0.txt
![Joel Olawanle](https://www.freecodecamp.org/news/content/images/size/w60/2022/06/1654890413623.jpg) [ Joel Olawanle ](/news/author/joel-olawanle/)
Providers/requiringmodulesinno_206_0.txt
ADVERTISEMENT
Providers/requiringmodulesinno_150_0.txt
Moreover, since every module gets wrapped in a function, we can actually access that function’s arguments with the ` arguments ` keyword:
Providers/const_153_0.txt
]: Non-standard. Check cross-browser support before using.
Providers/const_51_0.txt
All browser compatibility updates at a glance
Providers/indexjs_85_0.txt
You can’t perform that action at this time.
Providers/const_84_0.txt
` nameN `
Providers/howtousethejavascrip_38_0.txt
You can access over 180 of my articles by [ visiting my website ](https://joelolawanle.com/contents) . You can also use the search field to see if I've written a specific article.
Providers/requiringmodulesinno_199_0.txt
Learning React or Node? Checkout my books:
Providers/requiringmodulesinno_68_0.txt
More importantly now, what happens if the ` lib/util ` module required the main ` index ` module? This is where we get into what’s known as the circular modular dependency, which is allowed in Node.
Providers/const_118_0.txt
Still, it's possible to push items into the array and thus mutate it.
Providers/howtousethejavascrip_1_0.txt
[ ![freeCodeCamp.org](https://cdn.freecodecamp.org/platform/universal/fcc_primary.svg) ](https://www.freecodecamp.org/news/)
Providers/howtousethejavascrip_4_0.txt
# JavaScript Require – How to Use the require() Function in JS
Providers/Providers_52_0.txt
class TransactionReceipt inherits from [ TransactionReceiptParams ](/v6/api/providers/formatting/#TransactionReceiptParams) A TransactionReceipt includes additional information about a transaction that is only available after it has been mined.
Providers/indexjs_54_0.txt
## History
Providers/Providers_20_0.txt
PROPERTIES io/ethers.js/blob/main/src.ts/providers/plugins-network.ts#Lundefined) feeDataNetworkPlugin . feeDataFunc ⇒ ( provider: [ Provider ](/v6/api/providers/#Provider) ) => Promise< [ FeeData ](/v6/api/providers/#FeeData) > read-only The fee data function provided to the constructor.
Providers/indexjs_32_0.txt
## Use saved searches to filter your results more quickly
Providers/const_80_0.txt
The **` const ` ** declaration declares block-scoped local variables. The value of a constant can't be changed through reassignment using the [ assignment operator ](/en- US/docs/Web/JavaScript/Reference/Operators/Assignment) , but if a constant is an [ object ](/en-US/docs/Web/JavaScript/Data_structures#objects) , its...
Providers/const_49_0.txt
](/en-US/plus/ai-help)
Providers/indexjs_3_0.txt
[ ](https://github.com/)
Providers/indexjs_63_0.txt
## File metadata and controls
Providers/const_95_0.txt
Many style guides (including [ MDN's ](/en- US/docs/MDN/Writing_guidelines/Writing_style_guide/Code_style_guide/JavaScript#variable_declarations) ) recommend using ` const ` over [ ` let ` ](/en- US/docs/Web/JavaScript/Reference/Statements/let) whenever a variable is not reassigned in its scope. This makes the intent c...
Providers/requiringmodulesinno_92_0.txt
Note how in this delayed ` console.log ` output both ` lib/util.js ` and ` index.js ` are fully loaded.
Providers/requiringmodulesinno_17_0.txt
mkdir ~/learn-node && cd ~/learn-node
Providers/Providers_48_0.txt
PROPERTIES io/ethers.js/blob/main/src.ts/providers/provider.ts#L1897) provider . provider ⇒ this The provider iteself. This is part of the necessary API for executing a contract, as it provides a common property on any [ ContractRunner ](/v6/api/providers/#ContractRunner) that can be used to access the read-only...
Providers/requiringmodulesinno_210_0.txt
ADVERTISEMENT
Providers/const_55_0.txt
](/en-US/plus/docs/features/overview)
Providers/requiringmodulesinno_66_0.txt
~/learn-node $ node index.js In index Module { id: '.', exports: {}, parent: null, filename: '/Users/samer/learn-node/index.js', loaded: false, children: [], paths: [ ... ] } In util Module { id: '/Users/samer/learn-node/lib/util.js', exports: {}, parent: Module { id: '.', exports: {}, parent: null, filename: '/Users/s...
Providers/requiringmodulesinno_137_0.txt
In a browser, when we declare a variable in a script like this:
Providers/requiringmodulesinno_163_0.txt
require = function() {
Providers/const_71_1.txt
[ TypeError ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
Providers/howtousethejavascrip_19_0.txt
The ` require() ` function is straightforward to use and understand, as all you have to do is assign the function to a variable.
Providers/const_74_0.txt
14. [ for ](/en-US/docs/Web/JavaScript/Reference/Statements/for) 15. [ for await...of ](/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of) 16. [ for...in ](/en-US/docs/Web/JavaScript/Reference/Statements/for...in) 17. [ for...of ](/en-US/docs/Web/JavaScript/Reference/Statements/for...of) 18. [ function ](/...
Providers/indexjs_55_0.txt
[ History ](/SuhailTechInfo/Suhail-Md/commits/main/index.js)
Providers/requiringmodulesinno_45_0.txt
~/learn-node $ echo "console.log('Found again.');" > node_modules/find-me/index.js
Providers/requiringmodulesinno_33_0.txt
~/learn-node $ mkdir node_modules
Providers/indexjs_14_0.txt
Resources
Providers/const_36_0.txt
Learn to style content using CSS
Providers/const_13_0.txt
](/en-US/docs/Web/JavaScript)
Providers/const_69_0.txt
* Try it * Syntax * Description * Examples * Specifications * Browser compatibility * See also
Providers/Providers_36_0.txt
METHODS io/ethers.js/blob/main/src.ts/providers/provider.ts#L841) log . getBlock ( ) ⇒ Promise< [ Block ](/v6/api/providers/#Block) > Returns the block that this log occurred in. io/ethers.js/blob/main/src.ts/providers/provider.ts#L850) log . getTransaction ( ) ⇒ Promise< [ TransactionResponse ](/v6/api/pr...
Providers/const_112_0.txt
const MY_OBJECT = { key: "value" }; MY_OBJECT = { OTHER_KEY: "value" };
Providers/const_91_0.txt
if (true) const a = 1; // SyntaxError: Lexical declaration cannot appear in a single-statement context
Providers/const_66_0.txt
* [ Español ](/es/docs/Web/JavaScript/Reference/Statements/const) * [ Français ](/fr/docs/Web/JavaScript/Reference/Statements/const) * [ 日本語 ](/ja/docs/Web/JavaScript/Reference/Statements/const) * [ 한국어 ](/ko/docs/Web/JavaScript/Reference/Statements/const) * [ Português (do Brasil) ](/pt-BR/docs/We...
Providers/const_97_0.txt
## Examples
Providers/const_102_0.txt
// Re-assigning to a constant variable throws an error MY_FAV = 20; // TypeError: Assignment to constant variable
Providers/const_116_0.txt
The same applies to arrays. Assigning a new array to the variable throws an error "Assignment to constant variable".
Providers/requiringmodulesinno_96_0.txt
exports.data = data; // Will not work. });
Providers/Providers_6_0.txt
class BrowserProvider A BrowserProvider is intended to wrap an injected provider which adheres to the [ EIP-1193 ](https://eips.ethereum.org/EIPS/eip-1193) standard, which most (if not all) currently do.
Providers/const_34_0.txt
](/en-US/docs/Learn/HTML)
Providers/indexjs_69_0.txt
const { VERSION } = require ( __dirname \+ '/config' )
Providers/indexjs_30_0.txt
Cancel Submit feedback
Providers/requiringmodulesinno_110_0.txt
#### JSON and C/C++ addons
Providers/indexjs_41_0.txt
[ SuhailTechInfo ](/SuhailTechInfo) / **[ Suhail-Md ](/SuhailTechInfo/Suhail- Md) ** Public
Providers/Providers_8_0.txt
METHODS io/ethers.js/blob/main/src.ts/providers/provider-browser.ts#L94) browserProvider . getRpcError ( payload : [ JsonRpcPayload ](/v6/api/providers/jsonrpc/#JsonRpcPayload) , error : [ JsonRpcError ](/v6/api/providers/jsonrpc/#JsonRpcError) ) ⇒ Error Resolves to true if the provider manages the a...
Providers/const_82_0.txt
## Syntax
Providers/Providers_17_0.txt
CREATING INSTANCES Creates a new FeeData for gasPrice , maxFeePerGas and maxPriorityFeePerGas .
Providers/requiringmodulesinno_89_0.txt
// In index.js setImmediate(() => { console.log('The index.js module object is now loaded!', module) });
Providers/const_12_0.txt
General-purpose scripting language
Providers/requiringmodulesinno_67_0.txt
Note how the main ` index ` module ` (id: '.') ` is now listed as the parent for the ` lib/util ` module. However, the ` lib/util ` module was not listed as a child of the ` index ` module. Instead, we have the ` [Circular] ` value there because this is a circular reference. If Node prints the ` lib/util ` module objec...
Providers/Providers_51_1.txt
pedDataDomain ](/v6/api/hashing/#TypedDataDomain) , types : Record< string , Array< [ TypedDataField ](/v6/api/hashing/#TypedDataField) > > , value : Record< string , any > ) ⇒ Promise< string > Signs the [ EIP-712 ](https://eips.ethereum.org/EIPS/eip-712) typed data.
Providers/Providers_50_0.txt
PROPERTIES The [ Provider ](/v6/api/providers/#Provider) attached to this Signer (if any).
Providers/requiringmodulesinno_55_0.txt
This can be used, for example, to check whether an optional package is installed or not and only use it when it’s available.
Providers/requiringmodulesinno_108_0.txt
We required ` module2 ` before ` module1 ` was fully loaded, and since ` module2 ` required ` module1 ` while it wasn’t fully loaded, what we get from the ` exports ` object at that point are all the properties exported prior to the circular dependency. Only the ` a ` property was reported because both ` b ` and ` c ` ...
Providers/Providers_45_0.txt
CREATING INSTANCES io/ethers.js/blob/main/src.ts/providers/signer-noncemanager.ts#L29) new NonceManager ( signer : [ Signer ](/v6/api/providers/#Signer) ) Creates a new NonceManager to manage signer .
Providers/requiringmodulesinno_213_0.txt
ADVERTISEMENT
Providers/const_23_0.txt
* [ Web Technology
Providers/requiringmodulesinno_162_0.txt
For example, maybe for testing purposes, we want every ` require ` call to be mocked by default and just return a fake object instead of the required module exports object. This simple reassignment of require will do the trick:
Providers/howtousethejavascrip_22_0.txt
Suppose you have a CommonJS module that exports a function ` *getFullName* ` as seen below:
Providers/const_150_0.txt
Deprecated
Providers/const_93_0.txt
const FOO; // SyntaxError: Missing initializer in const declaration
Providers/Providers_3_0.txt
PROPERTIES The base fee per gas that all transactions in this block were charged. This adjusts after each block, depending on how congested the network is. The total amount of blob gas consumed by the transactions within the block. See [ EIP-4844 ](https://eips.ethereum.org/EIPS/eip-4844) . The [ Date ](https:...
Providers/const_61_0.txt
Theme
Providers/indexjs_70_0.txt
const start = async ( ) => {
Providers/requiringmodulesinno_171_0.txt
The function takes a numeric argument ` size ` and a string argument ` header ` and it prints that header in a frame of stars controlled by the size we specify.
Providers/howtousethejavascrip_58_0.txt
[ About ](https://www.freecodecamp.org/news/about/) [ Alumni Network ](https://www.linkedin.com/school/free-code-camp/people/) [ Open Source ](https://github.com/freeCodeCamp/) [ Shop ](https://www.freecodecamp.org/news/shop/) [ Support ](https://www.freecodecamp.org/news/support/) [ Sponsors ](https://www.freecodecamp...
Providers/howtousethejavascrip_12_0.txt
CommonJS and EMCAScript modules (ES modules) now work perfectly in Node.js. The major difference between them is their execution.
Providers/requiringmodulesinno_121_0.txt
The Node documentation site has a [ sample addon file ](https://nodejs.org/api/addons.html#addons_hello_world) which is written in C++. It’s a simple module that exposes a ` hello() ` function and the hello function outputs “world.”
Providers/const_35_0.txt
* [ CSS
Providers/howtousethejavascrip_6_0.txt
![JavaScript Require – How to Use the require\(\) Function in JS](https://www.freecodecamp.org/news/content/images/size/w2000/2023/01/cover- template--11-.png)
Providers/requiringmodulesinno_10_0.txt
You can think of the ` require ` module as the command and the ` module ` module as the organizer of all required modules.
Providers/const_0_0.txt
* Skip to main content * Skip to search * Skip to select language
Providers/requiringmodulesinno_31_0.txt
~/learn-node $ node > require('find-me') Error: Cannot find module 'find-me' at Function.Module._resolveFilename (module.js:470:15) at Function.Module._load (module.js:418:25) at Module.require (module.js:498:17) at require (internal/module.js:20:19) at repl:1:1 at ContextifyScript.Script.runInThisContext (vm.js:23:33)...
Providers/howtousethejavascrip_43_0.txt
![Joel Olawanle](https://www.freecodecamp.org/news/content/images/size/w60/2022/06/1654890413623.jpg) [ Joel Olawanle ](/news/author/joel-olawanle/)
Providers/requiringmodulesinno_7_0.txt
> **Update:** This article is now part of my book “Node.js Beyond The Basics”. > > Read the updated version of this content and more about Node at [ > **jscomplete.com/node-beyond-basics** ](https://jscomplete.com/g/node- > modules) .
Providers/indexjs_52_0.txt
Blame
Providers/requiringmodulesinno_14_0.txt
* **Resolving** : To find the absolute path of the file. * **Loading** : To determine the type of the file content. * **Wrapping** : To give the file its private scope. This is what makes both the ` require ` and ` module ` objects local to every file we require. * **Evaluating** : This is what the VM eventually does w...
Providers/requiringmodulesinno_186_0.txt
if (require.main === module) { printInFrame(process.argv[2], process.argv[3]); } else { module.exports = printInFrame; }
Providers/const_147_0.txt
[ Mozilla logo ](https://www.mozilla.org/)
Providers/const_3_0.txt
Web technology reference for developers
Providers/requiringmodulesinno_136_0.txt
Let me ask one more question before explaining Node’s wrapping process.
Providers/Providers_33_0.txt
CREATING INSTANCES io/ethers.js/blob/main/src.ts/providers/provider-ipcsocket.ts#L40) new IpcSocketProvider ( path : string , network ?: [ Networkish ](/v6/api/providers/#Networkish) , options ?: [ JsonRpcApiProviderOptions ](/v6/api/providers/jsonrpc/#JsonRpcApiProviderOptions) )
Providers/requiringmodulesinno_75_0.txt
~/learn-node $ node index.js In index Module { id: '.', exports: { id: 'index' }, loaded: false, ... } In util Module { id: '/Users/samer/learn-node/lib/util.js', exports: { id: 'lib/util' }, parent: Module { id: '.', exports: { id: 'index' }, loaded: false, ... }, loaded: false, ... }
Providers/howtousethejavascrip_21_0.txt
const varName = require(locationName);
Providers/const_64_0.txt
Article Actions
Providers/const_41_0.txt
* [ Accessibility