id
stringlengths
16
145
text
stringlengths
1
179k
title
stringclasses
1 value
Providers/requiringmodulesinno_98_0.txt
Let’s now try to answer the important question about circular dependency in Node: What happens when module 1 requires module 2, and module 2 requires module 1?
Providers/const_107_0.txt
if (MY_FAV === 7) { // This is fine because it's in a new block scope const MY_FAV = 20; console.log(MY_FAV); // 20
Providers/indexjs_67_0.txt
[ Raw ](https://github.com/SuhailTechInfo/Suhail-Md/raw/main/index.js)
Providers/const_119_0.txt
MY_ARRAY.push("A"); // ["A"]
Providers/const_127_0.txt
BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.
Providers/Providers_66_0.txt
PROPERTIES io/ethers.js/blob/main/src.ts/providers/network.ts#Lundefined) network . chainId ⇒ bigint The network chain ID. io/ethers.js/blob/main/src.ts/providers/network.ts#Lundefined) network . name ⇒ string The network common name. This is the canonical name, as networks migh have multiple names. io/ethe...
Providers/howtousethejavascrip_15_0.txt
Node.js, by default, supports the CommonJS module format, which loads modules using the ` require() ` function, and exports them with ` module.exports ` .
Providers/requiringmodulesinno_51_0.txt
~/learn-node $ node > require('find-me'); I rule {} >
Providers/indexjs_84_0.txt
* [ Terms ](https://docs.github.com/site-policy/github-terms/github-terms-of-service) * [ Privacy ](https://docs.github.com/site-policy/privacy-policies/github-privacy-statement) * [ Security ](https://github.com/security) * [ Status ](https://www.githubstatus.com/) * [ Docs ](https://docs.github.com/) * [ Contact ](ht...
Providers/Providers_68_0.txt
METHODS io/ethers.js/blob/main/src.ts/providers/network.ts#L153) network . attachPlugin ( plugin : [ NetworkPlugin ](/v6/api/providers/#NetworkPlugin) ) ⇒ this Attach a new plugin to this Network. The network name must be unique, excluding any fragment. io/ethers.js/blob/main/src.ts/providers/network.ts#L18...
Providers/const_42_0.txt
Learn to make the web accessible to all
Providers/const_110_0.txt
### const in objects and arrays
Providers/requiringmodulesinno_57_0.txt
Besides resolving modules from within the ` node_modules ` directories, we can also place the module anywhere we want and require it with either relative paths ( ` ./ ` and ` ../ ` ) or with absolute paths starting with ` / ` .
Providers/indexjs_47_0.txt
main
Providers/const_70_0.txt
1. [ JavaScript ](/en-US/docs/Web/JavaScript) 2. [ Tutorials ](/en-US/docs/Web/JavaScript/Tutorials) 3. Complete beginners 1. [ JavaScript basics ](/en-US/docs/Learn/Getting_started_with_the_web/JavaScript_basics) 2. [ JavaScript first steps ](/en-US/docs/Learn/JavaScript/First_steps) 3. [ JavaScript building blocks ](...
Providers/requiringmodulesinno_167_0.txt
There is also ` require.main ` which can be helpful to determine if the script is being required or run directly.
Providers/indexjs_61_0.txt
# index.js
Providers/requiringmodulesinno_160_0.txt
#### The require object
Providers/requiringmodulesinno_109_0.txt
Node keeps this really simple. During the loading of a module, it builds the ` exports ` object. You can require the module before it’s done loading and you’ll just get a partial exports object with whatever was defined so far.
Providers/indexjs_8_0.txt
* [ All features ](https://github.com/features) * [ Documentation ](https://docs.github.com) * [ GitHub Skills ](https://skills.github.com) * [ Blog ](https://github.blog)
Providers/requiringmodulesinno_18_0.txt
All the commands in the rest of this article will be run from within ` ~/learn-node ` .
Providers/requiringmodulesinno_114_0.txt
{ "host": "localhost", "port": 8080 }
Providers/const_149_0.txt
Visit [ Mozilla Corporation’s ](https://www.mozilla.org) not-for-profit parent, the [ Mozilla Foundation ](https://foundation.mozilla.org/) . Portions of this content are ©1998– 2024 by individual mozilla.org contributors. Content available under [ a Creative Commons license ](/en- US/docs/MDN/Writing_guideli...
Providers/howtousethejavascrip_49_0.txt
freeCodeCamp is a donor-supported tax-exempt 501(c)(3) charity organization (United States Federal Tax Identification Number: 82-0779546)
Providers/const_15_0.txt
Protocol for transmitting web resources
Providers/const_47_0.txt
* [ AI Help (beta)
Providers/requiringmodulesinno_194_0.txt
The second require will not show the header because of modules’ caching. Node caches the first call and does not load the file on the second call.
Providers/requiringmodulesinno_145_0.txt
All of these arguments get their values when Node executes the wrapper function. ` exports ` is defined as a reference to ` module.exports ` prior to that. ` require ` and ` module ` are both specific to the function to be executed, and ` __filename ` / ` __dirname ` variables will contain the wrapped module’s absolute...
Providers/howtousethejavascrip_0_0.txt
Search Submit your search query
Providers/requiringmodulesinno_77_0.txt
// Add the following line in index.js before the console.log
Providers/requiringmodulesinno_158_0.txt
return module.exports; }
Providers/const_22_0.txt
](/en-US/docs/Mozilla/Add-ons/WebExtensions)
Providers/howtousethejavascrip_50_0.txt
Our mission: to help people learn to code for free. We accomplish this by creating thousands of videos, articles, and interactive coding lessons - all freely available to the public.
Providers/howtousethejavascrip_8_0.txt
Modules are self-contained, making it easy to add, remove, and update functionalities without affecting your entire code because they are decoupled from other pieces of code.
Providers/const_96_0.txt
The list that follows the ` const ` keyword is called a _[ binding ](/en- US/docs/Glossary/Binding) list _ and is separated by commas, where the commas are _not_ [ comma operators ](/en- US/docs/Web/JavaScript/Reference/Operators/Comma_operator) and the ` = ` signs are _not_ [ assignment operators ](/en- US/docs/Web/Ja...
Providers/requiringmodulesinno_63_0.txt
Do the same for an ` index.js ` file, which is what we’ll be executing with the node command. Make this ` index.js ` file require ` lib/util.js ` :
Providers/requiringmodulesinno_182_0.txt
if (require.main === module) { // The file is being executed directly (not with require) }
Providers/indexjs_75_0.txt
await bot . DATABASE . sync ( )
Providers/requiringmodulesinno_65_0.txt
Now execute the ` index.js ` file with node:
Providers/const_52_0.txt
](/en-US/plus/updates)
Providers/Providers_59_0.txt
PROPERTIES io/ethers.js/blob/main/src.ts/providers/provider-websocket.ts#L18) webSocketLike . readyState ⇒ number
Providers/howtousethejavascrip_24_0.txt
Then you can use the require() function to use/include this module within your JavaScript file:
Providers/requiringmodulesinno_148_0.txt
~/learn-node $ node bad.js ~/bad.js:1 (function (exports, require, module, __filename, __dirname) { euaohseu ^ ReferenceError: euaohseu is not defined
Providers/requiringmodulesinno_205_0.txt
ADVERTISEMENT
Providers/requiringmodulesinno_50_0.txt
~/learn-node $ echo '{ "name": "find-me-folder", "main": "start.js" }' > node_modules/find-me/package.json
Providers/const_50_0.txt
* [ Updates
Providers/requiringmodulesinno_40_0.txt
If we remove the local ` node_modules ` directory under ` ~/learn-node ` and try to require ` find-me ` one more time, the file under the home’s ` node_modules ` directory would be used:
Providers/indexjs_16_0.txt
* Open Source
Providers/Providers_5_0.txt
METHODS If a Block was fetched with a request to include the transactions this will allow synchronous access to those transactions. If the transactions were not prefetched, this will throw. Get the transaction at indexe within this block. io/ethers.js/blob/main/src.ts/providers/provider.ts#L711) block . isL...
Providers/Providers_53_0.txt
PROPERTIES The price paid per BLOB in gas. See [ EIP-4844 ](https://eips.ethereum.org/EIPS/eip-4844) . The gas used for BLObs. See [ EIP-4844 ](https://eips.ethereum.org/EIPS/eip-4844) . io/ethers.js/blob/main/src.ts/providers/provider.ts#L934) transactionReceipt . blockHash ⇒ string read-only The block has...
Providers/requiringmodulesinno_220_0.txt
![Samer Buna](https://www.freecodecamp.org/news/content/images/size/w60/2021/05/samer- buna-gravatar.jpeg) [ Samer Buna ](/news/author/samerbuna/)
Providers/const_117_0.txt
const MY_ARRAY = []; MY_ARRAY = ["B"];
Providers/const_26_0.txt
* Guides [ Guides ](/en-US/docs/Learn) * [ Overview / MDN Learning Area
Providers/const_104_0.txt
### Block scoping
Providers/requiringmodulesinno_217_0.txt
ADVERTISEMENT
Providers/const_33_0.txt
Learn to structure web content with HTML
Providers/const_32_0.txt
* [ HTML
Providers/requiringmodulesinno_88_0.txt
The ` module ` module uses the ` loaded ` attribute to track which modules have been loaded (true value) and which modules are still being loaded (false value). We can, for example, see the ` index.js ` module fully loaded if we print its ` module ` object on the next cycle of the event loop using a ` setImmediate ` ca...
Providers/requiringmodulesinno_47_0.txt
Note how it ignored the home directory’s ` node_modules ` path again since we have a local one now.
Providers/howtousethejavascrip_9_0.txt
When you have these modules in separate JavaScript files, you'll want to use them within the original JavaScript file.
Providers/const_21_0.txt
Developing extensions for web browsers
Providers/const_78_0.txt
* Try it * Syntax * Description * Examples * Specifications * Browser compatibility * See also
Providers/requiringmodulesinno_48_0.txt
An ` index.js ` file will be used by default when we require a folder, but we can control what file name to start with under the folder using the ` main ` property in ` package.json ` . For example, to make the ` require('find-me') ` line resolve to a different file under the ` find-me ` folder, all we need to do is ad...
Providers/Providers_39_0.txt
class NetworkPlugin A NetworkPlugin provides additional functionality on a [ Network ](/v6/api/providers/#Network) .
Providers/requiringmodulesinno_111_0.txt
We can natively require JSON files and C++ addon files with the require function. You don’t even need to specify a file extension to do so.
Providers/requiringmodulesinno_84_0.txt
console.log('UTIL:', UTIL);
Providers/Providers_61_0.txt
class WebSocketProvider inherits from [ SocketProvider ](/v6/api/providers/abstract- provider/#SocketProvider) , [ JsonRpcApiProvider ](/v6/api/providers/jsonrpc/#JsonRpcApiProvider) A JSON-RPC provider which is backed by a WebSocket. WebSockets are often preferred because they retain a live connection to a server...
Providers/howtousethejavascrip_30_0.txt
The require and import functions/statements are used to include modules within your JavaScript file, but they possess some differences. The two major differences are:
Providers/const_123_0.txt
For more information, see [ Destructuring assignment ](/en- US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment) .
Providers/const_137_0.txt
Your blueprint for a better internet.
Providers/requiringmodulesinno_198_0.txt
That’s all I have for this topic. Thanks for reading. Until next time!
Providers/requiringmodulesinno_159_0.txt
If we change the whole ` exports ` object, it would no longer be a reference to ` module.exports ` . This is the way JavaScript reference objects work everywhere, not just in this context.
Providers/requiringmodulesinno_59_0.txt
require('./lib/find-me');
Providers/requiringmodulesinno_105_0.txt
const Module1 = require('./module1'); console.log('Module1 is partially loaded here', Module1);
Providers/indexjs_74_0.txt
bot . logger . info ( '⏳ Database syncing!' )
Providers/howtousethejavascrip_18_0.txt
### How to Use the require() Function in JS
Providers/Providers_57_1.txt
for legacy transactions types. io/ethers.js/blob/main/src.ts/providers/provider.ts#L1308) transactionResponse . value ⇒ bigint read-only The value, in wei. Use [ formatEther ](/v6/api/utils/#formatEther) to format this value as ether.
Providers/requiringmodulesinno_172_0.txt
We want to use this file in two ways:
Providers/requiringmodulesinno_12_0.txt
const config = require('/path/to/file');
Providers/const_138_0.txt
* [ MDN on Mastodon ](https://mozilla.social/@mdn) * [ MDN on X (formerly Twitter) ](https://twitter.com/mozdevnet) * [ MDN on GitHub ](https://github.com/mdn/) * [ MDN Blog RSS Feed ](/en-US/blog/rss.xml)
Providers/requiringmodulesinno_93_0.txt
The ` exports ` object becomes complete when Node finishes loading the module (and labels it so). The whole process of requiring/loading a module is _synchronous._ That’s why we were able to see the modules fully loaded after one cycle of the event loop.
Providers/indexjs_11_0.txt
* [ Enterprise ](https://github.com/enterprise) * [ Teams ](https://github.com/team) * [ Startups ](https://github.com/enterprise/startups) * [ Education ](https://education.github.com)
Providers/indexjs_50_0.txt
# index.js
Providers/requiringmodulesinno_203_0.txt
ADVERTISEMENT
Providers/requiringmodulesinno_69_0.txt
To understand it better, let’s first understand a few other concepts on the module object.
Providers/requiringmodulesinno_209_0.txt
ADVERTISEMENT
Providers/Providers_37_0.txt
PROPERTIES io/ethers.js/blob/main/src.ts/providers/provider.ts#L393) minedBlock . date ⇒ Date read-only The block date, created from the [ timestamp ](/v6/api/providers/#MinedBlock#MinedBlock-timestamp) . io/ethers.js/blob/main/src.ts/providers/provider.ts#L383) minedBlock . hash ⇒ string read-only The blo...
Providers/const_139_0.txt
## MDN
Providers/requiringmodulesinno_90_0.txt
The output of that would be:
Providers/indexjs_34_0.txt
Query
Providers/requiringmodulesinno_38_0.txt
When we ` require('find-me') ` from within the ` learn-node ` directory — which has its own ` node_modules/find-me.js ` , the ` find-me.js ` file under the home directory will not be loaded at all:
Providers/const_1_0.txt
[ MDN Web Docs ](/en-US/) Open main menu
Providers/requiringmodulesinno_190_0.txt
Say that you have the following ` ascii-art.js ` file that prints a cool looking header:
Providers/const_25_0.txt
](/en-US/docs/Web)
Providers/const_11_0.txt
* [ JavaScript
Providers/requiringmodulesinno_201_0.txt
ADVERTISEMENT
Providers/requiringmodulesinno_6_0.txt
![Requiring modules in Node.js: Everything you need to know](https://cdn- media-1.freecodecamp.org/images/1*AL0-iuggGnBLSvSVvt0Xzw.png)
Providers/indexjs_44_0.txt
Additional navigation options
Providers/Providers_30_0.txt
CREATING INSTANCES io/ethers.js/blob/main/src.ts/providers/plugins-network.ts#L127) new GasCostPlugin ( effectiveBlock ?: number , costs ?: [ GasCostParameters ](/v6/api/providers/#GasCostParameters) ) Creates a new GasCostPlugin from effectiveBlock until the latest block or another GasCostPlugin supercedes...
Providers/Providers_44_0.txt
PROPERTIES io/ethers.js/blob/main/src.ts/providers/signer-noncemanager.ts#L21) nonceManager . signer ⇒ [ Signer ](/v6/api/providers/#Signer) The Signer being managed.