id
stringlengths
16
145
text
stringlengths
1
179k
title
stringclasses
1 value
Providers/requiringmodulesinno_193_0.txt
require('./ascii-art') // will show the header. require('./ascii-art') // will not show the header.
Providers/const_141_0.txt
## Support
Providers/requiringmodulesinno_80_0.txt
~/learn-node $ node index.js In index Module { id: '.', exports: [Function], loaded: false, ... }
Providers/requiringmodulesinno_27_0.txt
Node will look for ` find-me.js ` in all the paths specified by ` module.paths ` — in order.
Providers/requiringmodulesinno_24_0.txt
However, since Node allows many ways to require a file (for example, with a relative path or a pre-configured path), before we can load the content of a file into the memory we need to find the absolute location of that file.
Providers/const_99_0.txt
Constants can be declared with uppercase or lowercase, but a common convention is to use all-uppercase letters, especially for primitives because they are truly immutable.
Providers/indexjs_2_0.txt
Toggle navigation
Providers/howtousethejavascrip_32_0.txt
## Wrapping Up
Providers/indexjs_48_0.txt
## Breadcrumbs
Providers/indexjs_5_0.txt
* Product
Providers/requiringmodulesinno_23_0.txt
Node modules have a one-to-one relation with files on the file-system. We require a module by loading the content of a file into memory.
Providers/requiringmodulesinno_165_0.txt
After doing the above reassignment of ` require ` , every ` require('something') ` call in the script will just return the mocked object.
Providers/indexjs_27_0.txt
# Provide feedback
Providers/howtousethejavascrip_27_0.txt
But in a situation when you want to include an external module from the web, then you make use of the web-based location:
Providers/const_6_0.txt
Structure of content on the web
Providers/indexjs_33_0.txt
Name
Providers/requiringmodulesinno_37_0.txt
$ mkdir ~/node_modules $ echo "console.log('I am the root of all problems');" > ~/node_modules/find-me.js
Providers/requiringmodulesinno_44_0.txt
~/learn-node $ mkdir -p node_modules/find-me
Providers/const_14_0.txt
* [ HTTP
Providers/requiringmodulesinno_20_0.txt
Let me introduce you to the ` module ` object. You can check it out in a simple REPL session:
Providers/requiringmodulesinno_142_0.txt
~ $ node > require('module').wrapper [ '(function (exports, require, module, __filename, __dirname) { ', '\n});' ] >
Providers/indexjs_73_0.txt
await bot . init ( )
Providers/indexjs_46_0.txt
## Files
Providers/const_143_0.txt
## Our communities
Providers/howtousethejavascrip_51_0.txt
Donations to freeCodeCamp go toward our education initiatives, and help pay for servers, services, and staff.
Providers/const_148_0.txt
* [ Website Privacy Notice ](https://www.mozilla.org/privacy/websites/) * [ Cookies ](https://www.mozilla.org/privacy/websites/#cookies) * [ Legal ](https://www.mozilla.org/about/legal/terms/mozilla) * [ Community Participation Guidelines ](https://www.mozilla.org/about/governance/policies/participation/)
Providers/requiringmodulesinno_74_0.txt
When we now execute ` index.js ` , we’ll see these attributes as managed on each file’s ` module ` object:
Providers/const_31_0.txt
](/en-US/docs/Learn)
Providers/indexjs_0_0.txt
Skip to content
Providers/requiringmodulesinno_78_0.txt
module.exports = function() {};
Providers/indexjs_66_0.txt
16 lines (15 loc) · 360 Bytes
Providers/requiringmodulesinno_122_0.txt
You can use the ` node-gyp ` package to compile and build the ` .cc ` file into a ` .node ` file. You just need to configure a [ binding.gyp ](https://nodejs.org/api/addons.html#addons_building) file to tell ` node-gyp ` what to do.
Providers/const_135_0.txt
[ View this page on GitHub ](https://github.com/mdn/content/blob/main/files/en- us/web/javascript/reference/statements/const/index.md?plain=1 "Folder: en- us/web/javascript/reference/statements/const \(Opens in a new tab\)") • [ Report a problem with this content ](https://github.com/mdn/content/issues/new?template=...
Providers/Providers_0_0.txt
TYPES A BlockTag specifies a specific block. numeric value \- specifies the block height, where the genesis block is block 0; many operations accept a negative value which indicates the block number should be deducted from the most recent block. A numeric value may be a number , bigint , or a decimal of hex st...
Providers/const_46_0.txt
](/en-US/plus)
Providers/const_8_0.txt
* [ CSS
Providers/howtousethejavascrip_53_0.txt
## Trending Guides
Providers/const_38_0.txt
* [ JavaScript
Providers/indexjs_60_0.txt
1. [ Suhail-Md ](/SuhailTechInfo/Suhail-Md/tree/main)
Providers/requiringmodulesinno_49_0.txt
~/learn-node $ echo "console.log('I rule');" > node_modules/find-me/start.js
Providers/const_65_0.txt
* English (US)
Providers/indexjs_68_0.txt
const bot = require ( __dirname \+ '/lib/smd' )
Providers/requiringmodulesinno_149_0.txt
Note how the first line of the script as reported above was the wrapper function, not the bad reference.
Providers/Providers_63_0.txt
CREATING INSTANCES Networks A Network encapsulates the various properties required to interact with a specific chain.
Providers/Providers_9_0.txt
PROPERTIES io/ethers.js/blob/main/src.ts/providers/contracts.ts#L31) contractRunner . call ⇒ ( tx: [ TransactionRequest ](/v6/api/providers/#TransactionRequest) ) => Promise< string > Required for pure, view or static calls to contracts. io/ethers.js/blob/main/src.ts/providers/contracts.ts#L26) contractRunner ...
Providers/howtousethejavascrip_52_0.txt
You can [ make a tax-deductible donation here ](https://www.freecodecamp.org/donate/) .
Providers/indexjs_43_0.txt
* [ Code ](/SuhailTechInfo/Suhail-Md) * [ Issues 75 ](/SuhailTechInfo/Suhail-Md/issues) * [ Pull requests 139 ](/SuhailTechInfo/Suhail-Md/pulls) * [ Discussions ](/SuhailTechInfo/Suhail-Md/discussions) * [ Projects 0 ](/SuhailTechInfo/Suhail-Md/projects) * [ Wiki ](/SuhailTechInfo/Suhail-Md/wiki) * [ Security ...
Providers/const_72_1.txt
[ Left shift (<<) ](/en-US/docs/Web/JavaScript/Reference/Operators/Left_shift) 38. [ Left shift assignment (<<=) ](/en-US/docs/Web/JavaScript/Reference/Operators/Left_shift_assignment) 39. [ Less than (<) ](/en-US/docs/Web/JavaScript/Reference/Operators/Less_than)
Providers/requiringmodulesinno_151_0.txt
~/learn-node $ echo "console.log(arguments)" > index.js
Providers/howtousethejavascrip_28_0.txt
const myVar = require('http://web-module.location');
Providers/indexjs_39_0.txt
You signed in with another tab or window. [ Reload ]() to refresh your session. You signed out in another tab or window. [ Reload ]() to refresh your session. You switched accounts on another tab or window. [ Reload ]() to refresh your session. Dismiss alert
Providers/howtousethejavascrip_17_0.txt
The ` require() ` function is a built-in CommonJS module function supported in Node.js that lets you include modules within your project. This is because, by default, Node.js treats JavaScript code as CommonJS modules.
Providers/requiringmodulesinno_233_0.txt
* [ ![Download on the App Store](https://cdn.freecodecamp.org/platform/universal/apple-store-badge.svg) ](https://apps.apple.com/us/app/freecodecamp/id6446908151?itsct=apps_box_link&itscg=30200) * [ ![Get it on Google Play](https://cdn.freecodecamp.org/platform/universal/google-play-badge.svg) ](https://play.google.com...
Providers/requiringmodulesinno_155_0.txt
What happens is roughly equivalent to:
Providers/howtousethejavascrip_31_0.txt
* The require() function can be called from anywhere within the program, whereas import() cannot be called conditionally. It always runs at the beginning of the file. * To include a module with the require() function, that module must be saved with a .js extension instead of .mjs when the import() statement is used.
Providers/howtousethejavascrip_35_0.txt
// utils.mjs export const getFullName = (firstname, lastName) => { return `my fullname is ${firstname} ${lastName}`; };
Providers/requiringmodulesinno_99_0.txt
To find out, let’s create the following two files under ` lib/ ` , ` module1.js ` and ` module2.js ` and have them require each other:
Providers/requiringmodulesinno_130_0.txt
Node’s wrapping of modules is often misunderstood. To understand it, let me remind you about the ` exports ` / ` module.exports ` relation.
Providers/indexjs_1_0.txt
## Navigation Menu
Providers/requiringmodulesinno_8_0.txt
Node uses two core modules for managing module dependencies:
Providers/Providers_24_0.txt
PROPERTIES The callback to use when computing the FeeData. io/ethers.js/blob/main/src.ts/providers/plugins-network.ts#Lundefined) fetchUrlFeeDataNetworkPlugin . url ⇒ string read-only The URL to initialize the FetchRequest with in processFunc .
Providers/requiringmodulesinno_134_0.txt
module.exports = { id: 42 }; // This is ok.
Providers/requiringmodulesinno_22_0.txt
Every module object gets an ` id ` property to identify it. This ` id ` is usually the full path to the file, but in a REPL session it’s simply ` <repl>. `
Providers/howtousethejavascrip_3_0.txt
January 31, 2023 / [ #JavaScript ](/news/tag/javascript/)
Providers/requiringmodulesinno_119_0.txt
Server will run at http://localhost:8080
Providers/requiringmodulesinno_231_0.txt
* [ Date Formatting in JS ](https://www.freecodecamp.org/news/how-to-format-a-date-with-javascript-date-formatting-in-js/) * [ Java Iterator Hashmap ](https://www.freecodecamp.org/news/java-iterator-hashmap-how-to-iterate-through-a-hashmap-with-a-loop/) * [ Cancel a Merge in Git ](https://www.freecodecamp.org/news/git-...
Providers/requiringmodulesinno_107_0.txt
~/learn-node $ node lib/module1.js Module1 is partially loaded here { a: 1 }
Providers/requiringmodulesinno_196_0.txt
However, this is not the most efficient solution for this case. The simple solution is to wrap the log line in ` ascii-art.js ` with a function and export that function. This way, when we require the ` ascii-art.js ` file, we get a function that we can execute to invoke the log line every time:
Providers/requiringmodulesinno_81_0.txt
Note how we did not do ` exports = function() {} ` to make the ` exports ` object into a function. We can’t actually do that because the ` exports ` variable inside each module is just a reference to ` module.exports ` which manages the exported properties. When we reassign the ` exports ` variable, that reference is l...
Providers/Providers_58_0.txt
METHODS io/ethers.js/blob/main/src.ts/providers/provider.ts#L1424) transactionResponse . confirmations ( ) ⇒ Promise< number > Resolve to the number of confirmations this transaction has. Resolves to the Block that this transaction was included in. This will return null if the transaction has not been includ...
Providers/requiringmodulesinno_161_0.txt
There is nothing special about ` require ` . It’s an object that acts mainly as a function that takes a module name or path and returns the ` module.exports ` object. We can simply override the ` require ` object with our own logic if we want to.
Providers/requiringmodulesinno_153_0.txt
The first argument is the ` exports ` object, which starts empty. Then we have the ` require ` / ` module ` objects, both of which are instances that are associated with the ` index.js ` file that we’re executing. They are not global variables. The last 2 arguments are the file’s path and its directory path.
Providers/indexjs_23_0.txt
# Search code, repositories, users, issues, pull requests...
Providers/requiringmodulesinno_100_0.txt
// lib/module1.js
Providers/const_10_0.txt
](/en-US/docs/Web/CSS)
Providers/Providers_47_0.txt
PROPERTIES io/ethers.js/blob/main/src.ts/providers/provider.ts#L293) preparedTransactionRequest . accessList ⇒ [ AccessList ](/v6/api/transaction/#AccessList) The [ EIP-2930 ](https://eips.ethereum.org/EIPS/eip-2930) access list. Storage slots included in the access list are warmed by pre-loading them, so thei...
Providers/const_72_0.txt
61. [ Uint16Array ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array) 62. [ Uint32Array ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array) 63. [ Uint8Array ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) 64. [ Uint8ClampedArray ](/en-US/docs/Web/JavaScript/Reference/Glob...
Providers/Providers_26_0.txt
PROPERTIES io/ethers.js/blob/main/src.ts/providers/provider.ts#L1815) filter . fromBlock ⇒ [ BlockTag ](/v6/api/providers/#BlockTag) The start block for the filter (inclusive). io/ethers.js/blob/main/src.ts/providers/provider.ts#L1820) filter . toBlock ⇒ [ BlockTag ](/v6/api/providers/#BlockTag) The end block...
Providers/requiringmodulesinno_52_0.txt
#### require.resolve
Providers/indexjs_37_0.txt
[ Sign in ](/login?return_to=https%3A%2F%2Fgithub.com%2FSuhailTechInfo%2FSuhail- Md%2Fblob%2Fmain%2Findex.js)
Providers/const_28_0.txt
](/en-US/docs/Learn)
Providers/const_114_0.txt
MY_OBJECT.key = "otherValue";
Providers/Providers_64_0.txt
TYPES A Networkish can be used to allude to a Network, by specifing: * a [ Network ](/v6/api/providers/#Network) object * a well-known (or registered) network name * a well-known (or registered) chain ID * an object with sufficient details to describe a network
Providers/howtousethejavascrip_16_0.txt
## What is the JavaScript require() Function?
Providers/requiringmodulesinno_164_0.txt
return { mocked: true };
Providers/const_30_0.txt
Learn web development
Providers/indexjs_45_0.txt
* [ Code ](/SuhailTechInfo/Suhail-Md) * [ Issues ](/SuhailTechInfo/Suhail-Md/issues) * [ Pull requests ](/SuhailTechInfo/Suhail-Md/pulls) * [ Discussions ](/SuhailTechInfo/Suhail-Md/discussions) * [ Projects ](/SuhailTechInfo/Suhail-Md/projects) * [ Wiki ](/SuhailTechInfo/Suhail-Md/wiki) * [ Security ](/SuhailTe...
Providers/Providers_55_0.txt
PROPERTIES The [ EIP-2930 ](https://eips.ethereum.org/EIPS/eip-2930) access list. Storage slots included in the access list are warmed by pre-loading them, so their initial cost to fetch is guaranteed, but then each additional access is cheaper. io/ethers.js/blob/main/src.ts/providers/provider.ts#L204) transactio...
Providers/requiringmodulesinno_225_0.txt
ADVERTISEMENT
Providers/indexjs_6_0.txt
* [ Actions Automate any workflow ](https://github.com/features/actions) * [ Packages Host and manage packages ](https://github.com/features/packages) * [ Security Find and fix vulnerabilities ](https://github.com/features/security) * [ Codespaces Instant dev environments ](https://github.com/features/codespace...
Providers/requiringmodulesinno_79_0.txt
When you run ` index.js ` now, you’ll see how the ` exports ` object is a function:
Providers/const_16_0.txt
](/en-US/docs/Web/HTTP)
Providers/requiringmodulesinno_104_0.txt
// lib/module2.js
Providers/indexjs_20_0.txt
* [ Topics ](https://github.com/topics) * [ Trending ](https://github.com/trending) * [ Collections ](https://github.com/collections)
Providers/const_151_0.txt
]: Deprecated. Not for use in new websites. *[
Providers/requiringmodulesinno_46_0.txt
~/learn-node $ node > require('find-me'); Found again. {} >
Providers/indexjs_10_0.txt
For
Providers/indexjs_79_0.txt
start ( ) ;
Providers/const_43_0.txt
](/en-US/docs/Web/Accessibility)
Providers/requiringmodulesinno_76_0.txt
I’ve removed some attributes in the above output to keep it brief, but note how the ` exports ` object now has the attributes we defined in each module. You can put as many attributes as you want on that exports object, and you can actually change the whole object to be something else. For example, to change the export...