content
large_stringlengths 3
20.5k
| url
large_stringlengths 54
193
| branch
large_stringclasses 4
values | source
large_stringclasses 39
values | embeddings
listlengths 384
384
| score
float64 -0.21
0.65
|
|---|---|---|---|---|---|
a `DataView`. This method throws [`ERR\_SOCKET\_BAD\_PORT`][] if called on an unbound socket. Example of sending a UDP packet to a port on `localhost`; ```mjs import dgram from 'node:dgram'; import { Buffer } from 'node:buffer'; const message = Buffer.from('Some bytes'); const client = dgram.createSocket('udp4'); client.send(message, 41234, 'localhost', (err) => { client.close(); }); ``` ```cjs const dgram = require('node:dgram'); const { Buffer } = require('node:buffer'); const message = Buffer.from('Some bytes'); const client = dgram.createSocket('udp4'); client.send(message, 41234, 'localhost', (err) => { client.close(); }); ``` Example of sending a UDP packet composed of multiple buffers to a port on `127.0.0.1`; ```mjs import dgram from 'node:dgram'; import { Buffer } from 'node:buffer'; const buf1 = Buffer.from('Some '); const buf2 = Buffer.from('bytes'); const client = dgram.createSocket('udp4'); client.send([buf1, buf2], 41234, (err) => { client.close(); }); ``` ```cjs const dgram = require('node:dgram'); const { Buffer } = require('node:buffer'); const buf1 = Buffer.from('Some '); const buf2 = Buffer.from('bytes'); const client = dgram.createSocket('udp4'); client.send([buf1, buf2], 41234, (err) => { client.close(); }); ``` Sending multiple buffers might be faster or slower depending on the application and operating system. Run benchmarks to determine the optimal strategy on a case-by-case basis. Generally speaking, however, sending multiple buffers is faster. Example of sending a UDP packet using a socket connected to a port on `localhost`: ```mjs import dgram from 'node:dgram'; import { Buffer } from 'node:buffer'; const message = Buffer.from('Some bytes'); const client = dgram.createSocket('udp4'); client.connect(41234, 'localhost', (err) => { client.send(message, (err) => { client.close(); }); }); ``` ```cjs const dgram = require('node:dgram'); const { Buffer } = require('node:buffer'); const message = Buffer.from('Some bytes'); const client = dgram.createSocket('udp4'); client.connect(41234, 'localhost', (err) => { client.send(message, (err) => { client.close(); }); }); ``` #### Note about UDP datagram size The maximum size of an IPv4/v6 datagram depends on the `MTU` (Maximum Transmission Unit) and on the `Payload Length` field size. \* The `Payload Length` field is 16 bits wide, which means that a normal payload cannot exceed 64K octets including the internet header and data (65,507 bytes = 65,535 − 8 bytes UDP header − 20 bytes IP header); this is generally true for loopback interfaces, but such long datagram messages are impractical for most hosts and networks. \* The `MTU` is the largest size a given link layer technology can support for datagram messages. For any link, IPv4 mandates a minimum `MTU` of 68 octets, while the recommended `MTU` for IPv4 is 576 (typically recommended as the `MTU` for dial-up type applications), whether they arrive whole or in fragments. For IPv6, the minimum `MTU` is 1280 octets. However, the mandatory minimum fragment reassembly buffer size is 1500 octets. The value of 68 octets is very small, since most current link layer technologies, like Ethernet, have a minimum `MTU` of 1500. It is impossible to know in advance the MTU of each link through which a packet might travel. Sending a datagram greater than the receiver `MTU` will not work because the packet will get silently dropped without informing the source that the data did not reach its intended recipient. ### `socket.setBroadcast(flag)` \* `flag` {boolean} Sets or clears the `SO\_BROADCAST` socket option. When set to `true`, UDP packets may be sent to a local interface's broadcast address. This method throws `EBADF` if called on an unbound socket. ### `socket.setMulticastInterface(multicastInterface)` \* `multicastInterface` {string} \_All references to scope in this section are referring to [IPv6 Zone Indexes][], which are defined by [RFC 4007][]. In string form, an IP with a scope index is written as `'IP%scope'` where scope is an interface name or interface number.\_ Sets the default outgoing multicast interface of the socket to a chosen interface
|
https://github.com/nodejs/node/blob/main//doc/api/dgram.md
|
main
|
nodejs
|
[
-0.01518190000206232,
0.007887736894190311,
0.07292404770851135,
-0.05889328569173813,
-0.056543655693531036,
-0.07884317636489868,
0.005491509567946196,
0.05319695174694061,
-0.003483997192233801,
-0.009527250193059444,
-0.03520682826638222,
-0.004868536721915007,
-0.023701753467321396,
-0.022893628105521202,
-0.018005389720201492,
-0.016959253698587418,
0.08372839540243149,
-0.052945688366889954,
-0.008390741422772408,
-0.03487351909279823,
-0.013818488456308842,
0.02523663453757763,
-0.011779021471738815,
-0.03363939747214317,
0.008987284265458584,
-0.023547673597931862,
0.10948967933654785,
0.007762150838971138,
0.03446361795067787,
0.019942013546824455,
0.01914115436375141,
-0.012745704501867294,
-0.09695563465356827,
0.07768630981445312,
-0.050614096224308014,
0.09531740099191666,
0.014730253256857395,
0.005003789439797401,
-0.08008095622062683,
0.047672659158706665,
0.021799417212605476,
0.08642882108688354,
-0.04604141414165497,
0.0780775398015976,
0.004970214329659939,
-0.013289996422827244,
-0.0789913684129715,
0.015241652727127075,
-0.03793998807668686,
-0.06553977727890015,
-0.056215763092041016,
0.045593827962875366,
-0.006732652895152569,
0.06525454670190811,
0.05558771267533302,
-0.12724833190441132,
-0.06047644466161728,
0.07431459426879883,
0.007798380684107542,
0.023949041962623596,
0.005758254323154688,
-0.004702831152826548,
0.06554131954908371,
-0.005021608900278807,
0.04684900492429733,
-0.011642350815236568,
0.02031467668712139,
0.08394879847764969,
0.035461265593767166,
0.05370107665657997,
-0.05840686336159706,
0.01294726599007845,
-0.08542553335428238,
0.06696733087301254,
-0.049764975905418396,
-0.04768034443259239,
0.01739494502544403,
-0.04983530566096306,
-0.05935821309685707,
0.011562624014914036,
-0.02894941344857216,
-0.04694593325257301,
-0.05244600027799606,
0.03892657533288002,
-0.000055496522691100836,
0.08068830519914627,
-0.05276067927479744,
-0.003961195237934589,
0.013882013969123363,
0.030871080234646797,
-0.10313258320093155,
0.0397736132144928,
-0.12284605205059052,
0.0949321985244751,
-0.025056207552552223,
-0.0024334206245839596,
0.012086223810911179,
0.01562749594449997,
-0.009473707526922226,
0.02504677139222622,
0.026789074763655663,
-0.004495872650295496,
-0.0718531608581543,
-0.03653760626912117,
-0.00005802397572551854,
-0.059044621884822845,
-0.03656056150794029,
-0.09097609668970108,
-0.035316102206707,
0.06223120167851448,
-0.021350037306547165,
0.02708645723760128,
-0.01114840991795063,
0.012751930393278599,
-0.039117030799388885,
-0.016633253544569016,
-0.014675147831439972,
0.025309106335043907,
-0.03939962759613991,
0.001998733961954713,
-0.0005223905900493264,
-0.04196903854608536,
-0.0202842615544796,
-0.006215246394276619,
-0.0024039705749601126,
-0.05714241787791252,
0.10024633258581161,
3.2538025258806626e-33,
-0.05193677544593811,
-0.07794731110334396,
-0.06981582939624786,
0.0730239525437355,
0.01894799992442131,
-0.012966885231435299,
0.0070445300079882145,
0.060697633773088455,
-0.09550997614860535,
0.012667485512793064,
-0.038001712411642075,
-0.050352372229099274,
0.049337055534124374,
0.011264472268521786,
-0.001788136549293995,
0.012284181080758572,
0.06695614010095596,
-0.006537749897688627,
0.05115428939461708,
0.03228998929262161,
-0.017897315323352814,
-0.014574017375707626,
-0.009653273038566113,
-0.051220815628767014,
-0.045550476759672165,
0.007859382778406143,
-0.05465014651417732,
0.009785294532775879,
0.04780678078532219,
0.00847429595887661,
-0.04258830472826958,
-0.01697343960404396,
0.026551220566034317,
0.02813308872282505,
0.03847825899720192,
-0.07683293521404266,
-0.047217439860105515,
0.006090303882956505,
-0.06060868874192238,
-0.026866793632507324,
-0.023218385875225067,
-0.03426710516214371,
-0.11052042245864868,
-0.009545393288135529,
-0.006865460891276598,
-0.030167127028107643,
-0.0752348005771637,
-0.07821932435035706,
-0.007710599806159735,
-0.06504472345113754,
0.041800130158662796,
-0.0005880968528799713,
0.07896694540977478,
-0.01891140826046467,
0.05752718821167946,
-0.005624603945761919,
0.029868043959140778,
-0.007397816050797701,
-0.02272290550172329,
0.10924951732158661,
-0.016592364758253098,
0.048729363828897476,
-0.013600397855043411,
-0.004952280782163143,
0.049157556146383286,
0.0024164882488548756,
-0.0517200343310833,
0.030839305371046066,
0.004535357002168894,
-0.04661499336361885,
0.016879936680197716,
0.03297790139913559,
0.051078591495752335,
0.06627257168292999,
-0.056809742003679276,
0.06344568729400635,
-0.04647469520568848,
0.01395464688539505,
0.005927655845880508,
-0.044306933879852295,
-0.005366207100450993,
-0.05835939571261406,
0.0038298547733575106,
0.010031726211309433,
0.04132081940770149,
0.0148007245734334,
0.004537226632237434,
-0.0059219845570623875,
-0.010768857784569263,
0.0940801352262497,
-0.13060885667800903,
-0.03084038384258747,
-0.010613661259412766,
-0.055168792605400085,
0.023755138739943504,
-7.510582382288995e-33,
-0.05027089640498161,
0.12588661909103394,
-0.12811718881130219,
0.06853469461202621,
-0.026070157065987587,
-0.029503805562853813,
0.06474298238754272,
0.04988650605082512,
-0.026071535423398018,
-0.008780479431152344,
-0.04077524319291115,
-0.016683248803019524,
0.04760049656033516,
0.05696787312626839,
-0.006609803531318903,
-0.012578129768371582,
-0.06806860119104385,
-0.007059959694743156,
-0.0762697234749794,
-0.03494027256965637,
-0.06558471918106079,
-0.004374010022729635,
0.03808511793613434,
-0.00866137444972992,
-0.057119619101285934,
0.027557330206036568,
-0.008854325860738754,
0.04589715227484703,
-0.11207302659749985,
-0.05522170290350914,
0.06031869351863861,
0.019709119573235512,
-0.022563306614756584,
0.01607677899301052,
-0.0222261194139719,
0.025528164580464363,
0.12673096358776093,
0.05481511354446411,
0.052665069699287415,
0.010526294820010662,
0.10995252430438995,
0.01893249712884426,
-0.06694251298904419,
0.010753651149570942,
0.011191699653863907,
0.011743977665901184,
-0.03548840805888176,
0.058305151760578156,
0.014786933548748493,
-0.00906482245773077,
0.010641512461006641,
0.01427031122148037,
0.058103956282138824,
0.07388786971569061,
0.016626890748739243,
0.10122901201248169,
0.10199598968029022,
-0.010975413955748081,
0.12850239872932434,
0.028199780732393265,
-0.0045175026170909405,
-0.22143879532814026,
-0.03178730979561806,
-0.023090949282050133,
0.04628096520900726,
-0.030386988073587418,
-0.00975545309484005,
0.006551285739988089,
0.05337144061923027,
0.010972767136991024,
0.001389495562762022,
0.05614648386836052,
-0.05897805094718933,
0.007954220287501812,
0.02152894251048565,
0.07006333023309708,
-0.05053868517279625,
-0.04341372847557068,
0.02324014902114868,
0.09187596291303635,
-0.0548795610666275,
0.021928299218416214,
0.0024175269063562155,
0.08692160993814468,
0.09815999120473862,
-0.015432888641953468,
-0.022196611389517784,
-0.057327598333358765,
-0.018005801364779472,
-0.08069048076868057,
0.011324380524456501,
0.05336252599954605,
-0.07310783863067627,
0.018305743113160133,
0.028974175453186035,
-5.504925226773594e-8,
0.009269659407436848,
-0.0759306252002716,
-0.01968776434659958,
-0.010226867161691189,
-0.0027668816037476063,
-0.02281826175749302,
-0.04278915002942085,
-0.032244447618722916,
0.07967725396156311,
-0.021835697814822197,
-0.04529162123799324,
-0.028512073680758476,
-0.06323127448558807,
-0.026220468804240227,
0.07592035084962845,
-0.051829565316438675,
0.003084366675466299,
-0.0839218944311142,
-0.028678448870778084,
-0.0610928051173687,
0.04853596165776253,
-0.028965597972273827,
-0.05014084652066231,
0.04980212450027466,
-0.06412758678197861,
-0.05552874878048897,
0.08359717577695847,
0.03800619766116142,
-0.08099706470966339,
-0.0881609320640564,
-0.047837838530540466,
0.000663492945022881,
0.06727559864521027,
0.029465189203619957,
-0.0296630859375,
0.024848463013768196,
-0.029320266097784042,
-0.020208396017551422,
0.07443792372941971,
0.08556385338306427,
0.02110769972205162,
-0.006609560921788216,
-0.06003905460238457,
0.05167016386985779,
0.030151257291436195,
0.07100285589694977,
0.026281360536813736,
0.06342937052249908,
-0.0053512644954025745,
0.06427114456892014,
-0.003143523121252656,
0.0013261709827929735,
-0.03579220920801163,
-0.05243292450904846,
0.03323568031191826,
-0.023364802822470665,
-0.08655763417482376,
-0.07043774425983429,
-0.04805189371109009,
0.041684988886117935,
-0.0504695400595665,
0.161994069814682,
-0.02981996349990368,
-0.04604102298617363
] | 0.079092
|
in this section are referring to [IPv6 Zone Indexes][], which are defined by [RFC 4007][]. In string form, an IP with a scope index is written as `'IP%scope'` where scope is an interface name or interface number.\_ Sets the default outgoing multicast interface of the socket to a chosen interface or back to system interface selection. The `multicastInterface` must be a valid string representation of an IP from the socket's family. For IPv4 sockets, this should be the IP configured for the desired physical interface. All packets sent to multicast on the socket will be sent on the interface determined by the most recent successful use of this call. For IPv6 sockets, `multicastInterface` should include a scope to indicate the interface as in the examples that follow. In IPv6, individual `send` calls can also use explicit scope in addresses, so only packets sent to a multicast address without specifying an explicit scope are affected by the most recent successful use of this call. This method throws `EBADF` if called on an unbound socket. #### Example: IPv6 outgoing multicast interface On most systems, where scope format uses the interface name: ```js const socket = dgram.createSocket('udp6'); socket.bind(1234, () => { socket.setMulticastInterface('::%eth1'); }); ``` On Windows, where scope format uses an interface number: ```js const socket = dgram.createSocket('udp6'); socket.bind(1234, () => { socket.setMulticastInterface('::%2'); }); ``` #### Example: IPv4 outgoing multicast interface All systems use an IP of the host on the desired physical interface: ```js const socket = dgram.createSocket('udp4'); socket.bind(1234, () => { socket.setMulticastInterface('10.0.0.2'); }); ``` #### Call results A call on a socket that is not ready to send or no longer open may throw a \_Not running\_ [`Error`][]. If `multicastInterface` can not be parsed into an IP then an \_EINVAL\_ [`System Error`][] is thrown. On IPv4, if `multicastInterface` is a valid address but does not match any interface, or if the address does not match the family then a [`System Error`][] such as `EADDRNOTAVAIL` or `EPROTONOSUP` is thrown. On IPv6, most errors with specifying or omitting scope will result in the socket continuing to use (or returning to) the system's default interface selection. A socket's address family's ANY address (IPv4 `'0.0.0.0'` or IPv6 `'::'`) can be used to return control of the sockets default outgoing interface to the system for future multicast packets. ### `socket.setMulticastLoopback(flag)` \* `flag` {boolean} Sets or clears the `IP\_MULTICAST\_LOOP` socket option. When set to `true`, multicast packets will also be received on the local interface. This method throws `EBADF` if called on an unbound socket. ### `socket.setMulticastTTL(ttl)` \* `ttl` {integer} Sets the `IP\_MULTICAST\_TTL` socket option. While TTL generally stands for "Time to Live", in this context it specifies the number of IP hops that a packet is allowed to travel through, specifically for multicast traffic. Each router or gateway that forwards a packet decrements the TTL. If the TTL is decremented to 0 by a router, it will not be forwarded. The `ttl` argument may be between 0 and 255. The default on most systems is `1`. This method throws `EBADF` if called on an unbound socket. ### `socket.setRecvBufferSize(size)` \* `size` {integer} Sets the `SO\_RCVBUF` socket option. Sets the maximum socket receive buffer in bytes. This method throws [`ERR\_SOCKET\_BUFFER\_SIZE`][] if called on an unbound socket. ### `socket.setSendBufferSize(size)` \* `size` {integer} Sets the `SO\_SNDBUF` socket option. Sets the maximum socket send buffer in bytes. This method throws [`ERR\_SOCKET\_BUFFER\_SIZE`][] if called on an unbound socket. ### `socket.setTTL(ttl)` \* `ttl` {integer} Sets the `IP\_TTL` socket option. While TTL generally stands for "Time to Live", in this context it specifies the number of IP hops that a packet is allowed to
|
https://github.com/nodejs/node/blob/main//doc/api/dgram.md
|
main
|
nodejs
|
[
-0.0037247459404170513,
-0.03845720365643501,
0.006342888344079256,
-0.07210472971200943,
-0.006644891574978828,
0.05296776443719864,
0.002029901370406151,
-0.012684401124715805,
-0.013504117727279663,
-0.010387540794909,
-0.04342825338244438,
-0.003428412601351738,
0.0017978959949687123,
-0.0668996125459671,
-0.025872018188238144,
-0.03869612142443657,
0.025599395856261253,
-0.11515294760465622,
-0.03996957466006279,
-0.044723477214574814,
0.058204323053359985,
0.05487649887800217,
0.01156964898109436,
-0.07183513790369034,
-0.03279050439596176,
-0.04609334468841553,
0.006368640810251236,
0.040883857756853104,
0.07870794087648392,
0.09401856362819672,
0.0075368150137364864,
0.07785731554031372,
-0.023538200184702873,
0.06240787357091904,
-0.10845498740673065,
0.032634004950523376,
-0.024066127836704254,
-0.03432918339967728,
-0.12546609342098236,
0.04047149792313576,
0.043089739978313446,
0.0004654716176446527,
0.0007748341886326671,
-0.009329554624855518,
0.00785446260124445,
0.04096602648496628,
-0.02666744962334633,
0.051079217344522476,
-0.027309980243444443,
-0.07158023118972778,
-0.00107451097574085,
-0.022542515769600868,
-0.022388212382793427,
0.10304810106754303,
0.1044296845793724,
-0.09734106808900833,
-0.07721353322267532,
0.023109490051865578,
0.023811127990484238,
0.060424014925956726,
-0.025399981066584587,
0.007943427190184593,
0.025168702006340027,
0.028648534789681435,
0.044224537909030914,
-0.017923785373568535,
0.014053377322852612,
0.04111146554350853,
-0.07640337944030762,
-0.023441866040229797,
-0.11673834174871445,
0.026524098590016365,
0.008333231322467327,
0.005420766770839691,
0.03578087314963341,
0.022111130878329277,
-0.022936958819627762,
-0.059544194489717484,
0.004244337324053049,
0.01207431685179472,
-0.019946260377764702,
0.006823535542935133,
-0.03298891335725784,
0.023235030472278595,
-0.00918063148856163,
-0.07002230733633041,
-0.0803380087018013,
-0.05865214392542839,
0.04485929757356644,
0.08298680931329727,
0.009986626915633678,
-0.01775188185274601,
-0.014372958801686764,
0.02007775567471981,
0.021563848480582237,
0.046570293605327606,
-0.022575827315449715,
-0.05351708084344864,
0.04598721116781235,
0.014671940356492996,
0.018410654738545418,
-0.07864545285701752,
-0.10093691945075989,
-0.007244783919304609,
0.01264406368136406,
-0.06041048839688301,
-0.06148792803287506,
0.06250341981649399,
-0.008254796266555786,
0.09444769471883774,
-0.1068684309720993,
0.036734625697135925,
0.02142827771604061,
-0.004408384207636118,
-0.02306175045669079,
0.019559409469366074,
0.03509027883410454,
0.03246113657951355,
0.0159830991178751,
-0.006132860668003559,
-0.08759705722332001,
0.040739644318819046,
0.05457494035363197,
0.012369356118142605,
-0.075374074280262,
-0.029625289142131805,
0.021938785910606384,
3.9296702679592145e-33,
-0.025057606399059296,
-0.0030389982275664806,
-0.0015982288168743253,
0.037672258913517,
-0.07805945724248886,
0.03799452632665634,
-0.03646526113152504,
0.03195642679929733,
-0.07108912616968155,
-0.0006695691263303161,
0.04271429404616356,
0.02727171778678894,
0.08755065500736237,
0.06558138877153397,
0.021029703319072723,
0.042604174464941025,
0.0962645411491394,
0.026349060237407684,
0.061888016760349274,
0.08814923465251923,
0.032951682806015015,
0.02638016827404499,
0.02860415354371071,
-0.028318796306848526,
0.05103091150522232,
0.11361373215913773,
-0.021632034331560135,
-0.08068599551916122,
-0.01747177168726921,
0.024651024490594864,
-0.05123447999358177,
-0.0019133109599351883,
0.05466098338365555,
-0.031053615733981133,
0.07089368253946304,
-0.0051881917752325535,
-0.08281787484884262,
-0.01251097209751606,
-0.08035886287689209,
-0.028013765811920166,
0.05013583227992058,
-0.022308170795440674,
-0.10939149558544159,
-0.008534576743841171,
0.026891477406024933,
0.032482702285051346,
-0.1016290932893753,
0.014571018517017365,
-0.018619420006871223,
-0.03224187344312668,
0.036134228110313416,
0.04361554980278015,
0.08779145777225494,
-0.0165632963180542,
0.06462553888559341,
-0.00781251210719347,
-0.011227903887629509,
0.06251830607652664,
-0.008201215416193008,
0.007048972882330418,
-0.020038705319166183,
0.014721744693815708,
-0.0522565096616745,
0.009304521605372429,
0.03148309886455536,
-0.009060573764145374,
0.026949316263198853,
-0.03997323662042618,
-0.0018081397283822298,
0.011737624183297157,
-0.006985915824770927,
0.010700429789721966,
-0.055155765265226364,
0.11792891472578049,
-0.01955423876643181,
0.05616107955574989,
-0.0760272741317749,
-0.040767308324575424,
0.03336595743894577,
-0.004689003340899944,
-0.05730168893933296,
0.11442688852548599,
-0.0039475951343774796,
-0.0895136222243309,
-0.011535749770700932,
-0.019881440326571465,
-0.007051223423331976,
0.03358592092990875,
-0.010941645130515099,
-0.04975961148738861,
0.013405879028141499,
-0.02448093891143799,
-0.07830331474542618,
0.026340633630752563,
-0.012245499528944492,
-6.484735809166078e-33,
0.007153703365474939,
0.036521244794130325,
-0.18106813728809357,
0.007284022402018309,
-0.033715780824422836,
-0.09864950180053711,
0.06905220448970795,
0.002060080412775278,
0.05601787194609642,
-0.05226661264896393,
-0.006431818474084139,
-0.041805773973464966,
0.027790499851107597,
0.0025995627511292696,
-0.0037961250636726618,
-0.006818367168307304,
-0.07933381199836731,
-0.006732307840138674,
-0.013471457175910473,
-0.03385813534259796,
-0.008139414712786674,
-0.07668396085500717,
0.029996102675795555,
-0.02712426148355007,
-0.05372781306505203,
-0.025299623608589172,
0.06003091484308243,
0.0346665158867836,
-0.10082190483808517,
-0.04870690032839775,
0.022308683022856712,
-0.058925993740558624,
0.032932281494140625,
0.034263383597135544,
-0.05614611133933067,
0.0706813782453537,
0.06089373677968979,
-0.032057326287031174,
0.04820160195231438,
-0.018078358843922615,
0.05267883837223053,
0.05118008702993393,
-0.014253329485654831,
0.08104852586984634,
-0.038449764251708984,
0.01262962818145752,
-0.028425566852092743,
0.09705308079719543,
0.01340820174664259,
-0.01684821955859661,
0.0042749554850161076,
-0.10393363982439041,
0.022431040182709694,
0.05990937724709511,
0.0500347837805748,
0.0334189347922802,
0.05108869820833206,
-0.061692606657743454,
0.01613593101501465,
0.0029465912375599146,
0.06427820026874542,
-0.08321525901556015,
-0.004612629767507315,
0.0724710077047348,
0.056646861135959625,
-0.02215929701924324,
0.11702491343021393,
-0.11119328439235687,
0.025196678936481476,
-0.13433362543582916,
0.05422978848218918,
0.006651784293353558,
-0.03965079411864281,
-0.048464663326740265,
0.030394602566957474,
0.06787317991256714,
0.06909026950597763,
0.07250139117240906,
-0.016443930566310883,
0.011387480422854424,
-0.15419068932533264,
0.03473107889294624,
-0.04023631662130356,
0.07057195901870728,
0.06193719431757927,
-0.022728079929947853,
0.10708781331777573,
0.04371129348874092,
0.004464784637093544,
-0.052773140370845795,
0.015244932845234871,
0.07732021808624268,
-0.039849262684583664,
-0.015803147107362747,
-0.007815675809979439,
-5.3137032551831e-8,
0.007349198218435049,
-0.020654145628213882,
-0.07008585333824158,
-0.037254367023706436,
-0.014585684053599834,
0.048987261950969696,
-0.03964285925030708,
-0.05677926540374756,
-0.008595951832830906,
0.005674423184245825,
0.025503985583782196,
-0.07268033921718597,
-0.01973322592675686,
-0.07509254664182663,
0.09760723263025284,
-0.05475010350346565,
-0.013007798232138157,
-0.0687471553683281,
-0.06123119965195656,
-0.013662881217896938,
0.0002381442318437621,
-0.039294350892305374,
-0.058571573346853256,
0.007581419311463833,
0.0011330186389386654,
-0.05578124523162842,
0.05368892848491669,
0.05127645656466484,
-0.04300539195537567,
0.0030588030349463224,
-0.0438627265393734,
-0.006411937065422535,
-0.04099676012992859,
-0.010992906056344509,
-0.08092009276151657,
0.09697627276182175,
0.0043718586675822735,
-0.008102997206151485,
0.04647025465965271,
0.04818131402134895,
0.019830722361803055,
-0.03210555762052536,
-0.004382885992527008,
-0.023927679285407066,
0.05593595281243324,
0.11052440106868744,
-0.028517020866274834,
0.1105666384100914,
0.014903253875672817,
0.039343710988759995,
-0.07335185259580612,
0.06268338859081268,
0.020285485312342644,
0.043163079768419266,
0.03703533858060837,
-0.03397221490740776,
-0.014865749515593052,
-0.05359915271401405,
0.06347323209047318,
-0.008431188762187958,
0.05041377618908882,
0.013521015644073486,
-0.0758914202451706,
-0.0063020940870046616
] | 0.101199
|
maximum socket send buffer in bytes. This method throws [`ERR\_SOCKET\_BUFFER\_SIZE`][] if called on an unbound socket. ### `socket.setTTL(ttl)` \* `ttl` {integer} Sets the `IP\_TTL` socket option. While TTL generally stands for "Time to Live", in this context it specifies the number of IP hops that a packet is allowed to travel through. Each router or gateway that forwards a packet decrements the TTL. If the TTL is decremented to 0 by a router, it will not be forwarded. Changing TTL values is typically done for network probes or when multicasting. The `ttl` argument may be between 1 and 255. The default on most systems is 64. This method throws `EBADF` if called on an unbound socket. ### `socket.unref()` \* Returns: {dgram.Socket} By default, binding a socket will cause it to block the Node.js process from exiting as long as the socket is open. The `socket.unref()` method can be used to exclude the socket from the reference counting that keeps the Node.js process active, allowing the process to exit even if the socket is still listening. Calling `socket.unref()` multiple times will have no additional effect. The `socket.unref()` method returns a reference to the socket so calls can be chained. ## `node:dgram` module functions ### `dgram.createSocket(options[, callback])` \* `options` {Object} Available options are: \* `type` {string} The family of socket. Must be either `'udp4'` or `'udp6'`. Required. \* `reuseAddr` {boolean} When `true` [`socket.bind()`][] will reuse the address, even if another process has already bound a socket on it, but only one socket can receive the data. \*\*Default:\*\* `false`. \* `reusePort` {boolean} When `true` [`socket.bind()`][] will reuse the port, even if another process has already bound a socket on it. Incoming datagrams are distributed to listening sockets. The option is available only on some platforms, such as Linux 3.9+, DragonFlyBSD 3.6+, FreeBSD 12.0+, Solaris 11.4, and AIX 7.2.5+. On unsupported platforms, this option raises an error when the socket is bound. \*\*Default:\*\* `false`. \* `ipv6Only` {boolean} Setting `ipv6Only` to `true` will disable dual-stack support, i.e., binding to address `::` won't make `0.0.0.0` be bound. \*\*Default:\*\* `false`. \* `recvBufferSize` {number} Sets the `SO\_RCVBUF` socket value. \* `sendBufferSize` {number} Sets the `SO\_SNDBUF` socket value. \* `lookup` {Function} Custom lookup function. \*\*Default:\*\* [`dns.lookup()`][]. \* `signal` {AbortSignal} An AbortSignal that may be used to close a socket. \* `receiveBlockList` {net.BlockList} `receiveBlockList` can be used for discarding inbound datagram to specific IP addresses, IP ranges, or IP subnets. This does not work if the server is behind a reverse proxy, NAT, etc. because the address checked against the blocklist is the address of the proxy, or the one specified by the NAT. \* `sendBlockList` {net.BlockList} `sendBlockList` can be used for disabling outbound access to specific IP addresses, IP ranges, or IP subnets. \* `callback` {Function} Attached as a listener for `'message'` events. Optional. \* Returns: {dgram.Socket} Creates a `dgram.Socket` object. Once the socket is created, calling [`socket.bind()`][] will instruct the socket to begin listening for datagram messages. When `address` and `port` are not passed to [`socket.bind()`][] the method will bind the socket to the "all interfaces" address on a random port (it does the right thing for both `udp4` and `udp6` sockets). The bound address and port can be retrieved using [`socket.address().address`][] and [`socket.address().port`][]. If the `signal` option is enabled, calling `.abort()` on the corresponding `AbortController` is similar to calling `.close()` on the socket: ```js const controller = new AbortController(); const { signal } = controller; const server = dgram.createSocket({ type: 'udp4', signal }); server.on('message', (msg, rinfo) => { console.log(`server got: ${msg} from ${rinfo.address}:${rinfo.port}`); }); // Later, when you want to close the server. controller.abort(); ``` ### `dgram.createSocket(type[,
|
https://github.com/nodejs/node/blob/main//doc/api/dgram.md
|
main
|
nodejs
|
[
-0.020784134045243263,
-0.034139588475227356,
-0.01973031461238861,
-0.0037395877297967672,
-0.05815745145082474,
-0.06847840547561646,
-0.0516529455780983,
0.010279509238898754,
0.08552706241607666,
0.0038242570590227842,
-0.05038173124194145,
0.09363143146038055,
-0.036207713186740875,
-0.05678335949778557,
-0.01384579949080944,
-0.029063869267702103,
0.04044177755713463,
-0.043870240449905396,
-0.024475665763020515,
-0.10192438215017319,
0.06293033808469772,
0.0019098775228485465,
0.01697157509624958,
-0.028847020119428635,
-0.0514431856572628,
-0.03959959000349045,
0.01781550422310829,
0.0006695769843645394,
0.06910400837659836,
0.0067708855494856834,
-0.07361145317554474,
-0.024913521483540535,
-0.047887030988931656,
0.021055122837424278,
-0.1092282235622406,
0.08101836591959,
0.03580377250909805,
-0.024038180708885193,
-0.1134699359536171,
0.0530269593000412,
0.051074933260679245,
-0.005023116711527109,
-0.06313811242580414,
-0.015205137431621552,
0.002229647943750024,
0.009678536094725132,
-0.13223384320735931,
0.032543063163757324,
-0.04375220462679863,
-0.06741326302289963,
0.04034580662846565,
0.05611883103847504,
-0.009514780715107918,
0.09263879060745239,
0.017474820837378502,
-0.043978720903396606,
-0.007269697263836861,
0.05144767090678215,
0.01007253397256136,
0.06991059333086014,
-0.058210339397192,
-0.0018492582021281123,
0.030978919938206673,
0.016592077910900116,
0.012211830355226994,
0.010431566275656223,
-0.034723736345767975,
-0.03304992988705635,
0.012706647627055645,
0.06765246391296387,
-0.05268780142068863,
-0.03447815030813217,
-0.037996333092451096,
0.056470274925231934,
-0.011160404421389103,
-0.06824511289596558,
0.023492371663451195,
-0.006914176978170872,
-0.07341956347227097,
0.06343742460012436,
0.00216158595867455,
-0.06729720532894135,
-0.01617688313126564,
0.036819517612457275,
-0.015240783803164959,
0.04287697747349739,
-0.0957699716091156,
0.03859016299247742,
0.048323825001716614,
0.10138434916734695,
-0.0906653106212616,
-0.024019232019782066,
-0.023545658215880394,
0.11385301500558853,
-0.020194808021187782,
0.04001467674970627,
0.018082214519381523,
0.02664732001721859,
-0.068397156894207,
-0.013307378627359867,
0.0491209514439106,
-0.05752158910036087,
-0.037989504635334015,
0.03499201685190201,
-0.01992928609251976,
-0.059171147644519806,
-0.008778136223554611,
-0.011531217023730278,
0.03687097877264023,
0.01487789023667574,
-0.011551942676305771,
-0.0007124707335606217,
0.05079887807369232,
0.015907475724816322,
-0.07238849997520447,
-0.023548483848571777,
-0.0269815381616354,
0.04615209624171257,
0.08672244846820831,
0.05998843535780907,
0.043104350566864014,
0.010424362495541573,
-0.015625769272446632,
-0.026303021237254143,
0.01698075234889984,
-0.02880784124135971,
0.08542363345623016,
3.3381923673521485e-33,
-0.019926002249121666,
-0.006074335426092148,
-0.026633083820343018,
0.04315023496747017,
-0.014174818992614746,
0.039720118045806885,
-0.0006552209379151464,
0.05017513036727905,
-0.02019929140806198,
0.02698836661875248,
-0.007559299468994141,
-0.0186235960572958,
0.07412929087877274,
0.040249891579151154,
0.03895965591073036,
0.03093991056084633,
0.058545906096696854,
-0.006304519716650248,
0.08095105737447739,
0.016061579808592796,
0.05233878642320633,
-0.04204711318016052,
-0.015786325559020042,
0.011154829524457455,
-0.015584862791001797,
0.044373661279678345,
-0.092136912047863,
-0.01831171102821827,
-0.07393722236156464,
0.022032281383872032,
-0.025714397430419922,
-0.0091674430295825,
0.004978600423783064,
0.06094939261674881,
0.08639928698539734,
-0.01985793374478817,
0.003930945880711079,
0.015614870935678482,
-0.02728458307683468,
0.03186696395277977,
-0.016387678682804108,
-0.03165799751877785,
-0.12725363671779633,
0.037359569221735,
-0.026386680081486702,
-0.08993525803089142,
-0.07627959549427032,
-0.0436549186706543,
-0.040236372500658035,
0.024180304259061813,
0.022280143573880196,
0.036605436354875565,
0.024968961253762245,
-0.022268302738666534,
0.038380805402994156,
-0.020752552896738052,
0.08772871643304825,
0.01573267951607704,
-0.02413898892700672,
0.11137264221906662,
0.03875439986586571,
-0.00794111005961895,
0.0398932583630085,
0.019376030191779137,
0.09360797703266144,
0.06799469888210297,
-0.054820623248815536,
-0.03306478634476662,
-0.04784676060080528,
0.01899615488946438,
-0.0038147668819874525,
0.0891483798623085,
0.08345722407102585,
0.05016545206308365,
-0.08034295588731766,
0.03148409351706505,
-0.020858226343989372,
-0.013172007165849209,
-0.012040137313306332,
0.013811390846967697,
-0.008958817459642887,
-0.013900321908295155,
-0.024570830166339874,
-0.01701790653169155,
0.027172718197107315,
-0.0005293730064295232,
-0.0019687905441969633,
-0.012398199178278446,
-0.00492852320894599,
0.038938287645578384,
-0.01740289106965065,
-0.025673741474747658,
0.007791419047862291,
-0.008937763050198555,
-0.014586812816560268,
-5.558528912664657e-33,
-0.01772506721317768,
0.07192062586545944,
-0.15110549330711365,
0.08439011126756668,
-0.0472109317779541,
-0.0968959778547287,
-0.014379391446709633,
0.07132986187934875,
0.05083296075463295,
-0.012776666320860386,
0.03779919445514679,
0.03238688036799431,
0.04564116150140762,
0.03416244313120842,
-0.0025618525687605143,
-0.044421859085559845,
-0.05739979073405266,
-0.030902164056897163,
-0.047690413892269135,
-0.04792870208621025,
-0.07620503008365631,
-0.05683322623372078,
0.01607627049088478,
0.004327839706093073,
-0.020383691415190697,
-0.009628728963434696,
0.0043185013346374035,
-0.01818213425576687,
-0.12185246497392654,
-0.038820669054985046,
0.05815230682492256,
-0.00663429219275713,
0.022486453875899315,
0.0704411044716835,
-0.004446473438292742,
0.022001663222908974,
0.01923743449151516,
0.03506695106625557,
0.12420324981212616,
0.001174091943539679,
0.11920106410980225,
0.04612366110086441,
-0.03225495293736458,
-0.007953477092087269,
0.0026870183646678925,
0.0745147168636322,
-0.10598646849393845,
-0.004666199907660484,
0.05159115046262741,
-0.03796716034412384,
0.06265511363744736,
-0.004854325205087662,
0.10098680853843689,
0.10836722701787949,
-0.024959679692983627,
-0.023706141859292984,
0.0029091034084558487,
0.00577679555863142,
0.08276662230491638,
-0.013102841563522816,
0.10750138014554977,
-0.0842033177614212,
-0.03017355501651764,
0.05385098233819008,
0.005878109484910965,
-0.04227671027183533,
-0.049573421478271484,
-0.019022323191165924,
0.06104612350463867,
-0.003922606818377972,
0.025670191273093224,
0.02155802771449089,
0.01012448687106371,
0.06188831478357315,
-0.05521010980010033,
-0.006843800190836191,
-0.0043908366933465,
-0.0612155944108963,
-0.06477034091949463,
0.03384427726268768,
-0.1304730474948883,
0.07779146730899811,
-0.08367246389389038,
-0.02700469270348549,
0.026667535305023193,
-0.002840646542608738,
-0.024076784029603004,
0.05990315601229668,
0.011243187822401524,
-0.06375495344400406,
0.031057283282279968,
0.0756232738494873,
-0.10077714920043945,
-0.04568988457322121,
-0.03767864778637886,
-5.1808953571708116e-8,
-0.01564025692641735,
-0.0446927472949028,
-0.10634053498506546,
0.008661093190312386,
0.04548785462975502,
0.03891123831272125,
0.01767857000231743,
-0.048926979303359985,
0.1022692546248436,
0.05694169923663139,
0.007115433923900127,
-0.011513900011777878,
0.021660123020410538,
-0.04979439452290535,
0.07028410583734512,
0.06976562738418579,
0.007715178653597832,
-0.10186479985713959,
0.022906294092535973,
-0.09102675318717957,
-0.00021608178212773055,
-0.046318601816892624,
-0.060256555676460266,
0.02603478543460369,
-0.05104557424783707,
-0.07324685901403427,
0.1033218502998352,
0.1115533858537674,
-0.10022629797458649,
-0.054230500012636185,
-0.09841480851173401,
0.00015366774459835142,
-0.0032791669946163893,
0.02913999743759632,
-0.008038550615310669,
0.08554761856794357,
-0.0589277409017086,
0.0006106052896939218,
0.024007024243474007,
0.11854787915945053,
-0.03892424702644348,
-0.021512117236852646,
-0.05606234073638916,
0.002002418041229248,
-0.04681312292814255,
0.03783584386110306,
0.029545553028583527,
0.09359809756278992,
-0.033121008425951004,
0.008655416779220104,
0.04078122228384018,
0.02520616538822651,
-0.02446010150015354,
-0.060802459716796875,
0.02715236321091652,
0.011895349249243736,
-0.023468688130378723,
-0.07146225869655609,
-0.05607317388057709,
0.0466318316757679,
-0.03423025459051132,
0.06809428334236145,
0.004824608098715544,
-0.06571479886770248
] | 0.110852
|
to calling `.close()` on the socket: ```js const controller = new AbortController(); const { signal } = controller; const server = dgram.createSocket({ type: 'udp4', signal }); server.on('message', (msg, rinfo) => { console.log(`server got: ${msg} from ${rinfo.address}:${rinfo.port}`); }); // Later, when you want to close the server. controller.abort(); ``` ### `dgram.createSocket(type[, callback])` \* `type` {string} Either `'udp4'` or `'udp6'`. \* `callback` {Function} Attached as a listener to `'message'` events. \* Returns: {dgram.Socket} Creates a `dgram.Socket` object of the specified `type`. Once the socket is created, calling [`socket.bind()`][] will instruct the socket to begin listening for datagram messages. When `address` and `port` are not passed to [`socket.bind()`][] the method will bind the socket to the "all interfaces" address on a random port (it does the right thing for both `udp4` and `udp6` sockets). The bound address and port can be retrieved using [`socket.address().address`][] and [`socket.address().port`][]. [IPv6 Zone Indexes]: https://en.wikipedia.org/wiki/IPv6\_address#Scoped\_literal\_IPv6\_addresses [RFC 4007]: https://tools.ietf.org/html/rfc4007 [`'close'`]: #event-close [`ERR\_SOCKET\_BAD\_PORT`]: errors.md#err\_socket\_bad\_port [`ERR\_SOCKET\_BUFFER\_SIZE`]: errors.md#err\_socket\_buffer\_size [`ERR\_SOCKET\_DGRAM\_IS\_CONNECTED`]: errors.md#err\_socket\_dgram\_is\_connected [`ERR\_SOCKET\_DGRAM\_NOT\_CONNECTED`]: errors.md#err\_socket\_dgram\_not\_connected [`Error`]: errors.md#class-error [`System Error`]: errors.md#class-systemerror [`close()`]: #socketclosecallback [`cluster`]: cluster.md [`connect()`]: #socketconnectport-address-callback [`dgram.createSocket()`]: #dgramcreatesocketoptions-callback [`dns.lookup()`]: dns.md#dnslookuphostname-options-callback [`socket.address().address`]: #socketaddress [`socket.address().port`]: #socketaddress [`socket.bind()`]: #socketbindport-address-callback [`socket.close()`]: #socketclosecallback [byte length]: buffer.md#static-method-bufferbytelengthstring-encoding
|
https://github.com/nodejs/node/blob/main//doc/api/dgram.md
|
main
|
nodejs
|
[
-0.0405026450753212,
-0.05032927170395851,
0.02131558023393154,
0.025607990100979805,
-0.02099025808274746,
-0.03028908744454384,
0.017910417169332504,
0.02139960043132305,
0.09574799239635468,
0.006455346941947937,
-0.024172315374016762,
0.07417481392621994,
-0.12388083338737488,
-0.04150678962469101,
-0.02775527909398079,
0.07058630138635635,
0.014040950685739517,
-0.04843878746032715,
-0.02593725547194481,
-0.022754501551389694,
0.02316461317241192,
0.03430068865418434,
0.007557381875813007,
-0.014750026166439056,
-0.07855552434921265,
-0.052550286054611206,
0.10668515413999557,
0.003138539846986532,
0.026000861078500748,
0.01977844536304474,
0.04369141533970833,
-0.07186678051948547,
-0.12143348157405853,
-0.04175535961985588,
-0.11097352206707001,
0.13238826394081116,
-0.0052566491067409515,
-0.015087914653122425,
0.005881761200726032,
0.01101219467818737,
0.08571420609951019,
0.06273865699768066,
-0.061525434255599976,
0.014072458259761333,
0.03690946847200394,
0.016011282801628113,
-0.10926448553800583,
-0.0013066354440525174,
-0.014949935488402843,
-0.058151938021183014,
-0.004219422582536936,
0.026227714493870735,
0.03137994185090065,
0.0415116511285305,
0.08080955594778061,
-0.08749260753393173,
-0.049138378351926804,
0.03989187628030777,
0.023401500657200813,
0.05642581731081009,
-0.0062581803649663925,
0.023090863600373268,
0.015837980434298515,
-0.02481761947274208,
0.07866665720939636,
0.0021226273383945227,
0.05006377771496773,
0.004996277391910553,
0.03190049156546593,
0.034005120396614075,
-0.019541211426258087,
0.02346695214509964,
-0.045297618955373764,
0.020515769720077515,
-0.02682066522538662,
-0.053288619965314865,
-0.030471505597233772,
-0.07227692008018494,
-0.07045740634202957,
0.05533064156770706,
-0.017381710931658745,
-0.06811581552028656,
-0.02208174765110016,
-0.00012561118637677282,
-0.017266390845179558,
0.059075016528367996,
-0.012897281907498837,
-0.03941754251718521,
0.031576819717884064,
-0.03538741543889046,
-0.10796023905277252,
0.002971518086269498,
-0.048721447587013245,
0.09777050465345383,
-0.04690314456820488,
-0.0009116907021962106,
0.0038919842336326838,
0.025351285934448242,
-0.05170336738228798,
0.027924928814172745,
0.0273840744048357,
0.029246820136904716,
-0.09193502366542816,
-0.03900766000151634,
0.005376509856432676,
-0.026302406564354897,
-0.09723346680402756,
-0.0005993372178636491,
-0.01391677837818861,
0.03667572885751724,
-0.04143994674086571,
0.026560312137007713,
0.004960601218044758,
0.10567191988229752,
-0.04609660431742668,
0.040721066296100616,
0.014795459806919098,
0.028932513669133186,
0.018982641398906708,
0.04054851084947586,
0.0785926878452301,
-0.01658429391682148,
-0.05122522637248039,
0.000602713436819613,
0.0336005724966526,
-0.006816722918301821,
0.06555503606796265,
4.885298846747881e-35,
-0.018877342343330383,
-0.057655613869428635,
-0.1173025518655777,
0.09518000483512878,
0.03518208861351013,
0.013133346103131771,
-0.033326275646686554,
0.043854087591171265,
-0.08299075067043304,
0.1040894091129303,
-0.007390817627310753,
-0.014113790355622768,
0.04007091373205185,
-0.02005978859961033,
0.03806979954242706,
-0.0309919286519289,
0.12119460105895996,
0.00033568800427019596,
0.09688132256269455,
-0.014276946894824505,
0.011219341307878494,
0.016331937164068222,
-0.0011887189466506243,
0.0310891792178154,
0.04079107940196991,
0.08166339248418808,
-0.008398293517529964,
0.046699486672878265,
0.0006592776044271886,
-0.009652495384216309,
-0.0008527696481905878,
-0.028027256950736046,
0.018914692103862762,
0.04237472638487816,
0.06779827177524567,
-0.098775714635849,
-0.025209253653883934,
-0.02364872768521309,
-0.08366767317056656,
-0.047344617545604706,
0.056748464703559875,
-0.048334039747714996,
-0.2460561841726303,
0.04732309654355049,
0.01494835689663887,
-0.05498535558581352,
-0.023542718961834908,
-0.05229423567652702,
0.08324268460273743,
-0.04474327340722084,
-0.013982916250824928,
0.0065972465090453625,
0.06757402420043945,
0.004724378697574139,
0.07489398121833801,
-0.009088872000575066,
0.011642043478786945,
-0.047968365252017975,
-0.012889020144939423,
0.017659064382314682,
0.008029598742723465,
-0.038888730108737946,
0.027075475081801414,
-0.0014446430141106248,
0.02436443231999874,
-0.07741549611091614,
-0.056749507784843445,
-0.010542736388742924,
0.005322874989360571,
-0.04286910966038704,
-0.018477344885468483,
0.02527090720832348,
0.017904583364725113,
0.03371668979525566,
-0.009424930438399315,
0.06985387206077576,
-0.049047037959098816,
0.0544944703578949,
0.05971309170126915,
-0.03863935172557831,
0.09743938595056534,
0.011040332727134228,
-0.0460079163312912,
0.01784982718527317,
0.11064425855875015,
0.029361125081777573,
-0.035507138818502426,
0.0004678106342907995,
0.004018734209239483,
0.06160682812333107,
-0.10938196629285812,
-0.02889951691031456,
-0.035751067101955414,
-0.01248236931860447,
-0.033184267580509186,
-3.744185708265104e-33,
-0.07726998627185822,
0.030643867328763008,
-0.11255545169115067,
0.04483838379383087,
-0.03213755413889885,
-0.05976860597729683,
0.03510254994034767,
0.01617289148271084,
-0.06878411024808884,
-0.04094189032912254,
0.007868786342442036,
-0.03703176602721214,
0.07820823043584824,
0.09510266035795212,
-0.04402812197804451,
0.07363872230052948,
-0.03846253082156181,
-0.023395342752337456,
-0.016119346022605896,
-0.051220569759607315,
-0.051528364419937134,
-0.008482950739562511,
0.042717549949884415,
-0.0092702591791749,
-0.09573463350534439,
0.024388404563069344,
0.014237175695598125,
0.005799893289804459,
-0.06627769023180008,
-0.0277384202927351,
0.03033500537276268,
-0.014540479518473148,
0.023986995220184326,
0.045804399996995926,
-0.022532369941473007,
0.06870555877685547,
0.08278252929449081,
0.018590256571769714,
-0.0022108268458396196,
-0.019863484427332878,
0.12636370956897736,
-0.015791617333889008,
-0.07644417881965637,
-0.06289996951818466,
-0.021341657266020775,
0.024700898677110672,
-0.011138759553432465,
0.02278898097574711,
0.00014541020209435374,
-0.004497968126088381,
0.001615474815480411,
-0.01952970400452614,
0.06647371500730515,
0.06070847809314728,
-0.021507341414690018,
-0.0003894419060088694,
0.0909760519862175,
-0.024134771898388863,
0.07924848794937134,
0.018634049221873283,
0.057098638266325,
-0.13939176499843597,
0.06271616369485855,
-0.006042981054633856,
0.021177683025598526,
0.0013967518461868167,
-0.014748306944966316,
0.04215579852461815,
0.13204136490821838,
-0.0209855604916811,
-0.010008607991039753,
0.05266578868031502,
0.007497061043977737,
0.02170644886791706,
-0.03314518555998802,
0.03756284713745117,
-0.040175098925828934,
-0.08329268544912338,
0.03410685807466507,
0.07364167273044586,
-0.06471020728349686,
-0.0003365107986610383,
-0.029529215767979622,
0.06175115332007408,
0.031784024089574814,
0.02773337997496128,
0.014525734819471836,
0.0060515436343848705,
-0.03113457001745701,
-0.08502882719039917,
0.02292255125939846,
0.04835517704486847,
-0.02339351177215576,
-0.004747449420392513,
-0.025827011093497276,
-4.752940085950286e-8,
0.020373987033963203,
0.025456316769123077,
0.010917412117123604,
-0.04949769377708435,
0.005762714426964521,
-0.06620311737060547,
-0.009267938323318958,
-0.02672690898180008,
-0.04217000678181648,
0.05972544848918915,
-0.04093893617391586,
0.010055793449282646,
0.001722844084724784,
-0.004034356214106083,
0.06216084584593773,
-0.02795594185590744,
0.009591491892933846,
-0.0014410052681341767,
0.02866027131676674,
-0.05406878888607025,
0.09198664128780365,
-0.04964623972773552,
0.016068266704678535,
0.015196283347904682,
-0.02161293663084507,
-0.0945698469877243,
0.07705875486135483,
0.01064656488597393,
-0.07664415240287781,
-0.06552498787641525,
-0.058592792600393295,
0.015920419245958328,
0.024662459269165993,
0.043097514659166336,
-0.05951167270541191,
0.03710899502038956,
-0.01744122803211212,
-0.03965883329510689,
0.05826514959335327,
0.04989540949463844,
0.044831037521362305,
-0.0206639114767313,
-0.09909994155168533,
0.0692991316318512,
0.016704613342881203,
0.05197746679186821,
0.0466730073094368,
0.05987437441945076,
0.004498119931668043,
0.04574251547455788,
-0.026668816804885864,
-0.0525253601372242,
-0.008056898601353168,
-0.05718237906694412,
0.011761459521949291,
-0.02590153180062771,
-0.0634397566318512,
-0.05295836552977562,
-0.07197044789791107,
-0.000601692299824208,
-0.049429237842559814,
0.07416920363903046,
-0.06066668778657913,
-0.0803026631474495
] | 0.080554
|
# VM (executing JavaScript) > Stability: 2 - Stable The `node:vm` module enables compiling and running code within V8 Virtual Machine contexts. **The `node:vm` module is not a security mechanism. Do not use it to run untrusted code.** JavaScript code can be compiled and run immediately or compiled, saved, and run later. A common use case is to run the code in a different V8 Context. This means invoked code has a different global object than the invoking code. One can provide the context by [\_contextifying\_][contextified] an object. The invoked code treats any property in the context like a global variable. Any changes to global variables caused by the invoked code are reflected in the context object. ```js const vm = require('node:vm'); const x = 1; const context = { x: 2 }; vm.createContext(context); // Contextify the object. const code = 'x += 40; var y = 17;'; // `x` and `y` are global variables in the context. // Initially, x has the value 2 because that is the value of context.x. vm.runInContext(code, context); console.log(context.x); // 42 console.log(context.y); // 17 console.log(x); // 1; y is not defined. ``` ## Class: `vm.Script` Instances of the `vm.Script` class contain precompiled scripts that can be executed in specific contexts. ### `new vm.Script(code[, options])` \* `code` {string} The JavaScript code to compile. \* `options` {Object|string} \* `filename` {string} Specifies the filename used in stack traces produced by this script. \*\*Default:\*\* `'evalmachine.'`. \* `lineOffset` {number} Specifies the line number offset that is displayed in stack traces produced by this script. \*\*Default:\*\* `0`. \* `columnOffset` {number} Specifies the first-line column number offset that is displayed in stack traces produced by this script. \*\*Default:\*\* `0`. \* `cachedData` {Buffer|TypedArray|DataView} Provides an optional `Buffer` or `TypedArray`, or `DataView` with V8's code cache data for the supplied source. When supplied, the `cachedDataRejected` value will be set to either `true` or `false` depending on acceptance of the data by V8. \* `produceCachedData` {boolean} When `true` and no `cachedData` is present, V8 will attempt to produce code cache data for `code`. Upon success, a `Buffer` with V8's code cache data will be produced and stored in the `cachedData` property of the returned `vm.Script` instance. The `cachedDataProduced` value will be set to either `true` or `false` depending on whether code cache data is produced successfully. This option is \*\*deprecated\*\* in favor of `script.createCachedData()`. \*\*Default:\*\* `false`. \* `importModuleDynamically` {Function|vm.constants.USE\\_MAIN\\_CONTEXT\\_DEFAULT\\_LOADER} Used to specify how the modules should be loaded during the evaluation of this script when `import()` is called. This option is part of the experimental modules API. We do not recommend using it in a production environment. For detailed information, see [Support of dynamic `import()` in compilation APIs][]. If `options` is a string, then it specifies the filename. Creating a new `vm.Script` object compiles `code` but does not run it. The compiled `vm.Script` can be run later multiple times. The `code` is not bound to any global object; rather, it is bound before each run, just for that run. ### `script.cachedDataRejected` \* Type: {boolean|undefined} When `cachedData` is supplied to create the `vm.Script`, this value will be set to either `true` or `false` depending on acceptance of the data by V8. Otherwise the value is `undefined`. ### `script.createCachedData()` \* Returns: {Buffer} Creates a code cache that can be used with the `Script` constructor's `cachedData` option. Returns a `Buffer`. This method may be called at any time and any number of times. The code cache of the `Script` doesn't contain any JavaScript observable states. The code cache is safe to be saved along side the script source and used to construct new `Script` instances multiple times.
|
https://github.com/nodejs/node/blob/main//doc/api/vm.md
|
main
|
nodejs
|
[
-0.03583170846104622,
0.02360418438911438,
-0.023326953873038292,
0.045282088220119476,
0.08343680948019028,
-0.045921433717012405,
-0.005082903429865837,
0.01595771126449108,
-0.009462008252739906,
-0.05657178908586502,
0.005810425151139498,
0.02463754452764988,
0.0053144171833992004,
-0.06207356974482536,
0.0763716772198677,
0.03084595501422882,
0.09058435261249542,
0.05774356797337532,
-0.02944391965866089,
0.02102695219218731,
0.008484674617648125,
-0.0058135404251515865,
-0.025805359706282616,
-0.029012179002165794,
-0.004900981672108173,
0.020708218216896057,
-0.04402263090014458,
0.04107984900474548,
0.12132570892572403,
-0.00454162759706378,
0.017363157123327255,
-0.007401930168271065,
-0.07082274556159973,
0.03669765219092369,
-0.08591962605714798,
0.1196984052658081,
-0.06921115517616272,
-0.11229266971349716,
-0.043643247336149216,
0.003113249083980918,
-0.0285105649381876,
0.07031671702861786,
-0.1231640949845314,
-0.03303143382072449,
0.025922922417521477,
-0.006805177312344313,
-0.01763330027461052,
0.014175591059029102,
-0.0861838310956955,
0.0016576938796788454,
-0.01286994107067585,
-0.04687998816370964,
0.0072341435588896275,
-0.05827953293919563,
-0.08463379740715027,
-0.008822492323815823,
0.03839356079697609,
0.03592536598443985,
0.006695020478218794,
0.08666994422674179,
-0.023903867229819298,
0.03923638164997101,
0.017610179260373116,
0.0343748964369297,
0.06219793111085892,
-0.02120504342019558,
0.03935619071125984,
0.03309347480535507,
-0.0133308544754982,
-0.00813055969774723,
0.05632490664720535,
0.059482820332050323,
0.04590940475463867,
-0.0041081467643380165,
-0.03551112487912178,
-0.02772844210267067,
-0.06687705218791962,
-0.041571930050849915,
0.0686638206243515,
0.007375558838248253,
0.043008409440517426,
-0.013947761617600918,
-0.044801682233810425,
0.0402887761592865,
-0.031112220138311386,
0.07971865683794022,
0.03912824019789696,
-0.007837466895580292,
0.040459197014570236,
0.09195122867822647,
-0.0524732805788517,
-0.056104011833667755,
0.02152831107378006,
0.07070361077785492,
0.07540766894817352,
-0.050960324704647064,
0.00758448988199234,
-0.0034377379342913628,
0.041484054177999496,
-0.0023753726854920387,
-0.042964156717061996,
-0.019560549408197403,
0.01888037472963333,
0.028763538226485252,
0.0697142705321312,
0.051998455077409744,
-0.015969758853316307,
-0.017651205882430077,
0.005541544407606125,
0.02393282763659954,
0.010239727795124054,
0.09905507415533066,
0.011797187849879265,
-0.05187986046075821,
-0.01874520629644394,
0.008493687026202679,
0.09874402731657028,
-0.05636698007583618,
0.07813186943531036,
0.08771536499261856,
0.10600990802049637,
0.00997834000736475,
0.048641037195920944,
-0.02355140447616577,
-0.06576155871152878,
-0.09341608732938766,
0.008643201552331448,
3.617509661574694e-33,
-0.017445672303438187,
-0.11079226434230804,
-0.0013881210470572114,
0.08157815784215927,
0.050800345838069916,
0.04948186129331589,
-0.01729133352637291,
0.01227392815053463,
-0.1127694845199585,
0.0076097180135548115,
0.03364038094878197,
0.03326834738254547,
0.06305339932441711,
0.0056294105015695095,
0.07965551316738129,
-0.0007369326776824892,
0.063930943608284,
-0.008344962261617184,
0.0220333244651556,
0.010262131690979004,
-0.009299373254179955,
-0.07301583141088486,
-0.008366876281797886,
0.030467282980680466,
-0.020695215091109276,
-0.00048416180652566254,
-0.009767988696694374,
0.028141139075160027,
-0.026996426284313202,
0.006429120432585478,
-0.04017658159136772,
0.04261612147092819,
-0.048911307007074356,
0.10274486988782883,
-0.011751034297049046,
0.027349300682544708,
-0.02907703071832657,
-0.007022809237241745,
-0.08440665900707245,
-0.00743799889460206,
0.08015242964029312,
0.029917756095528603,
-0.007716634776443243,
-0.03482339531183243,
-0.03228229284286499,
-0.08245550841093063,
-0.05904655158519745,
0.018371157348155975,
-0.014259659685194492,
0.024368293583393097,
-0.07427166402339935,
0.0648036003112793,
0.006768412888050079,
-0.05218799039721489,
0.05931001529097557,
0.04045218974351883,
0.04049969092011452,
-0.02421775832772255,
-0.06728851795196533,
0.03195802867412567,
-0.030812593176960945,
-0.017024897038936615,
-0.017080014571547508,
0.04857633635401726,
-0.04357586428523064,
-0.004002503119409084,
-0.041317638009786606,
-0.07338816672563553,
0.005987795069813728,
0.02142302878201008,
-0.047067977488040924,
0.04070785269141197,
-0.04334794357419014,
0.0014079698594287038,
-0.003846981329843402,
-0.04124383628368378,
-0.07916300743818283,
0.040748462080955505,
-0.043123695999383926,
-0.04216394200921059,
0.03313697502017021,
0.03560713678598404,
-0.008076791651546955,
0.06738674640655518,
-0.0024171273689717054,
0.0007181749097071588,
-0.07382013648748398,
0.021327199414372444,
0.03275100886821747,
0.03614616394042969,
0.06057813763618469,
-0.1051236167550087,
0.017771676182746887,
-0.05912008881568909,
-0.10266603529453278,
-6.184822384549187e-33,
-0.06985297054052353,
0.04210289195179939,
-0.10808568447828293,
0.125151589512825,
-0.040449101477861404,
-0.05319051072001457,
-0.044761672616004944,
-0.014567366801202297,
-0.11694256216287613,
0.0010836066212505102,
-0.05565616860985756,
0.04502183571457863,
0.03798266127705574,
0.08135620504617691,
0.03206019103527069,
0.0519045926630497,
-0.058115627616643906,
-0.033904772251844406,
0.016578728333115578,
-0.06123485788702965,
0.03879350423812866,
0.003290534485131502,
0.051585499197244644,
-0.00009931559907272458,
-0.016987495124340057,
-0.0595335029065609,
-0.1360807567834854,
-0.039836447685956955,
0.002561510307714343,
0.02344411611557007,
-0.03100832924246788,
0.08700035512447357,
-0.0500529445707798,
0.03184770420193672,
0.0534786619246006,
-0.07293110340833664,
0.027938973158597946,
0.014866073615849018,
0.07463279366493225,
-0.0549120157957077,
0.03366928920149803,
0.014533068053424358,
0.008854023180902004,
-0.006635371595621109,
0.016724444925785065,
0.09154385328292847,
0.005155646707862616,
0.0016225954750552773,
0.0563991516828537,
-0.05158508941531181,
-0.0552784763276577,
-0.05076143890619278,
-0.01963808201253414,
0.03421847149729729,
-0.08497847616672516,
-0.0649690106511116,
-0.015835147351026535,
0.014465567655861378,
0.0822925865650177,
0.0434667207300663,
0.07013712078332901,
-0.09383711218833923,
-0.038855165243148804,
-0.019196631386876106,
-0.03938116505742073,
-0.020402628928422928,
-0.061229970306158066,
-0.015604976564645767,
0.09228780120611191,
-0.03248707205057144,
-0.03248657286167145,
-0.0307158250361681,
-0.016970038414001465,
-0.021827667951583862,
-0.10413570702075958,
-0.02141393907368183,
0.014754872769117355,
-0.1535520702600479,
-0.00003662990275188349,
0.020473213866353035,
0.037243012338876724,
0.016036730259656906,
-0.03011883795261383,
-0.02320394292473793,
-0.037025392055511475,
-0.0039861309342086315,
-0.0431307889521122,
0.0297706201672554,
-0.025153620168566704,
0.026624592021107674,
0.000607387803029269,
-0.0017160895513370633,
-0.191905677318573,
-0.03233839571475983,
-0.02972974255681038,
-5.398056401872964e-8,
-0.02624434605240822,
0.06783487647771835,
-0.0790112242102623,
-0.007500004954636097,
0.011628888547420502,
0.013662083074450493,
0.02779918722808361,
-0.0022224741987884045,
0.0859559029340744,
0.07694610953330994,
0.022933699190616608,
-0.01902615837752819,
0.02598903886973858,
-0.021099671721458435,
-0.027799149975180626,
0.0772789716720581,
-0.04453473538160324,
0.02377423271536827,
0.0010284129530191422,
0.008226176723837852,
0.050366636365652084,
0.024517333135008812,
-0.005003829952329397,
0.09651120007038116,
0.014899756759405136,
-0.058674126863479614,
0.06028783693909645,
0.06858696043491364,
0.022832931950688362,
-0.008243763819336891,
-0.07153228670358658,
0.11003778129816055,
-0.02768690325319767,
0.0104654710739851,
-0.14964108169078827,
0.0355728417634964,
-0.01789686270058155,
0.0006905123009346426,
0.07742846757173538,
-0.005550294183194637,
0.0433066226541996,
-0.007910827174782753,
-0.06447852402925491,
0.03989078477025032,
-0.04677748680114746,
0.053581029176712036,
0.08100128173828125,
-0.021576030179858208,
-0.026606542989611626,
-0.02134678140282631,
0.018391909077763557,
0.024554165080189705,
-0.0451454222202301,
0.0861324742436409,
-0.020690882578492165,
-0.0379028245806694,
0.017287878319621086,
-0.05223143473267555,
0.05523445084691048,
-0.022199619561433792,
-0.07307664304971695,
0.013017571531236172,
0.06646954268217087,
-0.08606045693159103
] | 0.113642
|
Returns a `Buffer`. This method may be called at any time and any number of times. The code cache of the `Script` doesn't contain any JavaScript observable states. The code cache is safe to be saved along side the script source and used to construct new `Script` instances multiple times. Functions in the `Script` source can be marked as lazily compiled and they are not compiled at construction of the `Script`. These functions are going to be compiled when they are invoked the first time. The code cache serializes the metadata that V8 currently knows about the `Script` that it can use to speed up future compilations. ```js const script = new vm.Script(` function add(a, b) { return a + b; } const x = add(1, 2); `); const cacheWithoutAdd = script.createCachedData(); // In `cacheWithoutAdd` the function `add()` is marked for full compilation // upon invocation. script.runInThisContext(); const cacheWithAdd = script.createCachedData(); // `cacheWithAdd` contains fully compiled function `add()`. ``` ### `script.runInContext(contextifiedObject[, options])` \* `contextifiedObject` {Object} A [contextified][] object as returned by the `vm.createContext()` method. \* `options` {Object} \* `displayErrors` {boolean} When `true`, if an [`Error`][] occurs while compiling the `code`, the line of code causing the error is attached to the stack trace. \*\*Default:\*\* `true`. \* `timeout` {integer} Specifies the number of milliseconds to execute `code` before terminating execution. If execution is terminated, an [`Error`][] will be thrown. This value must be a strictly positive integer. \* `breakOnSigint` {boolean} If `true`, receiving `SIGINT` (`Ctrl`+`C`) will terminate execution and throw an [`Error`][]. Existing handlers for the event that have been attached via `process.on('SIGINT')` are disabled during script execution, but continue to work after that. \*\*Default:\*\* `false`. \* Returns: {any} the result of the very last statement executed in the script. Runs the compiled code contained by the `vm.Script` object within the given `contextifiedObject` and returns the result. Running code does not have access to local scope. The following example compiles code that increments a global variable, sets the value of another global variable, then execute the code multiple times. The globals are contained in the `context` object. ```js const vm = require('node:vm'); const context = { animal: 'cat', count: 2, }; const script = new vm.Script('count += 1; name = "kitty";'); vm.createContext(context); for (let i = 0; i < 10; ++i) { script.runInContext(context); } console.log(context); // Prints: { animal: 'cat', count: 12, name: 'kitty' } ``` Using the `timeout` or `breakOnSigint` options will result in new event loops and corresponding threads being started, which have a non-zero performance overhead. ### `script.runInNewContext([contextObject[, options]])` \* `contextObject` {Object|vm.constants.DONT\\_CONTEXTIFY|undefined} Either [`vm.constants.DONT\_CONTEXTIFY`][] or an object that will be [contextified][]. If `undefined`, an empty contextified object will be created for backwards compatibility. \* `options` {Object} \* `displayErrors` {boolean} When `true`, if an [`Error`][] occurs while compiling the `code`, the line of code causing the error is attached to the stack trace. \*\*Default:\*\* `true`. \* `timeout` {integer} Specifies the number of milliseconds to execute `code` before terminating execution. If execution is terminated, an [`Error`][] will be thrown. This value must be a strictly positive integer. \* `breakOnSigint` {boolean} If `true`, receiving `SIGINT` (`Ctrl`+`C`) will terminate execution and throw an [`Error`][]. Existing handlers for the event that have been attached via `process.on('SIGINT')` are disabled during script execution, but continue to work after that. \*\*Default:\*\* `false`. \* `contextName` {string} Human-readable name of the newly created context. \*\*Default:\*\* `'VM Context i'`, where `i` is an ascending numerical index of the created context. \* `contextOrigin` {string} [Origin][origin] corresponding to the newly created context for display purposes. The origin should be formatted like a URL, but with only the scheme, host, and port
|
https://github.com/nodejs/node/blob/main//doc/api/vm.md
|
main
|
nodejs
|
[
-0.050956182181835175,
-0.011950979009270668,
-0.014448627829551697,
0.019646020606160164,
-0.02775370515882969,
0.016067996621131897,
-0.03946997970342636,
-0.007518511265516281,
0.049709122627973557,
0.010454783216118813,
-0.03514339029788971,
0.05701758340001106,
-0.08499385416507721,
-0.1067851111292839,
0.03843831270933151,
-0.01312231458723545,
0.042593829333782196,
-0.0384661965072155,
0.017981141805648804,
-0.08572965115308762,
0.04840865731239319,
-0.022847045212984085,
0.007088923826813698,
-0.04255086928606033,
0.11334609240293503,
0.007837138138711452,
-0.04433469474315643,
-0.06805677711963654,
0.07718725502490997,
0.0033455619122833014,
0.035590361803770065,
-0.05174557864665985,
-0.051277242600917816,
-0.017385350540280342,
-0.04603389650583267,
0.1190132349729538,
-0.04670407995581627,
-0.006501804571598768,
-0.0016621580580249429,
0.023439178243279457,
-0.05678390711545944,
0.08144312351942062,
-0.09623214602470398,
0.0047170259058475494,
0.05484002083539963,
-0.053486548364162445,
-0.021268265321850777,
-0.06437354534864426,
-0.08961551636457443,
0.002453241962939501,
0.026092832908034325,
0.028801316395401955,
-0.02941926196217537,
-0.01143765076994896,
0.021967334672808647,
-0.014491044916212559,
-0.04649040102958679,
0.047919970005750656,
-0.016340142115950584,
0.028676576912403107,
0.00570877268910408,
0.006308973301202059,
0.06489623337984085,
0.030284158885478973,
0.10436946898698807,
-0.036217015236616135,
0.06598641723394394,
0.008884190581738949,
0.022102244198322296,
0.01587693765759468,
-0.08184590190649033,
0.1065237820148468,
0.06333346664905548,
0.0029157507233321667,
-0.036094240844249725,
-0.021502098068594933,
-0.024265892803668976,
0.03289636969566345,
0.04899997636675835,
-0.08988942950963974,
-0.028230886906385422,
-0.0723094642162323,
-0.05669041723012924,
0.04294280707836151,
-0.012456911616027355,
0.07324983179569244,
0.05696661025285721,
0.016474008560180664,
0.10701137036085129,
0.028985509648919106,
-0.022340625524520874,
0.03579691797494888,
-0.018419627100229263,
0.023709408938884735,
-0.02950330823659897,
-0.011856460943818092,
-0.002288050949573517,
0.07394202053546906,
0.06461186707019806,
-0.011048078536987305,
0.01843751035630703,
0.04137827455997467,
0.047134559601545334,
0.04318718612194061,
0.026474757120013237,
0.0012985793873667717,
-0.030983587726950645,
-0.009338467381894588,
-0.04323501139879227,
0.03854801878333092,
0.011040467768907547,
0.057614486664533615,
0.06414473056793213,
-0.056091777980327606,
-0.020110415294766426,
0.06389861553907394,
0.044546350836753845,
-0.0544205941259861,
0.06578005105257034,
0.06575265526771545,
0.15388813614845276,
0.041909921914339066,
0.05953406170010567,
-0.014744632877409458,
-0.032911356538534164,
-0.06105756759643555,
0.01230581384152174,
2.664543554531766e-33,
0.0009216841426678002,
-0.050526101142168045,
-0.04328305274248123,
0.05371949076652527,
0.019790779799222946,
0.03398186340928078,
0.02699960023164749,
0.07090297341346741,
-0.13049882650375366,
0.02136051654815674,
0.01284840889275074,
-0.006016577128320932,
0.0346745103597641,
0.08825887739658356,
0.0036747942212969065,
0.022001519799232483,
0.05578640103340149,
-0.01928458735346794,
-0.005026743747293949,
-0.005006815306842327,
0.007962165400385857,
0.004507726989686489,
0.028212400153279305,
0.08501996099948883,
-0.03971137851476669,
0.03703594580292702,
0.07271046936511993,
0.033938515931367874,
-0.11907563358545303,
-0.00709543377161026,
-0.010273819789290428,
0.03669353947043419,
-0.11050247400999069,
0.03361506760120392,
0.0007721027941443026,
0.0003474638797342777,
-0.0012301773531362414,
-0.006662057247012854,
-0.03536193072795868,
0.02931481972336769,
0.04992847889661789,
0.009014014154672623,
-0.07792117446660995,
-0.06984838843345642,
-0.009371109306812286,
-0.09709249436855316,
-0.08199996501207352,
0.013521366752684116,
0.09211820363998413,
0.02788645029067993,
-0.01563364267349243,
0.04375559091567993,
0.04560336470603943,
0.0045209284871816635,
0.025445394217967987,
0.07546636462211609,
0.027479050680994987,
-0.04923877492547035,
0.0036654591094702482,
0.09479856491088867,
-0.022983064875006676,
-0.01909303106367588,
-0.04908836632966995,
0.07440117746591568,
-0.1120901107788086,
0.00689223175868392,
0.0042917244136333466,
-0.01876765489578247,
0.038812149316072464,
0.013285566121339798,
0.045037202537059784,
-0.005777773912996054,
-0.0021111334208399057,
-0.012913697399199009,
0.07869038730859756,
-0.07162200659513474,
-0.08337417244911194,
-0.01593744195997715,
-0.07547188550233841,
-0.04255232587456703,
0.05794064700603485,
0.02624562755227089,
-0.06753318011760712,
0.0538485050201416,
-0.017574679106473923,
-0.01159413531422615,
-0.06147989630699158,
0.017232920974493027,
0.06052122637629509,
0.06291841715574265,
-0.005934467539191246,
-0.09597597271203995,
0.03564128279685974,
-0.07527084648609161,
-0.036058880388736725,
-4.956843312988638e-33,
0.019384179264307022,
0.05209458991885185,
-0.09533083438873291,
0.10385339707136154,
-0.06270432472229004,
-0.02355196699500084,
-0.03353457897901535,
-0.0014608583878725767,
-0.05590483546257019,
-0.031463444232940674,
-0.06679867208003998,
0.031691938638687134,
-0.0071441191248595715,
0.06571078300476074,
0.03969067335128784,
0.030933761969208717,
-0.03376169130206108,
-0.08142571896314621,
0.02453041635453701,
-0.031749747693538666,
0.05781405046582222,
0.0033171456307172775,
0.11214680969715118,
0.020445767790079117,
0.015158107504248619,
-0.005748158786445856,
-0.05061358958482742,
-0.003902164986357093,
-0.06767694652080536,
-0.05447491630911827,
-0.06401507556438446,
0.06411642581224442,
-0.0796445980668068,
0.0008413950563408434,
0.06263036280870438,
-0.028092343360185623,
0.0767408162355423,
0.03616330772638321,
0.009503242559731007,
0.008207558654248714,
0.0224080141633749,
-0.03899236023426056,
0.033658333122730255,
0.011194175109267235,
0.028418835252523422,
0.061932481825351715,
-0.018765060231089592,
0.014162009581923485,
0.05220482498407364,
-0.03284839913249016,
0.026065519079566002,
-0.03354773670434952,
-0.07345712929964066,
0.03670063614845276,
-0.03692961856722832,
-0.030586818233132362,
-0.08916948735713959,
-0.05599971488118172,
0.11544181406497955,
0.09315259009599686,
-0.014974886551499367,
-0.11425991356372833,
0.03246493265032768,
-0.04862208664417267,
-0.04129607230424881,
-0.020928600803017616,
-0.07148904353380203,
-0.04845312237739563,
0.09570326656103134,
-0.007429344113916159,
-0.02135714516043663,
-0.04782138764858246,
-0.028586087748408318,
-0.029010988771915436,
-0.088435098528862,
0.012980670668184757,
0.0203214380890131,
-0.1778210997581482,
-0.017974933609366417,
0.00732734240591526,
-0.00008113535295706242,
0.014677925035357475,
0.0274979155510664,
-0.07306283712387085,
-0.030897781252861023,
-0.0017670729430392385,
-0.06024938076734543,
-0.008207764476537704,
-0.025075888261198997,
0.03338082507252693,
-0.02769388258457184,
0.058639127761125565,
-0.1393328309059143,
0.00878585409373045,
-0.04670801758766174,
-5.896472288213772e-8,
-0.0054598296992480755,
0.003977849148213863,
-0.07518228143453598,
0.0052330163307487965,
0.04059714078903198,
-0.04069015383720398,
-0.010715506970882416,
0.04107777401804924,
0.07255082577466965,
-0.07768404483795166,
0.09340541064739227,
-0.020227909088134766,
0.0343732126057148,
0.08072130382061005,
0.003943730611354113,
0.04018021374940872,
-0.03834998607635498,
-0.04964293912053108,
-0.05388191342353821,
-0.0296638160943985,
0.025587966665625572,
0.022823652252554893,
0.031918227672576904,
0.04032905772328377,
-0.015017721801996231,
-0.05718594789505005,
0.05492448806762695,
0.0235546063631773,
0.007751011289656162,
0.003436252474784851,
-0.048503078520298004,
0.10090155154466629,
0.04243224486708641,
-0.01244752760976553,
0.0007375896093435585,
-0.010332062840461731,
0.009327143430709839,
0.001512648887000978,
0.0907851830124855,
0.02294374816119671,
0.035874105989933014,
0.010909384116530418,
-0.029604515060782433,
0.055565815418958664,
0.012661670334637165,
-0.01885407418012619,
-0.09068655222654343,
-0.03763468563556671,
-0.046423833817243576,
-0.04167308285832405,
-0.013966390863060951,
0.01354933436959982,
-0.024682432413101196,
0.025301940739154816,
-0.05920557677745819,
-0.058262795209884644,
0.001418702071532607,
-0.10331713408231735,
0.05495033413171768,
0.01092261727899313,
-0.04173082113265991,
-0.0035034366883337498,
0.06614796072244644,
-0.11017518490552902
] | 0.07275
|
name of the newly created context. \*\*Default:\*\* `'VM Context i'`, where `i` is an ascending numerical index of the created context. \* `contextOrigin` {string} [Origin][origin] corresponding to the newly created context for display purposes. The origin should be formatted like a URL, but with only the scheme, host, and port (if necessary), like the value of the [`url.origin`][] property of a [`URL`][] object. Most notably, this string should omit the trailing slash, as that denotes a path. \*\*Default:\*\* `''`. \* `contextCodeGeneration` {Object} \* `strings` {boolean} If set to false any calls to `eval` or function constructors (`Function`, `GeneratorFunction`, etc) will throw an `EvalError`. \*\*Default:\*\* `true`. \* `wasm` {boolean} If set to false any attempt to compile a WebAssembly module will throw a `WebAssembly.CompileError`. \*\*Default:\*\* `true`. \* `microtaskMode` {string} If set to `afterEvaluate`, microtasks (tasks scheduled through `Promise`s and `async function`s) will be run immediately after the script has run. They are included in the `timeout` and `breakOnSigint` scopes in that case. \* Returns: {any} the result of the very last statement executed in the script. This method is a shortcut to `script.runInContext(vm.createContext(options), options)`. It does several things at once: 1. Creates a new context. 2. If `contextObject` is an object, [contextifies][contextified] it with the new context. If `contextObject` is undefined, creates a new object and [contextifies][contextified] it. If `contextObject` is [`vm.constants.DONT\_CONTEXTIFY`][], don't [contextify][contextified] anything. 3. Runs the compiled code contained by the `vm.Script` object within the created context. The code does not have access to the scope in which this method is called. 4. Returns the result. The following example compiles code that sets a global variable, then executes the code multiple times in different contexts. The globals are set on and contained within each individual `context`. ```js const vm = require('node:vm'); const script = new vm.Script('globalVar = "set"'); const contexts = [{}, {}, {}]; contexts.forEach((context) => { script.runInNewContext(context); }); console.log(contexts); // Prints: [{ globalVar: 'set' }, { globalVar: 'set' }, { globalVar: 'set' }] // This would throw if the context is created from a contextified object. // vm.constants.DONT\_CONTEXTIFY allows creating contexts with ordinary // global objects that can be frozen. const freezeScript = new vm.Script('Object.freeze(globalThis); globalThis;'); const frozenContext = freezeScript.runInNewContext(vm.constants.DONT\_CONTEXTIFY); ``` ### `script.runInThisContext([options])` \* `options` {Object} \* `displayErrors` {boolean} When `true`, if an [`Error`][] occurs while compiling the `code`, the line of code causing the error is attached to the stack trace. \*\*Default:\*\* `true`. \* `timeout` {integer} Specifies the number of milliseconds to execute `code` before terminating execution. If execution is terminated, an [`Error`][] will be thrown. This value must be a strictly positive integer. \* `breakOnSigint` {boolean} If `true`, receiving `SIGINT` (`Ctrl`+`C`) will terminate execution and throw an [`Error`][]. Existing handlers for the event that have been attached via `process.on('SIGINT')` are disabled during script execution, but continue to work after that. \*\*Default:\*\* `false`. \* Returns: {any} the result of the very last statement executed in the script. Runs the compiled code contained by the `vm.Script` within the context of the current `global` object. Running code does not have access to local scope, but \_does\_ have access to the current `global` object. The following example compiles code that increments a `global` variable then executes that code multiple times: ```js const vm = require('node:vm'); global.globalVar = 0; const script = new vm.Script('globalVar += 1', { filename: 'myfile.vm' }); for (let i = 0; i < 1000; ++i) { script.runInThisContext(); } console.log(globalVar); // 1000 ``` ### `script.sourceMapURL` \* Type: {string|undefined} When the script is compiled from a source that contains a source map magic comment, this property will be set to the URL of the source map. ```mjs import vm
|
https://github.com/nodejs/node/blob/main//doc/api/vm.md
|
main
|
nodejs
|
[
-0.02475760318338871,
0.04916179180145264,
-0.0626131221652031,
0.0346217080950737,
-0.03884880244731903,
-0.09304077178239822,
0.04688749462366104,
0.023637356236577034,
-0.040682632476091385,
-0.008005978539586067,
0.016411934047937393,
-0.08693907409906387,
0.028971778228878975,
0.03657868877053261,
0.059513598680496216,
0.09995236247777939,
0.040554292500019073,
0.03255651891231537,
-0.028337033465504646,
0.08555860817432404,
0.0859164372086525,
0.1134866252541542,
0.00461496552452445,
-0.046172186732292175,
0.04268023371696472,
-0.006324931047856808,
0.003977659158408642,
0.0455041378736496,
0.13905110955238342,
0.034836381673812866,
0.032806504517793655,
0.05015471950173378,
-0.03934908285737038,
0.0038811471313238144,
0.09452442824840546,
0.10491284728050232,
0.027009282261133194,
-0.06619725376367569,
-0.014848324470221996,
0.015370402485132217,
0.09041044861078262,
0.02762523852288723,
-0.03972037136554718,
-0.05967896804213524,
-0.09180299192667007,
-0.006773295812308788,
0.02297077886760235,
-0.007990500889718533,
-0.09804237633943558,
-0.043715521693229675,
-0.08410972356796265,
-0.022208036854863167,
-0.05897805467247963,
-0.07595540583133698,
0.024172814562916756,
0.0005124246818013489,
0.006649313028901815,
0.038243383169174194,
-0.0068847136572003365,
0.016965001821517944,
0.019542956724762917,
0.02117847464978695,
-0.007961497642099857,
0.005547693930566311,
-0.011752412654459476,
-0.0016655339859426022,
-0.015512745827436447,
-0.0010580748785287142,
0.04023498669266701,
-0.054147813469171524,
-0.10217785090208054,
-0.02549956925213337,
-0.08256129175424576,
0.0870232954621315,
0.0009689019061625004,
0.03321385756134987,
0.006583438720554113,
0.021315738558769226,
0.021384410560131073,
-0.07805977761745453,
0.08586838841438293,
-0.020964009687304497,
0.03674248605966568,
0.01922648772597313,
0.03797701373696327,
0.010241723619401455,
-0.006462868768721819,
-0.017092622816562653,
0.05866052582859993,
0.09715217351913452,
-0.04329664260149002,
-0.12633775174617767,
0.04869865998625755,
0.028498450294137,
0.07604032009840012,
-0.01591324619948864,
-0.028651924803853035,
-0.026220353320240974,
0.027866408228874207,
0.04900765046477318,
-0.011741552501916885,
-0.0759502500295639,
0.0217225831001997,
-0.01559936348348856,
0.0658467561006546,
0.07650666683912277,
-0.012385625392198563,
0.07524396479129791,
0.026754427701234818,
-0.022431639954447746,
-0.02470172569155693,
0.05997450649738312,
-0.03656011074781418,
-0.09301567077636719,
-0.038266729563474655,
-0.025796184316277504,
0.042176928371191025,
-0.024449186399579048,
0.029514534398913383,
0.1384313851594925,
0.0700242891907692,
-0.08194118738174438,
-0.014973069541156292,
-0.03778936713933945,
-0.09540501236915588,
-0.0949510782957077,
0.016450967639684677,
1.8888936071416796e-33,
-0.009807032532989979,
-0.02920534648001194,
0.01536643411964178,
0.024277182295918465,
0.08029510080814362,
0.018264366313815117,
0.007262200582772493,
0.03368552401661873,
-0.020573418587446213,
-0.018947619944810867,
-0.01387267280369997,
0.02895268425345421,
0.005374439526349306,
0.007438078988343477,
-0.00964167807251215,
-0.003897526301443577,
0.05364282801747322,
0.014188534580171108,
0.03478704020380974,
-0.010004276409745216,
-0.020674459636211395,
0.02913179062306881,
-0.022162793204188347,
-0.09665226191282272,
-0.06164044141769409,
0.0186926256865263,
0.008550883270800114,
-0.04805440455675125,
-0.06852315366268158,
0.0036836168728768826,
-0.03429747372865677,
-0.034098610281944275,
0.0032883340027183294,
0.07160162180662155,
0.020874975249171257,
0.08631380647420883,
0.0366215854883194,
-0.024154899641871452,
-0.11632929742336273,
-0.00731513649225235,
-0.026706160977482796,
0.008204289712011814,
-0.04237324371933937,
0.06401051580905914,
-0.03971829637885094,
-0.10026364028453827,
-0.09469533711671829,
0.04321189224720001,
0.016271384432911873,
0.033369969576597214,
-0.05849902704358101,
0.04746932536363602,
0.07662409543991089,
0.003367551602423191,
-0.00638623209670186,
-0.01966812089085579,
-0.046285584568977356,
0.007599532138556242,
0.015968777239322662,
-0.024945566430687904,
-0.04592333361506462,
0.05011461675167084,
-0.02768813818693161,
0.07974090427160263,
0.0017223884351551533,
-0.040795646607875824,
0.047319427132606506,
-0.05942989140748978,
0.015633361414074898,
-0.022606398910284042,
-0.07694443315267563,
0.04339136928319931,
-0.07930479198694229,
0.03269398584961891,
-0.02301768586039543,
-0.06405317783355713,
-0.02420852892100811,
-0.01962379179894924,
-0.04045657441020012,
-0.04663180932402611,
0.02424105629324913,
0.03484807536005974,
0.008238984271883965,
-0.011976996436715126,
-0.03389081731438637,
-0.011427408084273338,
-0.04444142431020737,
-0.04896409064531326,
0.02640463411808014,
-0.12830685079097748,
0.03233787417411804,
-0.12204822152853012,
-0.04940146207809448,
-0.021534625440835953,
-0.04492836445569992,
-4.7735947639549825e-33,
0.08656446635723114,
0.029622605070471764,
-0.05326082184910774,
0.05572230741381645,
-0.05411691218614578,
-0.0911758616566658,
0.10737047344446182,
0.037626009434461594,
-0.11855778843164444,
-0.014345435425639153,
0.0531914122402668,
0.07052447646856308,
0.07377692312002182,
0.036468133330345154,
0.054256871342659,
0.07129611074924469,
-0.02284545823931694,
-0.10263345390558243,
0.026977654546499252,
-0.037729933857917786,
0.021902423352003098,
0.043920520693063736,
-0.07223278284072876,
-0.009543186984956264,
-0.11243444681167603,
-0.012633202597498894,
-0.013776406645774841,
-0.09677105396986008,
-0.03743964433670044,
0.09316736459732056,
0.025676017627120018,
0.08399630337953568,
-0.042597707360982895,
-0.00024721951922401786,
-0.012157878838479519,
0.01638702116906643,
0.0032777239102870226,
0.016636477783322334,
0.011783776804804802,
-0.04658783972263336,
0.05342549458146095,
0.06462756544351578,
0.015026073902845383,
0.050711311399936676,
-0.021364815533161163,
0.016892988234758377,
0.0005903833080083132,
-0.012290545739233494,
0.04723195359110832,
-0.027769438922405243,
-0.000361768965376541,
-0.045069046318531036,
-0.014469772577285767,
-0.0014599653659388423,
-0.057288430631160736,
-0.04986078664660454,
-0.021886173635721207,
-0.015819743275642395,
-0.03750351071357727,
0.0006216440815478563,
0.030643032863736153,
0.01354831364005804,
-0.0424509234726429,
-0.020299943163990974,
0.02732722833752632,
-0.017394382506608963,
-0.07899732887744904,
-0.012278578244149685,
-0.023803550750017166,
-0.15105046331882477,
-0.012053546495735645,
0.0019356344128027558,
-0.09373683482408524,
0.006375787779688835,
-0.019502120092511177,
0.017626717686653137,
0.0633101537823677,
-0.00352034205570817,
0.019700447097420692,
0.09683079272508621,
0.05695461109280586,
-0.0026405630633234978,
-0.029985904693603516,
0.0010618172818794847,
-0.025600798428058624,
-0.06612682342529297,
-0.05367940291762352,
0.11710088700056076,
-0.0598849356174469,
0.016321619972586632,
-0.014156445860862732,
0.027887661010026932,
-0.11342112720012665,
0.05769938975572586,
-0.015768108889460564,
-5.786594314827198e-8,
-0.13139623403549194,
0.04217975214123726,
-0.06656034290790558,
0.006021685432642698,
-0.02568446844816208,
0.05973944067955017,
-0.008828607387840748,
-0.01874978467822075,
0.06871011108160019,
0.007108301855623722,
-0.013274281285703182,
0.01790260709822178,
-0.036510806530714035,
-0.0012119011953473091,
-0.043037667870521545,
0.028056146577000618,
-0.05573355033993721,
0.05125017464160919,
-0.009198631159961224,
0.02017640322446823,
0.018035782501101494,
-0.01257895864546299,
0.012965303845703602,
-0.06123516336083412,
0.052174124866724014,
-0.027337463572621346,
-0.010943309403955936,
0.08194974064826965,
-0.005239203106611967,
0.02713671326637268,
0.019595779478549957,
0.07449620962142944,
-0.08402319997549057,
0.0076219867914915085,
-0.1667230874300003,
0.10277385264635086,
-0.02986009232699871,
-0.04798279330134392,
0.023524167016148567,
-0.01630501262843609,
0.05978872627019882,
-0.018759822472929955,
0.015280178748071194,
0.01643185503780842,
0.0013292800867930055,
0.023839838802814484,
0.06083253026008606,
0.04629610851407051,
0.011401926167309284,
-0.06500017642974854,
-0.013583124615252018,
0.01700294390320778,
-0.05981045961380005,
0.03847366198897362,
0.017794011160731316,
-0.0071615297347307205,
-0.02265831269323826,
0.04830389469861984,
0.013240130618214607,
0.05601411312818527,
-0.011671045795083046,
0.046511828899383545,
0.032742939889431,
-0.038679059594869614
] | 0.118169
|
(let i = 0; i < 1000; ++i) { script.runInThisContext(); } console.log(globalVar); // 1000 ``` ### `script.sourceMapURL` \* Type: {string|undefined} When the script is compiled from a source that contains a source map magic comment, this property will be set to the URL of the source map. ```mjs import vm from 'node:vm'; const script = new vm.Script(` function myFunc() {} //# sourceMappingURL=sourcemap.json `); console.log(script.sourceMapURL); // Prints: sourcemap.json ``` ```cjs const vm = require('node:vm'); const script = new vm.Script(` function myFunc() {} //# sourceMappingURL=sourcemap.json `); console.log(script.sourceMapURL); // Prints: sourcemap.json ``` ## Class: `vm.Module` > Stability: 1 - Experimental This feature is only available with the `--experimental-vm-modules` command flag enabled. The `vm.Module` class provides a low-level interface for using ECMAScript modules in VM contexts. It is the counterpart of the `vm.Script` class that closely mirrors [Module Record][]s as defined in the ECMAScript specification. Unlike `vm.Script` however, every `vm.Module` object is bound to a context from its creation. Using a `vm.Module` object requires three distinct steps: creation/parsing, linking, and evaluation. These three steps are illustrated in the following example. This implementation lies at a lower level than the [ECMAScript Module loader][]. There is also no way to interact with the Loader yet, though support is planned. ```mjs import vm from 'node:vm'; const contextifiedObject = vm.createContext({ secret: 42, print: console.log, }); // Step 1 // // Create a Module by constructing a new `vm.SourceTextModule` object. This // parses the provided source text, throwing a `SyntaxError` if anything goes // wrong. By default, a Module is created in the top context. But here, we // specify `contextifiedObject` as the context this Module belongs to. // // Here, we attempt to obtain the default export from the module "foo", and // put it into local binding "secret". const rootModule = new vm.SourceTextModule(` import s from 'foo'; s; print(s); `, { context: contextifiedObject }); // Step 2 // // "Link" the imported dependencies of this Module to it. // // Obtain the requested dependencies of a SourceTextModule by // `sourceTextModule.moduleRequests` and resolve them. // // Even top-level Modules without dependencies must be explicitly linked. The // array passed to `sourceTextModule.linkRequests(modules)` can be // empty, however. // // Note: This is a contrived example in that the resolveAndLinkDependencies // creates a new "foo" module every time it is called. In a full-fledged // module system, a cache would probably be used to avoid duplicated modules. const moduleMap = new Map([ ['root', rootModule], ]); function resolveAndLinkDependencies(module) { const requestedModules = module.moduleRequests.map((request) => { // In a full-fledged module system, the resolveAndLinkDependencies would // resolve the module with the module cache key `[specifier, attributes]`. // In this example, we just use the specifier as the key. const specifier = request.specifier; let requestedModule = moduleMap.get(specifier); if (requestedModule === undefined) { requestedModule = new vm.SourceTextModule(` // The "secret" variable refers to the global variable we added to // "contextifiedObject" when creating the context. export default secret; `, { context: module.context }); moduleMap.set(specifier, requestedModule); // Resolve the dependencies of the new module as well. resolveAndLinkDependencies(requestedModule); } return requestedModule; }); module.linkRequests(requestedModules); } resolveAndLinkDependencies(rootModule); rootModule.instantiate(); // Step 3 // // Evaluate the Module. The evaluate() method returns a promise which will // resolve after the module has finished evaluating. // Prints 42. await rootModule.evaluate(); ``` ```cjs const vm = require('node:vm'); const contextifiedObject = vm.createContext({ secret: 42, print: console.log, }); (async () => { // Step 1 // // Create a Module by constructing a new `vm.SourceTextModule` object. This // parses the provided source text, throwing a `SyntaxError` if anything goes // wrong. By default, a Module is created in the top context. But here, we
|
https://github.com/nodejs/node/blob/main//doc/api/vm.md
|
main
|
nodejs
|
[
-0.012359373271465302,
0.04443041980266571,
0.020644396543502808,
0.011442395858466625,
0.03232046589255333,
0.0011858619982376695,
-0.014355611056089401,
0.031112385913729668,
-0.018003325909376144,
-0.040610626339912415,
0.001688101445324719,
-0.03567636385560036,
-0.04023874178528786,
-0.07486981153488159,
0.038099877536296844,
0.12572374939918518,
0.01687614433467388,
0.03973165899515152,
0.011030337773263454,
-0.007577879820019007,
0.09466762840747833,
0.021902481094002724,
0.016131585463881493,
0.006447221618145704,
0.0711970329284668,
0.0002534158411435783,
-0.02565412037074566,
0.017732130363583565,
0.046887148171663284,
0.008090472780168056,
0.014404518529772758,
0.00539796706289053,
-0.1304755061864853,
0.016978228464722633,
0.007405999582260847,
0.15729141235351562,
-0.07912307977676392,
-0.03958731144666672,
0.05150732398033142,
0.02908802218735218,
-0.005578612443059683,
0.09455416351556778,
-0.06099741905927658,
-0.0628214105963707,
0.025713251903653145,
-0.023483801633119583,
0.03690524026751518,
-0.005214930046349764,
-0.07339762896299362,
0.02525634504854679,
-0.07132560014724731,
0.012781769968569279,
-0.07815320044755936,
-0.10713235288858414,
-0.0062240054830908775,
0.016305847093462944,
-0.020738711580634117,
0.03560972958803177,
0.059716396033763885,
0.07207052409648895,
-0.02871444821357727,
0.008755232207477093,
0.02890152856707573,
-0.02711264044046402,
0.06426719576120377,
-0.0362367145717144,
-0.021067075431346893,
0.06415373086929321,
-0.013796229846775532,
-0.006011491641402245,
-0.004722336307168007,
-0.009832535870373249,
0.04848700761795044,
0.008503982797265053,
-0.002407703548669815,
-0.001235651085153222,
-0.09706303477287292,
0.01197369210422039,
0.038259029388427734,
-0.05342580005526543,
0.0029181467834860086,
-0.07817065715789795,
0.00645656231790781,
0.08082824945449829,
0.027216343209147453,
0.06925545632839203,
0.08459635823965073,
0.03333328664302826,
0.11946412175893784,
0.04235418885946274,
-0.07801572233438492,
-0.11897516250610352,
-0.030196012929081917,
0.08045066893100739,
0.09599468857049942,
0.002828510943800211,
-0.03282340243458748,
-0.05173526704311371,
0.0595565065741539,
0.046699948608875275,
-0.039995841681957245,
0.009647884406149387,
0.06518245488405228,
-0.015888197347521782,
0.061599913984537125,
0.026718277484178543,
0.017034536227583885,
0.029153183102607727,
-0.04464798420667648,
0.02906634658575058,
0.0065139420330524445,
0.07626420259475708,
-0.01121922954916954,
-0.11051779985427856,
-0.030148539692163467,
-0.01784597896039486,
0.06657594442367554,
-0.08045057207345963,
0.0501318983733654,
0.06454456597566605,
0.11395039409399033,
-0.035395435988903046,
0.03876611217856407,
-0.004733033012598753,
-0.0679338350892067,
-0.06325165927410126,
0.017852315679192543,
3.762610847530274e-33,
0.03537597134709358,
-0.043665025383234024,
0.0013190401950851083,
0.07251876592636108,
0.050738174468278885,
-0.0067763798870146275,
0.07138711959123611,
-0.07819337397813797,
-0.16016751527786255,
-0.051188863813877106,
-0.031333908438682556,
0.009484639391303062,
-0.02315758541226387,
0.06569172441959381,
-0.13071607053279877,
0.024762040004134178,
0.09138279408216476,
-0.017928138375282288,
-0.01094247866421938,
-0.049290210008621216,
0.011684068478643894,
0.023815616965293884,
0.004343879409134388,
-0.00927618145942688,
-0.010159780271351337,
0.02889327146112919,
-0.02447325363755226,
0.06406395137310028,
-0.08381345123052597,
-0.017768962308764458,
0.10868658125400543,
0.006201164331287146,
0.03780578076839447,
0.03487340733408928,
0.09057124704122543,
-0.0032582797575742006,
-0.036114566028118134,
0.006778433918952942,
-0.0813865140080452,
0.03936498239636421,
0.07188978791236877,
-0.0214647576212883,
-0.06719252467155457,
-0.06486979871988297,
-0.030894169583916664,
-0.03803959861397743,
-0.12396764010190964,
0.039290014654397964,
-0.0015339866513386369,
-0.019449884071946144,
-0.028145967051386833,
0.1124856173992157,
-0.014062046073377132,
-0.00330391526222229,
0.05502397567033768,
-0.026828529313206673,
-0.03792194277048111,
-0.08311343938112259,
0.0051956321112811565,
0.03207650035619736,
-0.09918452054262161,
0.05591724067926407,
0.00035547089646570385,
0.049954526126384735,
-0.010455530136823654,
-0.013076109811663628,
-0.05507727712392807,
-0.01784345880150795,
-0.012129685841500759,
-0.017157508060336113,
0.027557101100683212,
0.0035762828774750233,
-0.01663118042051792,
0.033626411110162735,
0.031393688172101974,
-0.028576381504535675,
-0.18119092285633087,
0.017535006627440453,
-0.06713342666625977,
-0.016270987689495087,
-0.028850408270955086,
0.0038842912763357162,
-0.0690019428730011,
0.047058429569005966,
0.014888012781739235,
-0.0037373569793999195,
-0.10030680149793625,
-0.05495529994368553,
0.06656057387590408,
0.05011294409632683,
0.013760167174041271,
-0.07187066972255707,
-0.048444271087646484,
-0.06738266348838806,
-0.05860999599099159,
-7.013563534294162e-33,
0.0037727842573076487,
0.036175426095724106,
-0.010815025307238102,
0.0966528058052063,
-0.07867790758609772,
-0.017426490783691406,
0.05516204237937927,
0.0008412976167164743,
-0.002381008816882968,
0.14914387464523315,
-0.04770580679178238,
0.025521334260702133,
0.020522572100162506,
-0.00844823382794857,
0.007149493787437677,
0.03445321321487427,
-0.006237868685275316,
-0.01628357358276844,
0.04713764041662216,
-0.00040385121246799827,
0.005300471093505621,
0.05884416401386261,
0.047802530229091644,
-0.006078899372369051,
-0.036778468638658524,
-0.02381042391061783,
-0.03552507981657982,
0.005537834484130144,
-0.07298059016466141,
-0.01693664863705635,
-0.03288562595844269,
0.0673443153500557,
-0.08934778720140457,
-0.05909392237663269,
0.007223262917250395,
-0.006261113565415144,
0.020579876378178596,
0.07701265811920166,
-0.029482314363121986,
-0.023815160617232323,
0.029538732022047043,
-0.017332756891846657,
-0.05038795992732048,
-0.03960094228386879,
-0.020333504304289818,
-0.008547422476112843,
0.05164489895105362,
0.007762219291180372,
0.03837985172867775,
-0.05929854139685631,
0.041802920401096344,
-0.0927376076579094,
0.027530137449502945,
-0.05450977757573128,
-0.017699291929602623,
-0.03521912544965744,
-0.032244760543107986,
0.028644902631640434,
0.049588676542043686,
0.06907162070274353,
-0.01903384178876877,
-0.1723773181438446,
-0.011421420611441135,
-0.02366396225988865,
-0.00509641831740737,
0.0032199127599596977,
-0.0741235762834549,
0.03260309621691704,
0.08001528680324554,
-0.029176849871873856,
0.030239982530474663,
-0.002083598403260112,
0.04815883934497833,
0.012790003791451454,
0.00885550957173109,
0.000021218776964815333,
0.03909663110971451,
-0.0013752089580520988,
0.03434482216835022,
0.016574745997786522,
0.08335976302623749,
0.006641534622758627,
0.007236937526613474,
0.004084655083715916,
0.04170028492808342,
0.014465071260929108,
-0.030434971675276756,
0.022746002301573753,
-0.053984351456165314,
-0.037030111998319626,
0.005638744682073593,
0.033520136028528214,
-0.10584685951471329,
0.009107575751841068,
-0.04085785523056984,
-5.765103949784134e-8,
-0.08076045662164688,
0.015329152345657349,
-0.07598316669464111,
0.004080891143530607,
-0.016814270988106728,
0.016628587618470192,
0.08070643991231918,
0.015572364442050457,
0.03991250693798065,
0.04706417769193649,
0.032280243933200836,
0.03199310973286629,
0.06674824655056,
0.011985301971435547,
-0.03262380510568619,
-0.04033637046813965,
-0.05335424840450287,
0.08432063460350037,
-0.012484446167945862,
0.013661995530128479,
-0.06462360173463821,
0.027700956910848618,
0.02531423047184944,
0.019728947430849075,
0.0875968411564827,
-0.08337654918432236,
0.038726359605789185,
0.023675402626395226,
-0.04735927656292915,
0.012760684825479984,
-0.006966267712414265,
0.07945048809051514,
-0.05786915123462677,
-0.052085548639297485,
-0.13414017856121063,
-0.02642841450870037,
0.05935994163155556,
-0.04863538220524788,
0.06700261682271957,
0.021018536761403084,
0.0077435472048819065,
0.003353022737428546,
-0.02265787124633789,
-0.016632571816444397,
-0.0742381364107132,
-0.018353112041950226,
-0.040339816361665726,
-0.004253039602190256,
-0.00713519798591733,
0.025730008259415627,
-0.009206864982843399,
0.017016921192407608,
-0.048442814499139786,
-0.01015730295330286,
0.007746333722025156,
-0.05702013522386551,
-0.024152204394340515,
-0.04046815633773804,
-0.047273505479097366,
-0.00032156603992916644,
-0.01398654468357563,
-0.007948573678731918,
0.025787025690078735,
-0.06700966507196426
] | 0.003182
|
42, print: console.log, }); (async () => { // Step 1 // // Create a Module by constructing a new `vm.SourceTextModule` object. This // parses the provided source text, throwing a `SyntaxError` if anything goes // wrong. By default, a Module is created in the top context. But here, we // specify `contextifiedObject` as the context this Module belongs to. // // Here, we attempt to obtain the default export from the module "foo", and // put it into local binding "secret". const rootModule = new vm.SourceTextModule(` import s from 'foo'; s; print(s); `, { context: contextifiedObject }); // Step 2 // // "Link" the imported dependencies of this Module to it. // // Obtain the requested dependencies of a SourceTextModule by // `sourceTextModule.moduleRequests` and resolve them. // // Even top-level Modules without dependencies must be explicitly linked. The // array passed to `sourceTextModule.linkRequests(modules)` can be // empty, however. // // Note: This is a contrived example in that the resolveAndLinkDependencies // creates a new "foo" module every time it is called. In a full-fledged // module system, a cache would probably be used to avoid duplicated modules. const moduleMap = new Map([ ['root', rootModule], ]); function resolveAndLinkDependencies(module) { const requestedModules = module.moduleRequests.map((request) => { // In a full-fledged module system, the resolveAndLinkDependencies would // resolve the module with the module cache key `[specifier, attributes]`. // In this example, we just use the specifier as the key. const specifier = request.specifier; let requestedModule = moduleMap.get(specifier); if (requestedModule === undefined) { requestedModule = new vm.SourceTextModule(` // The "secret" variable refers to the global variable we added to // "contextifiedObject" when creating the context. export default secret; `, { context: module.context }); moduleMap.set(specifier, requestedModule); // Resolve the dependencies of the new module as well. resolveAndLinkDependencies(requestedModule); } return requestedModule; }); module.linkRequests(requestedModules); } resolveAndLinkDependencies(rootModule); rootModule.instantiate(); // Step 3 // // Evaluate the Module. The evaluate() method returns a promise which will // resolve after the module has finished evaluating. // Prints 42. await rootModule.evaluate(); })(); ``` ### `module.error` \* Type: {any} If the `module.status` is `'errored'`, this property contains the exception thrown by the module during evaluation. If the status is anything else, accessing this property will result in a thrown exception. The value `undefined` cannot be used for cases where there is not a thrown exception due to possible ambiguity with `throw undefined;`. Corresponds to the `[[EvaluationError]]` field of [Cyclic Module Record][]s in the ECMAScript specification. ### `module.evaluate([options])` \* `options` {Object} \* `timeout` {integer} Specifies the number of milliseconds to evaluate before terminating execution. If execution is interrupted, an [`Error`][] will be thrown. This value must be a strictly positive integer. \* `breakOnSigint` {boolean} If `true`, receiving `SIGINT` (`Ctrl`+`C`) will terminate execution and throw an [`Error`][]. Existing handlers for the event that have been attached via `process.on('SIGINT')` are disabled during script execution, but continue to work after that. \*\*Default:\*\* `false`. \* Returns: {Promise} Fulfills with `undefined` upon success. Evaluate the module and its depenendencies. Corresponds to the [Evaluate() concrete method][] field of [Cyclic Module Record][]s in the ECMAScript specification. If the module is a `vm.SourceTextModule`, `evaluate()` must be called after the module has been instantiated; otherwise `evaluate()` will return a rejected promise. For a `vm.SourceTextModule`, the promise returned by `evaluate()` may be fulfilled either synchronously or asynchronously: 1. If the `vm.SourceTextModule` has no top-level `await` in itself or any of its dependencies, the promise will be fulfilled \_synchronously\_ after the module and all its dependencies have been evaluated. 1. If the evaluation succeeds, the promise will be \_synchronously\_ resolved to `undefined`. 2. If the evaluation results in an exception, the promise will be
|
https://github.com/nodejs/node/blob/main//doc/api/vm.md
|
main
|
nodejs
|
[
-0.08169008791446686,
0.008357805199921131,
-0.053382426500320435,
0.09365356713533401,
0.02971314638853073,
-0.01807921938598156,
0.05643358454108238,
0.06871334463357925,
-0.03948216140270233,
-0.06067808344960213,
0.024734562262892723,
-0.09184708446264267,
0.010588987730443478,
0.009305796585977077,
0.11539999395608902,
0.06450464576482773,
0.08602581173181534,
0.0526682548224926,
-0.022661758586764336,
0.0609220452606678,
0.055576253682374954,
0.07628364115953445,
0.06581778079271317,
-0.027758724987506866,
0.049221884459257126,
0.016705816611647606,
-0.04834854230284691,
-0.056311123073101044,
0.11155544221401215,
0.01768025942146778,
-0.0051953960210084915,
0.11361290514469147,
-0.027244091033935547,
0.01260805781930685,
0.05602104216814041,
0.17436063289642334,
-0.004422696307301521,
-0.07150940597057343,
0.02242838405072689,
-0.01125173456966877,
0.06996212899684906,
0.11504220217466354,
-0.08692117780447006,
-0.03385845199227333,
-0.05564723163843155,
-0.04123738780617714,
0.0017854386242106557,
0.05335225909948349,
-0.07612986862659454,
-0.0030712673906236887,
-0.04463736712932587,
-0.026671970263123512,
-0.04236125946044922,
-0.05575726926326752,
-0.026922963559627533,
0.0686689242720604,
0.04835372790694237,
0.018575578927993774,
0.007016182877123356,
0.050861988216638565,
-0.00445095868781209,
0.06370991468429565,
-0.046743832528591156,
-0.015555443242192268,
0.028276536613702774,
0.00387284392490983,
0.02339429408311844,
0.03087007813155651,
-0.002716145943850279,
-0.003920328803360462,
-0.08444800227880478,
-0.027449389919638634,
0.018334705382585526,
0.06705521792173386,
-0.0455985851585865,
-0.05151110514998436,
-0.033785346895456314,
0.012329400517046452,
0.05059805512428284,
-0.05009106174111366,
0.01738036796450615,
0.026414090767502785,
0.013422557152807713,
0.07632148265838623,
0.020745739340782166,
0.03433121368288994,
0.028740299865603447,
0.03998975455760956,
0.03353925794363022,
0.07221884280443192,
-0.06357811391353607,
-0.1944284737110138,
0.02009742520749569,
0.06701105087995529,
0.06587690114974976,
0.017324315384030342,
-0.009932207874953747,
0.04633316770195961,
0.017695490270853043,
0.011230646632611752,
-0.039160557091236115,
-0.0016716942191123962,
0.003201577579602599,
0.020441947504878044,
0.06678526848554611,
0.02392794005572796,
-0.025628838688135147,
-0.045965775847435,
-0.021310612559318542,
0.011853252537548542,
0.008404312655329704,
0.05209137499332428,
-0.017575431615114212,
-0.11249632388353348,
0.019402461126446724,
-0.005128925666213036,
0.07283395528793335,
-0.02628621645271778,
0.001768055371940136,
0.07928771525621414,
-0.01231564860790968,
-0.032176174223423004,
0.07450974732637405,
-0.00736219109967351,
-0.04387253522872925,
-0.04684682562947273,
-0.02264343947172165,
-2.8087107734914192e-33,
-0.013136433437466621,
-0.04398997128009796,
0.02092641592025757,
0.1263693869113922,
0.05392914637923241,
0.05336437746882439,
0.04362381622195244,
-0.029234491288661957,
-0.057138681411743164,
-0.0013110298896208405,
0.013870655559003353,
0.014716308563947678,
-0.02905849739909172,
0.014862104319036007,
0.013279604725539684,
-0.02678348496556282,
0.02467171847820282,
-0.014633693732321262,
0.03346364572644234,
0.010766529478132725,
0.004870923701673746,
-0.006085581611841917,
0.011651786044239998,
-0.0698605552315712,
-0.011767848394811153,
0.011050017550587654,
0.012947230599820614,
-0.03015085868537426,
-0.03191298618912697,
0.002781088463962078,
-0.015690622851252556,
-0.0371292382478714,
0.0676787942647934,
0.05922599881887436,
-0.026221493259072304,
-0.03889378532767296,
-0.0016268723411485553,
-0.023439913988113403,
-0.13731804490089417,
-0.035032808780670166,
0.011479320004582405,
0.04221368208527565,
-0.042977139353752136,
-0.001923228264786303,
-0.03794531151652336,
-0.051828574389219284,
-0.07505211979150772,
0.07878249138593674,
0.07670389860868454,
-0.04983901605010033,
-0.010977238416671753,
0.07103706896305084,
0.044625505805015564,
-0.056537602096796036,
0.05379961058497429,
-0.01613941602408886,
0.021834613755345345,
0.014260204508900642,
0.06339102983474731,
-0.020071955397725105,
-0.025299537926912308,
0.009477058425545692,
-0.007033175323158503,
0.13605479896068573,
0.050920963287353516,
0.07727506011724472,
-0.07160200923681259,
-0.10762552171945572,
-0.00688385171815753,
-0.043217066675424576,
-0.07140594720840454,
0.011953141540288925,
-0.1589478701353073,
-0.003780853934586048,
0.016253719106316566,
0.008594098500907421,
-0.0667477548122406,
-0.02725503407418728,
-0.019474178552627563,
-0.09572348743677139,
0.03927644342184067,
0.03250322490930557,
0.022953804582357407,
0.048333048820495605,
-0.04029997065663338,
-0.03209613636136055,
-0.05195535346865654,
-0.04081188514828682,
0.0635441392660141,
-0.044767264276742935,
0.01036694273352623,
-0.13044852018356323,
-0.009003705345094204,
-0.08677797764539719,
-0.0271897092461586,
3.3165482561933966e-34,
0.06516687572002411,
0.030944975093007088,
-0.042180974036455154,
0.03880783170461655,
0.02662862464785576,
-0.00746638560667634,
-0.0024532340466976166,
0.014236117713153362,
-0.027995452284812927,
0.07353182137012482,
-0.04792284965515137,
0.0518154539167881,
0.07287734001874924,
0.03213723003864288,
0.04011474922299385,
0.07682466506958008,
0.014619456604123116,
-0.015474408864974976,
0.053590837866067886,
-0.08657898753881454,
0.038990568369627,
0.015018880367279053,
0.005231977440416813,
0.013552132062613964,
-0.054507169872522354,
-0.006022690795361996,
-0.10066064447164536,
0.04633010923862457,
-0.054501552134752274,
0.023917870596051216,
-0.04325433075428009,
0.0914834514260292,
-0.040394797921180725,
-0.04673612862825394,
-0.06027441844344139,
-0.016350800171494484,
-0.008332974277436733,
0.06866350769996643,
0.0015915160765871406,
-0.035957857966423035,
0.08566597104072571,
0.005724380258470774,
-0.04450167715549469,
-0.019905511289834976,
-0.033685941249132156,
-0.05116690695285797,
-0.021183721721172333,
-0.024044791236519814,
0.05864465609192848,
-0.027723437175154686,
0.001487632980570197,
-0.0741364136338234,
-0.01510964147746563,
-0.0023094979114830494,
-0.06395559012889862,
0.006188739091157913,
0.009029918350279331,
-0.0020546969026327133,
0.09109257161617279,
-0.03245722874999046,
0.05290408805012703,
-0.040070753544569016,
-0.03470584377646446,
-0.04418276995420456,
0.02463812567293644,
-0.019445976242423058,
-0.006076822988688946,
-0.007284657098352909,
0.05917837843298912,
-0.04238048195838928,
-0.001938225352205336,
-0.011650362983345985,
-0.03579546511173248,
0.04169870913028717,
0.0017760599730536342,
0.06407750397920609,
0.008548685349524021,
-0.0304897241294384,
0.06375319510698318,
0.03420022130012512,
0.05812907963991165,
-0.03936809301376343,
-0.009250217117369175,
-0.0016106626717373729,
0.07859014719724655,
-0.05897097662091255,
0.003780682571232319,
0.05529450997710228,
0.015069583430886269,
0.020991750061511993,
-0.016884425655007362,
-0.036417629569768906,
-0.09675315022468567,
0.025918688625097275,
0.02219315804541111,
-5.497806654375381e-8,
-0.09581190347671509,
0.027498142793774605,
-0.13359810411930084,
-0.0004960463847965002,
0.022603265941143036,
0.03113369271159172,
0.000007855340300011449,
-0.03298915922641754,
0.07427497953176498,
0.013566835783421993,
-0.03437133505940437,
-0.02986607328057289,
0.01552147138863802,
0.0079311802983284,
-0.03259068354964256,
0.048230912536382675,
-0.006913686636835337,
0.013762825168669224,
-0.036117684096097946,
-0.07691545784473419,
0.018279599025845528,
0.004906500689685345,
0.06348041445016861,
0.021241923794150352,
0.0038994699716567993,
-0.069920115172863,
0.05474567040801048,
0.08475004136562347,
0.04177219420671463,
-0.02287203259766102,
-0.05072372406721115,
0.04392276331782341,
-0.08781345188617706,
-0.0431053526699543,
-0.19746793806552887,
0.061398040503263474,
-0.00032775697764009237,
-0.1139969527721405,
0.06593047082424164,
0.05849723145365715,
0.0022378398571163416,
-0.024060631170868874,
-0.05293503776192665,
0.01882399618625641,
-0.03830264136195183,
-0.0077985730022192,
-0.0019270796328783035,
-0.016440941020846367,
-0.01309325359761715,
0.006890814285725355,
0.01597009040415287,
-0.005279858130961657,
-0.053959112614393234,
0.04545215144753456,
-0.02135535515844822,
-0.022587791085243225,
-0.03647099435329437,
0.0192937720566988,
0.003152004210278392,
-0.02302832342684269,
-0.07820378988981247,
0.0508858785033226,
0.08040843158960342,
-0.05429347604513168
] | 0.045709
|
top-level `await` in itself or any of its dependencies, the promise will be fulfilled \_synchronously\_ after the module and all its dependencies have been evaluated. 1. If the evaluation succeeds, the promise will be \_synchronously\_ resolved to `undefined`. 2. If the evaluation results in an exception, the promise will be \_synchronously\_ rejected with the exception that causes the evaluation to fail, which is the same as `module.error`. 2. If the `vm.SourceTextModule` has top-level `await` in itself or any of its dependencies, the promise will be fulfilled \_asynchronously\_ after the module and all its dependencies have been evaluated. 1. If the evaluation succeeds, the promise will be \_asynchronously\_ resolved to `undefined`. 2. If the evaluation results in an exception, the promise will be \_asynchronously\_ rejected with the exception that causes the evaluation to fail. If the module is a `vm.SyntheticModule`, `evaluate()` always returns a promise that fulfills synchronously, see the specification of [Evaluate() of a Synthetic Module Record][]: 1. If the `evaluateCallback` passed to its constructor throws an exception synchronously, `evaluate()` returns a promise that will be synchronously rejected with that exception. 2. If the `evaluateCallback` does not throw an exception, `evaluate()` returns a promise that will be synchronously resolved to `undefined`. The `evaluateCallback` of a `vm.SyntheticModule` is executed synchronously within the `evaluate()` call, and its return value is discarded. This means if `evaluateCallback` is an asynchronous function, the promise returned by `evaluate()` will not reflect its asynchronous behavior, and any rejections from an asynchronous `evaluateCallback` will be lost. `evaluate()` could also be called again after the module has already been evaluated, in which case: 1. If the initial evaluation ended in success (`module.status` is `'evaluated'`), it will do nothing and return a promise that resolves to `undefined`. 2. If the initial evaluation resulted in an exception (`module.status` is `'errored'`), it will re-reject the exception that the initial evaluation resulted in. This method cannot be called while the module is being evaluated (`module.status` is `'evaluating'`). ### `module.identifier` \* Type: {string} The identifier of the current module, as set in the constructor. ### `module.link(linker)` \* `linker` {Function} \* `specifier` {string} The specifier of the requested module: ```mjs import foo from 'foo'; // ^^^^^ the module specifier ``` \* `referencingModule` {vm.Module} The `Module` object `link()` is called on. \* `extra` {Object} \* `attributes` {Object} The data from the attribute: ```mjs import foo from 'foo' with { name: 'value' }; // ^^^^^^^^^^^^^^^^^ the attribute ``` Per ECMA-262, hosts are expected to trigger an error if an unsupported attribute is present. \* `assert` {Object} Alias for `extra.attributes`. \* Returns: {vm.Module|Promise} \* Returns: {Promise} Link module dependencies. This method must be called before evaluation, and can only be called once per module. Use [`sourceTextModule.linkRequests(modules)`][] and [`sourceTextModule.instantiate()`][] to link modules either synchronously or asynchronously. The function is expected to return a `Module` object or a `Promise` that eventually resolves to a `Module` object. The returned `Module` must satisfy the following two invariants: \* It must belong to the same context as the parent `Module`. \* Its `status` must not be `'errored'`. If the returned `Module`'s `status` is `'unlinked'`, this method will be recursively called on the returned `Module` with the same provided `linker` function. `link()` returns a `Promise` that will either get resolved when all linking instances resolve to a valid `Module`, or rejected if the linker function either throws an exception or returns an invalid `Module`. The linker function roughly corresponds to the implementation-defined [HostResolveImportedModule][] abstract operation in the ECMAScript specification, with a few key differences: \* The linker function is allowed to be asynchronous while [HostResolveImportedModule][] is synchronous. The actual [HostResolveImportedModule][] implementation used during module
|
https://github.com/nodejs/node/blob/main//doc/api/vm.md
|
main
|
nodejs
|
[
-0.11354523152112961,
0.01919618621468544,
0.012477070093154907,
0.08330407738685608,
0.06889346241950989,
0.004451477900147438,
-0.03224260360002518,
0.023225421085953712,
0.052668407559394836,
-0.05028286203742027,
0.018798667937517166,
-0.06758099049329758,
0.055349286645650864,
-0.05779954791069031,
0.05238531529903412,
0.0065874275751411915,
0.03083641827106476,
0.023570645600557327,
-0.010782705619931221,
0.025230780243873596,
0.06709431111812592,
0.025645868852734566,
0.057808730751276016,
-0.010209607891738415,
0.03744145855307579,
0.05083819106221199,
-0.07177741825580597,
-0.0697365254163742,
0.07368198782205582,
0.027459468692541122,
-0.07248903065919876,
0.04790071025490761,
-0.019448453560471535,
0.028918283060193062,
-0.0011741481721401215,
0.08384662866592407,
-0.037314482033252716,
-0.031572118401527405,
0.02157950960099697,
0.023752082139253616,
0.021050890907645226,
0.0209126565605402,
-0.06250996142625809,
0.0013005994260311127,
0.020351676270365715,
-0.1256234049797058,
0.054996345192193985,
-0.0305104348808527,
-0.1408257782459259,
-0.046911414712667465,
-0.06954637169837952,
-0.02249511331319809,
-0.06501830369234085,
0.04530762881040573,
-0.013219146989285946,
0.03458792343735695,
0.05945025384426117,
0.05084758251905441,
-0.004135757219046354,
0.029756881296634674,
-0.0019024442881345749,
-0.024615414440631866,
-0.06611757725477219,
-0.019927196204662323,
0.10195306688547134,
-0.026306699961423874,
0.09162641316652298,
-0.008000744506716728,
0.05269057676196098,
0.00822758674621582,
-0.060018718242645264,
-0.008552346378564835,
0.0008878175867721438,
0.033352188766002655,
-0.01512925699353218,
-0.06870263069868088,
0.039198972284793854,
0.01774495281279087,
0.0291350819170475,
-0.022685492411255836,
0.018815195187926292,
0.004762325435876846,
0.012923686765134335,
-0.051128555089235306,
-0.028747128322720528,
-0.009374122135341167,
0.03767233341932297,
0.06243407353758812,
0.035948749631643295,
-0.003469842951744795,
-0.007962140254676342,
-0.07822473347187042,
-0.077456995844841,
0.11786996573209763,
0.05908476561307907,
0.011208339594304562,
0.018200648948550224,
0.02241598069667816,
0.05374908819794655,
-0.06853624433279037,
0.04847289249300957,
-0.021003033965826035,
-0.03846726939082146,
-0.03491909056901932,
0.0036687334068119526,
-0.03986603394150734,
0.040943361818790436,
-0.04833454266190529,
-0.030026357620954514,
-0.013085298240184784,
0.027807192876935005,
-0.0015031503280624747,
0.06851023435592651,
0.00612688111141324,
-0.012437393888831139,
0.014314171858131886,
0.02763034775853157,
-0.033667054027318954,
0.021688072010874748,
0.007083369418978691,
0.03532002493739128,
0.0454682856798172,
0.19596226513385773,
-0.07032480835914612,
-0.03134489431977272,
-0.04156441241502762,
-0.02001749724149704,
3.576963555336972e-33,
-0.0005530508933588862,
-0.017171280458569527,
-0.010548154823482037,
0.009241627529263496,
0.04534238949418068,
0.049086760729551315,
0.019478823989629745,
-0.02876751683652401,
-0.06235549971461296,
-0.034808240830898285,
-0.009799184277653694,
-0.017898837104439735,
-0.093389131128788,
0.05030736327171326,
0.012044144794344902,
-0.011375128291547298,
0.056771714240312576,
-0.03829842433333397,
-0.01978432759642601,
0.07821048051118851,
0.038154102861881256,
-0.027333939447999,
0.00468640448525548,
0.009838011115789413,
-0.011004995554685593,
-0.04220600426197052,
0.004969686269760132,
0.0325486995279789,
-0.10232092440128326,
-0.00028749631019309163,
-0.09102989733219147,
-0.022587185725569725,
-0.00021620592451654375,
0.0373050682246685,
0.012222045101225376,
-0.028747569769620895,
-0.03905245661735535,
-0.047619592398405075,
-0.10434956103563309,
-0.05177775397896767,
-0.07920977473258972,
0.09081202000379562,
-0.020234916359186172,
-0.024077149108052254,
0.0038703226018697023,
-0.11585577577352524,
-0.05565693974494934,
0.05896684154868126,
0.07284516096115112,
-0.028479788452386856,
0.01666376180946827,
0.05994979292154312,
0.04653512313961983,
-0.04051226004958153,
0.08117271959781647,
-0.0033645108342170715,
0.019273942336440086,
0.030521336942911148,
0.017697855830192566,
0.08899562805891037,
-0.010735969059169292,
-0.1450537145137787,
-0.08040410280227661,
0.02542789652943611,
-0.009024263359606266,
0.08295882493257523,
-0.10811584442853928,
-0.10471035540103912,
-0.029071645811200142,
0.02042180858552456,
-0.020583678036928177,
0.016910750418901443,
-0.07503870874643326,
0.051758699119091034,
0.05561782792210579,
-0.011980317533016205,
-0.09359017759561539,
-0.06062924116849899,
0.025483248755335808,
-0.054952289909124374,
0.011111298575997353,
0.05547710135579109,
-0.04168180003762245,
0.04792602360248566,
-0.11913369596004486,
0.046500641852617264,
-0.015449158847332,
-0.058333542197942734,
0.02017161063849926,
0.005083669442683458,
-0.014052892103791237,
-0.07062978297472,
0.011911687441170216,
-0.02869359776377678,
0.02409014105796814,
-6.27936151771407e-33,
0.09034719318151474,
0.02319459803402424,
-0.0009374408982694149,
0.019841991364955902,
0.028395112603902817,
0.05549002066254616,
0.0057022771798074245,
-0.021945703774690628,
-0.019140146672725677,
0.00038962214603088796,
0.004521792754530907,
0.01983107440173626,
0.02684367075562477,
0.08722633868455887,
-0.010429484769701958,
0.06149149686098099,
0.09453120827674866,
-0.11946728080511093,
0.017618253827095032,
-0.030102873221039772,
0.0824693962931633,
0.04040795564651489,
-0.035701263695955276,
0.005112860351800919,
-0.02890525758266449,
0.004890440497547388,
-0.1059892475605011,
0.03368688374757767,
-0.020018314942717552,
-0.005292934365570545,
0.06295090168714523,
-0.024165164679288864,
-0.06539051979780197,
-0.037809066474437714,
0.03603528439998627,
0.04404040053486824,
0.03249719366431236,
-0.0033657464664429426,
-0.07691071182489395,
-0.028195420280098915,
0.12824593484401703,
-0.012224474921822548,
-0.04224352538585663,
-0.017958683893084526,
0.025162803009152412,
-0.09787825495004654,
-0.021363696083426476,
-0.08106951415538788,
0.004122607875615358,
-0.029650982469320297,
0.035448312759399414,
0.002863973844796419,
-0.05193508043885231,
0.013217597268521786,
0.004605126567184925,
-0.03764431178569794,
-0.029403921216726303,
0.026055507361888885,
0.03893459588289261,
-0.0425313375890255,
-0.04640888795256615,
-0.030363619327545166,
0.04386701062321663,
-0.028327902778983116,
-0.021236544474959373,
0.020965540781617165,
-0.023384781554341316,
0.01029275357723236,
0.17647407948970795,
0.034696925431489944,
0.10784106701612473,
-0.0027883308939635754,
-0.059032052755355835,
0.047426555305719376,
-0.037493765354156494,
0.01792057603597641,
0.001375200692564249,
-0.04343608021736145,
0.020704708993434906,
0.01578553579747677,
0.04734266921877861,
0.0013608245644718409,
0.038679562509059906,
0.04835810884833336,
-0.029259314760565758,
-0.007640892174094915,
0.04417899623513222,
-0.024061091244220734,
0.006334919016808271,
0.032185301184654236,
0.010702927596867085,
-0.0406363308429718,
-0.12623050808906555,
0.06305719166994095,
0.01801440492272377,
-5.9096834092997597e-8,
-0.04173124581575394,
-0.04378591105341911,
-0.08058848232030869,
-0.0007981066592037678,
0.0030376743525266647,
0.006411862093955278,
0.03343476727604866,
-0.09007351100444794,
0.07226364314556122,
-0.003760109655559063,
-0.03074290044605732,
-0.023252077400684357,
0.07434811443090439,
0.0020069419406354427,
-0.005557388998568058,
0.0893392339348793,
0.006795867811888456,
-0.016118556261062622,
-0.008122685365378857,
-0.08744106441736221,
0.0031319609843194485,
0.03637826442718506,
-0.05109965801239014,
0.02657604031264782,
-0.017819738015532494,
-0.03277187794446945,
0.0699346587061882,
0.09073878079652786,
0.0036879817489534616,
-0.03183320164680481,
-0.010743067599833012,
0.005808711051940918,
-0.0797683373093605,
-0.03719067573547363,
-0.08060964196920395,
0.05489843711256981,
0.08240831643342972,
-0.07693202048540115,
0.04917428269982338,
0.0699320137500763,
0.052376553416252136,
-0.03611734136939049,
-0.026595808565616608,
0.05220705643296242,
0.004680610727518797,
-0.060784801840782166,
-0.06347264349460602,
-0.10581528395414352,
-0.02272878959774971,
-0.07693998515605927,
-0.002717556431889534,
-0.019263137131929398,
-0.11404958367347717,
0.06760283559560776,
-0.02272256277501583,
-0.0004447464307304472,
0.017523741349577904,
0.023419074714183807,
-0.0026384741067886353,
-0.027346296235919,
0.05191561579704285,
-0.03295468911528587,
0.07379855960607529,
-0.08045767992734909
] | 0.081918
|
function either throws an exception or returns an invalid `Module`. The linker function roughly corresponds to the implementation-defined [HostResolveImportedModule][] abstract operation in the ECMAScript specification, with a few key differences: \* The linker function is allowed to be asynchronous while [HostResolveImportedModule][] is synchronous. The actual [HostResolveImportedModule][] implementation used during module linking is one that returns the modules linked during linking. Since at that point all modules would have been fully linked already, the [HostResolveImportedModule][] implementation is fully synchronous per specification. Corresponds to the [Link() concrete method][] field of [Cyclic Module Record][]s in the ECMAScript specification. ### `module.namespace` \* Type: {Object} The namespace object of the module. This is only available after linking (`module.link()`) has completed. Corresponds to the [GetModuleNamespace][] abstract operation in the ECMAScript specification. ### `module.status` \* Type: {string} The current status of the module. Will be one of: \* `'unlinked'`: `module.link()` has not yet been called. \* `'linking'`: `module.link()` has been called, but not all Promises returned by the linker function have been resolved yet. \* `'linked'`: The module has been linked successfully, and all of its dependencies are linked, but `module.evaluate()` has not yet been called. \* `'evaluating'`: The module is being evaluated through a `module.evaluate()` on itself or a parent module. \* `'evaluated'`: The module has been successfully evaluated. \* `'errored'`: The module has been evaluated, but an exception was thrown. Other than `'errored'`, this status string corresponds to the specification's [Cyclic Module Record][]'s `[[Status]]` field. `'errored'` corresponds to `'evaluated'` in the specification, but with `[[EvaluationError]]` set to a value that is not `undefined`. ## Class: `vm.SourceTextModule` > Stability: 1 - Experimental This feature is only available with the `--experimental-vm-modules` command flag enabled. \* Extends: {vm.Module} The `vm.SourceTextModule` class provides the [Source Text Module Record][] as defined in the ECMAScript specification. ### `new vm.SourceTextModule(code[, options])` \* `code` {string} JavaScript Module code to parse \* `options` \* `identifier` {string} String used in stack traces. \*\*Default:\*\* `'vm:module(i)'` where `i` is a context-specific ascending index. \* `cachedData` {Buffer|TypedArray|DataView} Provides an optional `Buffer` or `TypedArray`, or `DataView` with V8's code cache data for the supplied source. The `code` must be the same as the module from which this `cachedData` was created. \* `context` {Object} The [contextified][] object as returned by the `vm.createContext()` method, to compile and evaluate this `Module` in. If no context is specified, the module is evaluated in the current execution context. \* `lineOffset` {integer} Specifies the line number offset that is displayed in stack traces produced by this `Module`. \*\*Default:\*\* `0`. \* `columnOffset` {integer} Specifies the first-line column number offset that is displayed in stack traces produced by this `Module`. \*\*Default:\*\* `0`. \* `initializeImportMeta` {Function} Called during evaluation of this `Module` to initialize the `import.meta`. \* `meta` {import.meta} \* `module` {vm.SourceTextModule} \* `importModuleDynamically` {Function} Used to specify the how the modules should be loaded during the evaluation of this module when `import()` is called. This option is part of the experimental modules API. We do not recommend using it in a production environment. For detailed information, see [Support of dynamic `import()` in compilation APIs][]. Creates a new `SourceTextModule` instance. Properties assigned to the `import.meta` object that are objects may allow the module to access information outside the specified `context`. Use `vm.runInContext()` to create objects in a specific context. ```mjs import vm from 'node:vm'; const contextifiedObject = vm.createContext({ secret: 42 }); const module = new vm.SourceTextModule( 'Object.getPrototypeOf(import.meta.prop).secret = secret;', { initializeImportMeta(meta) { // Note: this object is created in the top context. As such, // Object.getPrototypeOf(import.meta.prop) points to the // Object.prototype in the top context rather than that in // the contextified object. meta.prop = {}; }, });
|
https://github.com/nodejs/node/blob/main//doc/api/vm.md
|
main
|
nodejs
|
[
-0.0581059530377388,
0.017837360501289368,
-0.009640498086810112,
0.07951980829238892,
0.04459159076213837,
-0.029565714299678802,
-0.08679015934467316,
0.07858363538980484,
-0.0428994745016098,
-0.08070320636034012,
-0.0012472070520743728,
-0.027994409203529358,
0.009742784313857555,
-0.03959513083100319,
0.008462106809020042,
0.01621301658451557,
-0.03114980459213257,
0.02553744427859783,
0.05201537534594536,
0.02571924589574337,
0.06827259808778763,
0.03010299801826477,
0.0010306183248758316,
0.004506357479840517,
-0.09853456169366837,
-0.0025802752934396267,
-0.04909424111247063,
0.010170628316700459,
0.0005481091211549938,
-0.026721777394413948,
-0.0031979670748114586,
0.03444096818566322,
-0.11507029831409454,
-0.019188862293958664,
0.06803629547357559,
0.1320033073425293,
0.05333590880036354,
-0.07654724270105362,
-0.022096198052167892,
-0.01487030740827322,
0.11195371299982071,
0.044938959181308746,
0.005625887308269739,
-0.0816873162984848,
-0.01663370244204998,
-0.04629188030958176,
-0.0006151862908154726,
0.03849341720342636,
-0.1195005550980568,
-0.001588946906849742,
0.033364903181791306,
0.10519663244485855,
0.030253680422902107,
0.021475346758961678,
0.07923821359872818,
0.05720705911517143,
-0.053698353469371796,
-0.023412277922034264,
0.03561491146683693,
0.029468605294823647,
0.04490780830383301,
0.05842971056699753,
-0.04234938696026802,
-0.054478615522384644,
0.047252312302589417,
-0.04160697013139725,
0.04833921790122986,
-0.00033617138979025185,
-0.035645075142383575,
-0.007789193652570248,
-0.065166175365448,
0.00011297977471258491,
0.07431121170520782,
0.14556743204593658,
0.01793246529996395,
-0.013164137490093708,
0.019396405667066574,
0.03526301309466362,
0.01766953058540821,
-0.05045202374458313,
0.026404689997434616,
-0.05689874663949013,
-0.057456135749816895,
-0.007284988649189472,
-0.012719319202005863,
-0.02449950948357582,
-0.04847238212823868,
-0.005705052055418491,
0.09417823702096939,
0.0612247996032238,
0.025480348616838455,
-0.042653560638427734,
-0.047741737216711044,
0.017284104600548744,
0.07613001018762589,
0.009953329339623451,
-0.04632594808936119,
0.09998080134391785,
-0.008099979721009731,
-0.004624580033123493,
0.06296675652265549,
0.043046142905950546,
0.02315504662692547,
-0.007672233507037163,
0.043691545724868774,
0.005426634103059769,
0.0261869877576828,
0.0468413382768631,
-0.02427373081445694,
-0.027696581557393074,
-0.058450084179639816,
-0.016818396747112274,
0.015793099999427795,
-0.08223120123147964,
-0.0407659076154232,
0.019889425486326218,
-0.015422829426825047,
-0.02688395418226719,
0.14308317005634308,
-0.0034695935901254416,
0.1036335825920105,
-0.0025683948770165443,
0.11106929928064346,
-0.005633165594190359,
0.008741059340536594,
-0.022619133815169334,
0.031837597489356995,
8.25837605230047e-33,
-0.015170928090810776,
-0.05080845206975937,
-0.05359739065170288,
0.0034124357625842094,
-0.023144440725445747,
0.0450565442442894,
-0.009895016439259052,
0.06287568807601929,
-0.11389127373695374,
-0.051800742745399475,
-0.0827716514468193,
0.08041375875473022,
-0.059000954031944275,
-0.01758335344493389,
-0.029259229078888893,
0.03223634138703346,
0.0640387311577797,
0.020024314522743225,
0.002657849108800292,
0.0666118785738945,
0.015666550025343895,
0.013060231693089008,
0.05760941654443741,
0.04543276131153107,
0.023715533316135406,
0.040499307215213776,
-0.05549928545951843,
-0.03423156216740608,
0.03582405298948288,
0.028894495218992233,
-0.021238412708044052,
0.063820481300354,
-0.024948006495833397,
0.029750799760222435,
0.07280443608760834,
0.03506610542535782,
0.0220657866448164,
-0.01895066164433956,
-0.17813347280025482,
0.0002753133303485811,
-0.0596819706261158,
-0.0022256774827837944,
-0.06829611957073212,
-0.020616281777620316,
0.012352634221315384,
-0.10566025227308273,
-0.01815982535481453,
0.004973870236426592,
0.055490221828222275,
0.03788501396775246,
0.005111883394420147,
-0.013062420301139355,
0.001467021182179451,
-0.11149340867996216,
0.07047253847122192,
-0.005081792362034321,
-0.05610694736242294,
0.024192770943045616,
0.04674072191119194,
0.055778659880161285,
-0.02731294371187687,
-0.032411620020866394,
-0.04453616961836815,
-0.03209029883146286,
0.06858732551336288,
0.037752117961645126,
-0.049958664923906326,
-0.05576445907354355,
-0.054897990077733994,
-0.017142096534371376,
0.023054765537381172,
0.07567953318357468,
-0.03391615301370621,
0.07899098843336105,
0.07684963941574097,
-0.029009360820055008,
-0.09765179455280304,
-0.09013904631137848,
-0.025138095021247864,
-0.01612081192433834,
-0.004735935479402542,
-0.0261579267680645,
-0.023467328399419785,
0.03729346767067909,
-0.00447250297293067,
0.006694957613945007,
-0.022287774831056595,
0.0489339604973793,
-0.008591679856181145,
-0.06232697144150734,
0.05358570069074631,
-0.012163016945123672,
0.005103447940200567,
0.03380845487117767,
0.016493452712893486,
-9.989805762664774e-33,
0.10677167773246765,
-0.0013307066401466727,
-0.012436751276254654,
-0.0306033194065094,
-0.09837891161441803,
-0.007628802675753832,
-0.0017261123284697533,
0.03018484078347683,
0.006992601323872805,
-0.008701601065695286,
0.009315745905041695,
-0.03204641863703728,
0.00494691776111722,
-0.02554636262357235,
0.0306132510304451,
0.05245877429842949,
-0.06661535799503326,
-0.07153956592082977,
0.001371848862618208,
0.055713627487421036,
0.09009745717048645,
0.06823669373989105,
0.027582669630646706,
0.010446351021528244,
-0.056617431342601776,
-0.02018973045051098,
-0.03692056983709335,
-0.0525825135409832,
-0.007553619798272848,
-0.038962479680776596,
0.04979800432920456,
0.02015325240790844,
-0.03722931817173958,
-0.0060005513951182365,
0.02741001732647419,
0.11005611717700958,
-0.00629572756588459,
-0.019638050347566605,
0.03378146514296532,
-0.09409996122121811,
0.06700415909290314,
0.021335415542125702,
-0.07569385319948196,
-0.08391363173723221,
0.10611918568611145,
0.022726457566022873,
-0.020484520122408867,
0.05287710577249527,
0.03842746093869209,
0.01786166802048683,
-0.017640400677919388,
-0.11499025672674179,
-0.008802826516330242,
-0.058616891503334045,
-0.021177716553211212,
0.06177792698144913,
-0.0036926160100847483,
-0.025786424055695534,
0.007995824329555035,
0.018309377133846283,
0.06833990663290024,
-0.08247381448745728,
0.003563323989510536,
-0.03974887728691101,
-0.007852062582969666,
0.026076359674334526,
-0.04947482794523239,
-0.0987282395362854,
0.06615480780601501,
0.1002495139837265,
-0.007053194101899862,
-0.03634248301386833,
-0.0813998281955719,
-0.018529122695326805,
0.011175869964063168,
0.09354645013809204,
0.008358464576303959,
-0.003919877577573061,
-0.004237976390868425,
0.04174128547310829,
-0.015507519245147705,
0.01636180840432644,
0.06188885495066643,
0.014909056946635246,
-0.027283327654004097,
-0.06863522529602051,
0.08276694267988205,
-0.013377649709582329,
-0.002079704776406288,
0.006838057190179825,
-0.009273410774767399,
-0.0590989775955677,
-0.04616142436861992,
0.09643877297639847,
-0.08530157804489136,
-6.715516320809911e-8,
-0.013583284802734852,
0.0035430691204965115,
-0.18638205528259277,
-0.07612234354019165,
0.05109604075551033,
0.035306308418512344,
-0.01794522814452648,
-0.05009051039814949,
0.08387137949466705,
0.03345580771565437,
-0.053239189088344574,
0.027770472690463066,
-0.0076646762900054455,
0.028577519580721855,
0.017891237512230873,
-0.009177555330097675,
-0.02417275495827198,
-0.0052808434702456,
-0.014513907954096794,
0.021989932283759117,
0.03513814136385918,
-0.07298281788825989,
-0.01985316351056099,
0.05956469103693962,
-0.01810539700090885,
-0.07329422980546951,
0.08489712327718735,
0.04185390844941139,
-0.013902504928410053,
0.013242681510746479,
-0.03359323740005493,
0.003868576604872942,
-0.03089299239218235,
0.05223166570067406,
-0.056411582976579666,
0.05141002684831619,
-0.002030768897384405,
-0.015444145537912846,
0.009357372298836708,
-0.008840781636536121,
0.07169592380523682,
0.04830396920442581,
-0.06259969621896744,
-0.003912115469574928,
0.11653456836938858,
-0.03151852265000343,
-0.055025581270456314,
0.03496284782886505,
-0.05518754944205284,
-0.02074897289276123,
-0.04686259478330612,
-0.0028988069389015436,
-0.0727287158370018,
-0.026385212317109108,
-0.026239806786179543,
-0.05217726156115532,
-0.04250543937087059,
-0.10301417112350464,
-0.005019796546548605,
-0.04555242881178856,
-0.024342287331819534,
0.06379460543394089,
0.0433771125972271,
-0.023965246975421906
] | 0.088664
|
secret: 42 }); const module = new vm.SourceTextModule( 'Object.getPrototypeOf(import.meta.prop).secret = secret;', { initializeImportMeta(meta) { // Note: this object is created in the top context. As such, // Object.getPrototypeOf(import.meta.prop) points to the // Object.prototype in the top context rather than that in // the contextified object. meta.prop = {}; }, }); // The module has an empty `moduleRequests` array. module.linkRequests([]); module.instantiate(); await module.evaluate(); // Now, Object.prototype.secret will be equal to 42. // // To fix this problem, replace // meta.prop = {}; // above with // meta.prop = vm.runInContext('{}', contextifiedObject); ``` ```cjs const vm = require('node:vm'); const contextifiedObject = vm.createContext({ secret: 42 }); (async () => { const module = new vm.SourceTextModule( 'Object.getPrototypeOf(import.meta.prop).secret = secret;', { initializeImportMeta(meta) { // Note: this object is created in the top context. As such, // Object.getPrototypeOf(import.meta.prop) points to the // Object.prototype in the top context rather than that in // the contextified object. meta.prop = {}; }, }); // The module has an empty `moduleRequests` array. module.linkRequests([]); module.instantiate(); await module.evaluate(); // Now, Object.prototype.secret will be equal to 42. // // To fix this problem, replace // meta.prop = {}; // above with // meta.prop = vm.runInContext('{}', contextifiedObject); })(); ``` ### `sourceTextModule.createCachedData()` \* Returns: {Buffer} Creates a code cache that can be used with the `SourceTextModule` constructor's `cachedData` option. Returns a `Buffer`. This method may be called any number of times before the module has been evaluated. The code cache of the `SourceTextModule` doesn't contain any JavaScript observable states. The code cache is safe to be saved along side the script source and used to construct new `SourceTextModule` instances multiple times. Functions in the `SourceTextModule` source can be marked as lazily compiled and they are not compiled at construction of the `SourceTextModule`. These functions are going to be compiled when they are invoked the first time. The code cache serializes the metadata that V8 currently knows about the `SourceTextModule` that it can use to speed up future compilations. ```js // Create an initial module const module = new vm.SourceTextModule('const a = 1;'); // Create cached data from this module const cachedData = module.createCachedData(); // Create a new module using the cached data. The code must be the same. const module2 = new vm.SourceTextModule('const a = 1;', { cachedData }); ``` ### `sourceTextModule.dependencySpecifiers` > Stability: 0 - Deprecated: Use [`sourceTextModule.moduleRequests`][] instead. \* Type: {string\[]} The specifiers of all dependencies of this module. The returned array is frozen to disallow any changes to it. Corresponds to the `[[RequestedModules]]` field of [Cyclic Module Record][]s in the ECMAScript specification. ### `sourceTextModule.hasAsyncGraph()` \* Returns: {boolean} Iterates over the dependency graph and returns `true` if any module in its dependencies or this module itself contains top-level `await` expressions, otherwise returns `false`. The search may be slow if the graph is big enough. This requires the module to be instantiated first. If the module is not instantiated yet, an error will be thrown. ### `sourceTextModule.hasTopLevelAwait()` \* Returns: {boolean} Returns whether the module itself contains any top-level `await` expressions. This corresponds to the field `[[HasTLA]]` in [Cyclic Module Record][] in the ECMAScript specification. ### `sourceTextModule.instantiate()` \* Returns: {undefined} Instantiate the module with the linked requested modules. This resolves the imported bindings of the module, including re-exported binding names. When there are any bindings that cannot be resolved, an error would be thrown synchronously. If the requested modules include cyclic dependencies, the [`sourceTextModule.linkRequests(modules)`][] method must be called on all modules in the cycle before calling this method. ### `sourceTextModule.linkRequests(modules)` \* `modules` {vm.Module\[]} Array of `vm.Module` objects that this module depends on. The order of the modules in the array is the order of [`sourceTextModule.moduleRequests`][]. \*
|
https://github.com/nodejs/node/blob/main//doc/api/vm.md
|
main
|
nodejs
|
[
-0.06652117520570755,
0.07374384999275208,
-0.010954456403851509,
0.05751099810004234,
0.04667961969971657,
0.011153987608850002,
0.06802699714899063,
0.12188540399074554,
-0.002716846065595746,
0.0008337799226865172,
-0.0225143413990736,
-0.10287526249885559,
-0.07890908420085907,
0.0159186739474535,
0.12052058428525925,
0.05450040474534035,
0.07094506919384003,
-0.026982557028532028,
-0.02021889202296734,
0.08101603388786316,
0.05921868607401848,
-0.040454357862472534,
0.11622831225395203,
-0.024285435676574707,
-0.021125491708517075,
-0.004067523404955864,
-0.026401342824101448,
-0.00553624052554369,
0.06453187018632889,
-0.00564277870580554,
0.025722095742821693,
0.08846072107553482,
-0.14132055640220642,
-0.015148933976888657,
-0.003484440967440605,
0.07551510632038116,
-0.05701790004968643,
-0.053172141313552856,
0.0393158495426178,
0.00952184945344925,
0.07763782143592834,
0.0834290087223053,
-0.113780677318573,
-0.014270368032157421,
0.0025161474477499723,
-0.034650810062885284,
0.046604007482528687,
0.07050863653421402,
0.02801618166267872,
-0.001694096950814128,
-0.09985831379890442,
-0.0442638024687767,
-0.02192998118698597,
0.03454123064875603,
-0.06569598615169525,
0.0023475480265915394,
0.002740063238888979,
0.03155515715479851,
0.07678396254777908,
0.09358156472444534,
0.006525571458041668,
-0.01750963367521763,
0.05263368785381317,
-0.06513889133930206,
0.03792492300271988,
-0.017614969983696938,
0.019963180646300316,
-0.004674161318689585,
-0.004396453499794006,
-0.04170364513993263,
0.0023620736319571733,
0.02111530303955078,
0.05127216503024101,
0.057356685400009155,
-0.011026004329323769,
-0.01735197752714157,
-0.07949758321046829,
-0.02084122970700264,
0.014604647643864155,
-0.02480819821357727,
0.05826212093234062,
-0.0228256918489933,
-0.0024540075100958347,
0.05112304911017418,
0.005116349086165428,
0.08904960006475449,
0.03602050617337227,
0.019228842109441757,
-0.021355025470256805,
0.013297422789037228,
-0.09529763460159302,
-0.10049261897802353,
-0.05575934797525406,
0.0728936642408371,
0.048684585839509964,
-0.004089461639523506,
-0.08469115197658539,
0.03429289534687996,
-0.04103345796465874,
0.06737721711397171,
0.004493194166570902,
-0.018756523728370667,
0.03227834403514862,
0.010036345571279526,
0.016277924180030823,
0.05685559660196304,
-0.03272930905222893,
0.015810655429959297,
-0.02958923578262329,
0.032662443816661835,
-0.018067657947540283,
0.06254702061414719,
-0.040599577128887177,
-0.04713738337159157,
-0.052684083580970764,
0.028113657608628273,
0.024972515180706978,
-0.029250873252749443,
0.03457425907254219,
0.06414010375738144,
0.046997133642435074,
0.004646238870918751,
0.053084805607795715,
-0.015705039724707603,
-0.04937614127993584,
-0.02606046572327614,
-0.023556042462587357,
-3.5954942135872274e-34,
-0.009304494597017765,
0.06488819420337677,
0.031184181571006775,
0.13274292647838593,
0.03258814290165901,
0.014778117649257183,
0.08390871435403824,
0.01852274499833584,
-0.05434036999940872,
-0.02293815091252327,
-0.05164692550897598,
-0.024829767644405365,
-0.08016520738601685,
-0.052796296775341034,
0.0007229627226479352,
-0.02726522833108902,
0.00912450347095728,
-0.010044657625257969,
0.021037954837083817,
-0.0453166663646698,
0.022267663851380348,
0.007978728972375393,
-0.004036156926304102,
-0.06948842108249664,
0.00004908057235297747,
0.014146310277283192,
-0.05068380385637283,
0.0421961285173893,
-0.08995390683412552,
0.011000458151102066,
0.07182015478610992,
0.015250717289745808,
0.08265571296215057,
0.10718691349029541,
-0.010198468342423439,
-0.07374046742916107,
0.0048651681281626225,
-0.0482618510723114,
-0.10065113753080368,
-0.07371293008327484,
0.05205738916993141,
-0.0017225142801180482,
0.03542853891849518,
-0.04652795568108559,
-0.1005963534116745,
-0.06725814938545227,
-0.07763512432575226,
0.035088103264570236,
0.07518883794546127,
-0.018050940707325935,
-0.05268998071551323,
0.05600909888744354,
-0.009679046459496021,
-0.10344389081001282,
0.035825252532958984,
0.0002507200406398624,
-0.03737090900540352,
0.039771247655153275,
0.022142667323350906,
-0.03869449719786644,
0.01130280364304781,
0.01820985972881317,
-0.0600898303091526,
0.05904018133878708,
-0.05146355181932449,
0.04862843453884125,
-0.08674578368663788,
-0.07344452291727066,
0.025692159309983253,
-0.01290821097791195,
-0.027241108939051628,
0.04881364479660988,
-0.11497191339731216,
-0.0011050495086237788,
-0.011284306645393372,
0.018608378246426582,
-0.08306042850017548,
-0.037936847656965256,
0.018271971493959427,
-0.03510088846087456,
0.03176224231719971,
0.059971000999212265,
0.005071908701211214,
0.10616035759449005,
-0.05492918938398361,
-0.0018313060281798244,
-0.051865819841623306,
-0.03496794030070305,
0.08353152871131897,
0.010178434662520885,
0.06764454394578934,
-0.05559532344341278,
-0.06330284476280212,
-0.0619150847196579,
-0.057627592235803604,
-2.7821488255956588e-33,
-0.0042105671018362045,
0.021151138469576836,
-0.029726412147283554,
0.009026696905493736,
0.04850604385137558,
0.03337131440639496,
-0.012446216307580471,
0.0003809588961303234,
-0.04831836745142937,
0.0815265104174614,
0.00116262910887599,
0.020241769030690193,
0.005578598473221064,
-0.0063937958329916,
0.009797382168471813,
0.031044159084558487,
0.0005287362728267908,
-0.03214165195822716,
0.10205236077308655,
-0.07661338150501251,
0.0612168125808239,
0.06278868019580841,
-0.008857875131070614,
-0.022391323000192642,
-0.05989592522382736,
-0.05764267221093178,
-0.04687628522515297,
0.037000954151153564,
0.020888028666377068,
0.05234864354133606,
-0.03813539445400238,
0.06717796623706818,
-0.07012458145618439,
0.03062470443546772,
0.0046553281135857105,
-0.020543085411190987,
-0.021536314859986305,
0.01824173517525196,
0.038845278322696686,
-0.051406193524599075,
0.04247984290122986,
-0.06359449028968811,
-0.05319451540708542,
-0.04213125258684158,
-0.020195158198475838,
-0.06869028508663177,
0.03891869634389877,
-0.05339832603931427,
0.14336760342121124,
-0.02751293033361435,
-0.01929427683353424,
-0.07282394915819168,
-0.015539678744971752,
-0.0888514593243599,
-0.05136466026306152,
-0.0030255389865487814,
-0.04403010755777359,
-0.042478352785110474,
0.06514903903007507,
0.04189174249768257,
0.10317429900169373,
-0.06377934664487839,
-0.08462623506784439,
-0.018127700313925743,
0.036497004330158234,
-0.004005744121968746,
-0.0638897716999054,
-0.0381866879761219,
0.06135665625333786,
-0.011636503972113132,
0.007180424407124519,
-0.0323445089161396,
-0.00913545023649931,
-0.005252367351204157,
0.01354206446558237,
0.002067148219794035,
-0.01705157943069935,
0.018267303705215454,
0.026104137301445007,
0.04938183352351189,
0.10413762181997299,
-0.04002697393298149,
-0.01909073069691658,
-0.029680967330932617,
0.07950857281684875,
-0.020908642560243607,
-0.043699342757463455,
0.07398269325494766,
-0.06886851787567139,
0.047243572771549225,
-0.02476087585091591,
-0.01662229746580124,
-0.08583371341228485,
0.05852685496211052,
0.02258589118719101,
-6.134713714800455e-8,
-0.038690585643053055,
0.02145565114915371,
-0.08369628340005875,
-0.014380311593413353,
-0.03024587221443653,
-0.0011501446133479476,
-0.03299502283334732,
-0.06876984238624573,
0.024257445707917213,
-0.014761130325496197,
-0.1047002375125885,
0.021930357441306114,
0.0873401015996933,
0.06383342295885086,
-0.026421738788485527,
-0.0023475047200918198,
-0.08157923817634583,
0.032482344657182693,
-0.006778926122933626,
-0.0461258627474308,
-0.02405746467411518,
-0.023711949586868286,
0.06249743327498436,
0.010422750376164913,
0.05728689581155777,
-0.05086652189493179,
0.03523452952504158,
0.044644009321928024,
0.02299879491329193,
0.1199541836977005,
-0.08746866881847382,
0.04251372441649437,
-0.04449423402547836,
-0.008723598904907703,
-0.13379380106925964,
0.07261563837528229,
-0.022974660620093346,
-0.03447575867176056,
0.014467266388237476,
0.034166958183050156,
0.11209700256586075,
0.0005755813326686621,
-0.08432476222515106,
0.03347955271601677,
0.004883442539721727,
0.018185921013355255,
0.05262787640094757,
0.0008354434976354241,
-0.01120552234351635,
-0.010880826972424984,
0.02951696328818798,
0.007580714765936136,
-0.06643790006637573,
-0.020049311220645905,
-0.022362830117344856,
0.01845500059425831,
-0.013299434445798397,
-0.002461624564602971,
-0.03251875936985016,
-0.0546649768948555,
0.02169126272201538,
0.05877986177802086,
0.0193539559841156,
-0.04935064911842346
] | 0.042088
|
the requested modules include cyclic dependencies, the [`sourceTextModule.linkRequests(modules)`][] method must be called on all modules in the cycle before calling this method. ### `sourceTextModule.linkRequests(modules)` \* `modules` {vm.Module\[]} Array of `vm.Module` objects that this module depends on. The order of the modules in the array is the order of [`sourceTextModule.moduleRequests`][]. \* Returns: {undefined} Link module dependencies. This method must be called before evaluation, and can only be called once per module. The order of the module instances in the `modules` array should correspond to the order of [`sourceTextModule.moduleRequests`][] being resolved. If two module requests have the same specifier and import attributes, they must be resolved with the same module instance or an `ERR\_MODULE\_LINK\_MISMATCH` would be thrown. For example, when linking requests for this module: ```mjs import foo from 'foo'; import source Foo from 'foo'; ``` The `modules` array must contain two references to the same instance, because the two module requests are identical but in two phases. If the module has no dependencies, the `modules` array can be empty. Users can use `sourceTextModule.moduleRequests` to implement the host-defined [HostLoadImportedModule][] abstract operation in the ECMAScript specification, and using `sourceTextModule.linkRequests()` to invoke specification defined [FinishLoadingImportedModule][], on the module with all dependencies in a batch. It's up to the creator of the `SourceTextModule` to determine if the resolution of the dependencies is synchronous or asynchronous. After each module in the `modules` array is linked, call [`sourceTextModule.instantiate()`][]. ### `sourceTextModule.moduleRequests` \* Type: {ModuleRequest\[]} Dependencies of this module. The requested import dependencies of this module. The returned array is frozen to disallow any changes to it. For example, given a source text: ```mjs import foo from 'foo'; import fooAlias from 'foo'; import bar from './bar.js'; import withAttrs from '../with-attrs.ts' with { arbitraryAttr: 'attr-val' }; import source Module from 'wasm-mod.wasm'; ``` The value of the `sourceTextModule.moduleRequests` will be: ```js [ { specifier: 'foo', attributes: {}, phase: 'evaluation', }, { specifier: 'foo', attributes: {}, phase: 'evaluation', }, { specifier: './bar.js', attributes: {}, phase: 'evaluation', }, { specifier: '../with-attrs.ts', attributes: { arbitraryAttr: 'attr-val' }, phase: 'evaluation', }, { specifier: 'wasm-mod.wasm', attributes: {}, phase: 'source', }, ]; ``` ## Class: `vm.SyntheticModule` > Stability: 1 - Experimental This feature is only available with the `--experimental-vm-modules` command flag enabled. \* Extends: {vm.Module} The `vm.SyntheticModule` class provides the [Synthetic Module Record][] as defined in the WebIDL specification. The purpose of synthetic modules is to provide a generic interface for exposing non-JavaScript sources to ECMAScript module graphs. ```js const vm = require('node:vm'); const source = '{ "a": 1 }'; const module = new vm.SyntheticModule(['default'], function() { const obj = JSON.parse(source); this.setExport('default', obj); }); // Use `module` in linking... ``` ### `new vm.SyntheticModule(exportNames, evaluateCallback[, options])` \* `exportNames` {string\[]} Array of names that will be exported from the module. \* `evaluateCallback` {Function} Called when the module is evaluated. \* `options` \* `identifier` {string} String used in stack traces. \*\*Default:\*\* `'vm:module(i)'` where `i` is a context-specific ascending index. \* `context` {Object} The [contextified][] object as returned by the `vm.createContext()` method, to compile and evaluate this `Module` in. Creates a new `SyntheticModule` instance. Objects assigned to the exports of this instance may allow importers of the module to access information outside the specified `context`. Use `vm.runInContext()` to create objects in a specific context. ### `syntheticModule.setExport(name, value)` \* `name` {string} Name of the export to set. \* `value` {any} The value to set the export to. This method sets the module export binding slots with the given value. ```mjs import vm from 'node:vm'; const m = new vm.SyntheticModule(['x'], () => { m.setExport('x', 1); }); await m.evaluate(); assert.strictEqual(m.namespace.x, 1); ``` ```cjs const vm = require('node:vm'); (async () => { const m =
|
https://github.com/nodejs/node/blob/main//doc/api/vm.md
|
main
|
nodejs
|
[
-0.07245670258998871,
-0.013532731682062149,
-0.013559719547629356,
0.053255919367074966,
0.06987980753183365,
-0.03210323676466942,
0.03178950771689415,
-0.01057275291532278,
-0.02289333939552307,
-0.06866781413555145,
0.05880571901798248,
-0.004082788713276386,
0.0485718734562397,
0.01968996226787567,
0.053900159895420074,
0.07816294580698013,
0.04116150364279747,
0.006901757325977087,
0.006529584992676973,
0.061594873666763306,
0.09006544202566147,
0.07406536489725113,
0.041387297213077545,
0.003953404258936644,
-0.013969572260975838,
-0.02930421009659767,
-0.058177027851343155,
-0.016478804871439934,
0.09916861355304718,
-0.031625762581825256,
0.019810261204838753,
0.14121221005916595,
-0.13472211360931396,
0.011478033848106861,
0.027933655306696892,
0.12454964220523834,
-0.07997597008943558,
-0.09161306917667389,
0.005008984357118607,
-0.024455584585666656,
0.06277966499328613,
0.06817235052585602,
-0.05496206879615784,
-0.12359148263931274,
-0.04660365730524063,
-0.04147140681743622,
-0.011444125324487686,
0.04456629604101181,
-0.059099920094013214,
-0.01938767172396183,
-0.05866766348481178,
-0.03272406756877899,
-0.05145538970828056,
0.018786510452628136,
0.00011245276255067438,
0.025131618604063988,
0.009074262343347073,
0.04174836352467537,
0.007634466979652643,
0.04357115551829338,
-0.05248795077204704,
-0.00035858957562595606,
-0.012680845335125923,
-0.06876123696565628,
0.02932199090719223,
-0.018623609095811844,
0.03822490572929382,
0.04233549162745476,
0.003815385978668928,
-0.004362545907497406,
-0.059122323989868164,
-0.0039153448306024075,
0.024169698357582092,
0.0744410827755928,
-0.0392862968146801,
-0.020659593865275383,
-0.055736787617206573,
-0.006621594540774822,
0.0015331547474488616,
-0.10758740454912186,
-0.037496086210012436,
0.005308115854859352,
0.013593127951025963,
0.022248057648539543,
0.047510698437690735,
-0.04606487974524498,
-0.011708737351000309,
0.05632326379418373,
0.04110601544380188,
0.027300875633955002,
0.03980325534939766,
-0.09584531933069229,
-0.011448943056166172,
0.07113149017095566,
0.08491846174001694,
0.038990043103694916,
-0.02683640457689762,
0.027792714536190033,
0.026161490008234978,
0.011751844547688961,
0.0006743217236362398,
-0.028586553409695625,
0.032454073429107666,
0.04043000191450119,
0.102467380464077,
0.009755559265613556,
-0.0022115099709481,
0.010452541522681713,
-0.042219676077365875,
-0.048080042004585266,
-0.02347368374466896,
0.01600017584860325,
0.035404402762651443,
-0.09984973818063736,
-0.0691690519452095,
-0.003401305992156267,
0.059433091431856155,
0.006402339320629835,
-0.0018775307107716799,
0.03358244523406029,
0.014856113120913506,
0.012711216695606709,
0.1785232275724411,
-0.07366690039634705,
-0.013602162711322308,
-0.041000425815582275,
-0.006517134141176939,
7.469612730742992e-33,
-0.029039328917860985,
-0.0279329102486372,
-0.01200025249272585,
0.07642903923988342,
0.010298817418515682,
0.02183934673666954,
0.06160711869597435,
0.0120086083188653,
-0.06347914785146713,
-0.09460233151912689,
-0.08776306360960007,
0.05399802327156067,
-0.01918274164199829,
-0.014179939404129982,
0.018214832991361618,
-0.006344725377857685,
0.0417640283703804,
0.024193700402975082,
0.01698688045144081,
0.0427422970533371,
0.014496779069304466,
-0.01864979974925518,
0.05802850052714348,
0.017624560743570328,
-0.010943311266601086,
0.031574029475450516,
0.022878408432006836,
-0.03854338079690933,
-0.07286179810762405,
0.007284319959580898,
0.012658948078751564,
0.04025387391448021,
0.0334727019071579,
0.052157532423734665,
0.041623298078775406,
0.003787612309679389,
-0.005112672224640846,
0.005765811074525118,
-0.14966653287410736,
-0.04095606133341789,
-0.0395936593413353,
0.07568490505218506,
-0.021469013765454292,
-0.04919213056564331,
-0.021176498383283615,
-0.07740473002195358,
-0.07821135967969894,
0.08703643828630447,
0.058655157685279846,
0.0014636655105277896,
0.0027544184122234583,
0.06700258702039719,
0.06469397991895676,
-0.031258098781108856,
0.010730935260653496,
-0.010653652250766754,
-0.017249740660190582,
0.014820633456110954,
0.05397125706076622,
-0.022415369749069214,
-0.00014861812815070152,
-0.06407088041305542,
-0.06093219295144081,
0.09756595641374588,
0.07135605067014694,
0.0898871123790741,
-0.03611644729971886,
-0.018810207024216652,
0.03234519436955452,
0.015531180426478386,
-0.015179152600467205,
0.04394563287496567,
-0.095598004758358,
0.001308143837377429,
0.02407025173306465,
-0.05000991374254227,
-0.07491004467010498,
-0.09203124791383743,
-0.0030735754407942295,
-0.024866381660103798,
0.0011349815176799893,
0.026820195838809013,
0.034458134323358536,
-0.030364103615283966,
-0.06013406440615654,
-0.01048958208411932,
-0.029795126989483833,
-0.04882087931036949,
0.03808852285146713,
-0.05771849676966667,
0.046585723757743835,
-0.009423606097698212,
-0.02052852138876915,
-0.04219543933868408,
0.026993403211236,
-6.248272630870697e-33,
0.11547522246837616,
0.07206091284751892,
0.0440995953977108,
0.038260918110609055,
0.06076132133603096,
-0.031477559357881546,
-0.020547717809677124,
0.002286429749801755,
0.035656776279211044,
0.07751388847827911,
-0.028438067063689232,
0.002492195228114724,
0.040563974529504776,
-0.012497714720666409,
0.019535304978489876,
0.14411014318466187,
-0.0081725362688303,
-0.07523790001869202,
0.05473531410098076,
-0.04816204681992531,
-0.03482635319232941,
0.0760909914970398,
0.012390010058879852,
-0.07805270701646805,
-0.046285469084978104,
0.02694331295788288,
-0.03046043962240219,
-0.02317528799176216,
0.06527236104011536,
0.03577083349227905,
0.008978327736258507,
0.040182944387197495,
-0.07076281309127808,
0.0001173382843262516,
0.01765345223248005,
0.07436484843492508,
-0.003940126858651638,
0.05958160385489464,
-0.026401124894618988,
0.019362857565283775,
0.1297464668750763,
0.02493475377559662,
-0.06430570781230927,
-0.06000572070479393,
-0.012357030995190144,
-0.09486053138971329,
-0.03706604987382889,
0.022489821538329124,
-0.013259987346827984,
-0.10945048183202744,
-0.030240269377827644,
-0.03649298474192619,
-0.03989560529589653,
-0.02955693192780018,
-0.04704832658171654,
-0.03371362015604973,
0.04519806429743767,
0.11230100691318512,
0.04935853183269501,
-0.01261361874639988,
0.055904049426317215,
-0.040722522884607315,
-0.0056067476980388165,
-0.025945935398340225,
-0.03733575716614723,
0.00024218866019509733,
-0.025902345776557922,
-0.0893164724111557,
0.10105600953102112,
-0.03130391612648964,
0.03967262804508209,
0.00217886408790946,
-0.016665179282426834,
0.0023169831838458776,
-0.04678177088499069,
0.05777032673358917,
0.0030521261505782604,
0.053345706313848495,
0.03374168649315834,
-0.017895950004458427,
0.01639110967516899,
-0.04212374612689018,
0.024526583030819893,
0.09352269768714905,
-0.060752201825380325,
-0.06659149378538132,
0.039168186485767365,
0.07677056640386581,
-0.008787279948592186,
-0.0019148740684613585,
0.02178991585969925,
-0.07505886256694794,
0.002911382121965289,
0.08837658911943436,
-0.01525736041367054,
-5.723279272729087e-8,
-0.029165618121623993,
-0.03462537005543709,
-0.12543518841266632,
0.024741707369685173,
0.02225283533334732,
0.046122655272483826,
-0.011076057329773903,
0.05122290551662445,
0.04364098981022835,
0.024142662063241005,
0.0171014703810215,
0.05057699605822563,
0.012483463622629642,
0.04915819689631462,
-0.03920307382941246,
0.039078038185834885,
-0.06200666353106499,
0.009098769165575504,
-0.0574662871658802,
-0.06715396046638489,
-0.02306067757308483,
-0.03571247309446335,
0.0731191337108612,
0.07247786223888397,
-0.012570741586387157,
-0.022527748718857765,
0.04970904812216759,
0.06809119135141373,
-0.008941813372075558,
-0.04047730565071106,
-0.01653449423611164,
0.04504462331533432,
-0.1133851632475853,
-0.041530415415763855,
-0.1051797866821289,
0.06269508600234985,
-0.03702276945114136,
-0.047631993889808655,
0.07582886517047882,
0.059227198362350464,
-0.009708755649626255,
-0.03273992985486984,
-0.05991436913609505,
-0.0017923591658473015,
0.0718124657869339,
-0.04974546283483505,
-0.06243272125720978,
-0.05885564163327217,
-0.03719989210367203,
-0.043295782059431076,
-0.014377135783433914,
-0.026062369346618652,
-0.050314679741859436,
0.012895230203866959,
-0.039977170526981354,
0.01557866483926773,
0.038984909653663635,
-0.023492911830544472,
0.01793167181313038,
-0.09650789946317673,
0.012853266671299934,
0.06808624416589737,
0.07297102361917496,
-0.10007046908140182
] | 0.031347
|
to set the export to. This method sets the module export binding slots with the given value. ```mjs import vm from 'node:vm'; const m = new vm.SyntheticModule(['x'], () => { m.setExport('x', 1); }); await m.evaluate(); assert.strictEqual(m.namespace.x, 1); ``` ```cjs const vm = require('node:vm'); (async () => { const m = new vm.SyntheticModule(['x'], () => { m.setExport('x', 1); }); await m.evaluate(); assert.strictEqual(m.namespace.x, 1); })(); ``` ## Type: `ModuleRequest` \* Type: {Object} \* `specifier` {string} The specifier of the requested module. \* `attributes` {Object} The `"with"` value passed to the [WithClause][] in a [ImportDeclaration][], or an empty object if no value was provided. \* `phase` {string} The phase of the requested module (`"source"` or `"evaluation"`). A `ModuleRequest` represents the request to import a module with given import attributes and phase. ## `vm.compileFunction(code[, params[, options]])` \* `code` {string} The body of the function to compile. \* `params` {string\[]} An array of strings containing all parameters for the function. \* `options` {Object} \* `filename` {string} Specifies the filename used in stack traces produced by this script. \*\*Default:\*\* `''`. \* `lineOffset` {number} Specifies the line number offset that is displayed in stack traces produced by this script. \*\*Default:\*\* `0`. \* `columnOffset` {number} Specifies the first-line column number offset that is displayed in stack traces produced by this script. \*\*Default:\*\* `0`. \* `cachedData` {Buffer|TypedArray|DataView} Provides an optional `Buffer` or `TypedArray`, or `DataView` with V8's code cache data for the supplied source. This must be produced by a prior call to [`vm.compileFunction()`][] with the same `code` and `params`. \* `produceCachedData` {boolean} Specifies whether to produce new cache data. \*\*Default:\*\* `false`. \* `parsingContext` {Object} The [contextified][] object in which the said function should be compiled in. \* `contextExtensions` {Object\[]} An array containing a collection of context extensions (objects wrapping the current scope) to be applied while compiling. \*\*Default:\*\* `[]`. \* `importModuleDynamically` {Function|vm.constants.USE\\_MAIN\\_CONTEXT\\_DEFAULT\\_LOADER} Used to specify the how the modules should be loaded during the evaluation of this function when `import()` is called. This option is part of the experimental modules API. We do not recommend using it in a production environment. For detailed information, see [Support of dynamic `import()` in compilation APIs][]. \* Returns: {Function} Compiles the given code into the provided context (if no context is supplied, the current context is used), and returns it wrapped inside a function with the given `params`. ## `vm.constants` \* Type: {Object} Returns an object containing commonly used constants for VM operations. ### `vm.constants.USE\_MAIN\_CONTEXT\_DEFAULT\_LOADER` > Stability: 1.1 - Active development A constant that can be used as the `importModuleDynamically` option to `vm.Script` and `vm.compileFunction()` so that Node.js uses the default ESM loader from the main context to load the requested module. For detailed information, see [Support of dynamic `import()` in compilation APIs][]. ## `vm.createContext([contextObject[, options]])` \* `contextObject` {Object|vm.constants.DONT\\_CONTEXTIFY|undefined} Either [`vm.constants.DONT\_CONTEXTIFY`][] or an object that will be [contextified][]. If `undefined`, an empty contextified object will be created for backwards compatibility. \* `options` {Object} \* `name` {string} Human-readable name of the newly created context. \*\*Default:\*\* `'VM Context i'`, where `i` is an ascending numerical index of the created context. \* `origin` {string} [Origin][origin] corresponding to the newly created context for display purposes. The origin should be formatted like a URL, but with only the scheme, host, and port (if necessary), like the value of the [`url.origin`][] property of a [`URL`][] object. Most notably, this string should omit the trailing slash, as that denotes a path. \*\*Default:\*\* `''`. \* `codeGeneration` {Object} \* `strings` {boolean} If set to false any calls to `eval` or function constructors (`Function`, `GeneratorFunction`, etc) will throw an `EvalError`. \*\*Default:\*\* `true`. \* `wasm` {boolean} If set to false any attempt to
|
https://github.com/nodejs/node/blob/main//doc/api/vm.md
|
main
|
nodejs
|
[
-0.0193770844489336,
0.022457346320152283,
-0.08485501259565353,
0.0941881537437439,
-0.01208386942744255,
0.048101916909217834,
0.0016770669026300311,
0.06795352697372437,
-0.0692003071308136,
-0.020718170329928398,
-0.036666881293058395,
-0.10306228697299957,
0.01077903900295496,
-0.028402036055922508,
0.049039579927921295,
0.07272528111934662,
0.016281157732009888,
0.027866041287779808,
-0.009963699616491795,
0.07416746020317078,
0.07043197751045227,
0.03508612513542175,
0.0628046989440918,
-0.03336677700281143,
0.005435223691165447,
-0.05512959882616997,
-0.006343006156384945,
0.017815345898270607,
0.0880807489156723,
-0.016659356653690338,
-0.009024297818541527,
0.058868348598480225,
-0.06823940575122833,
0.06977111101150513,
0.04578683152794838,
0.17139337956905365,
-0.05939152464270592,
-0.11199190467596054,
0.02890549600124359,
-0.0300072580575943,
0.12260019779205322,
0.0875970795750618,
-0.03599948808550835,
-0.12273690849542618,
0.04191364347934723,
0.003305745543912053,
0.011755689047276974,
0.007101422641426325,
-0.02733677066862583,
0.019482199102640152,
0.01144564338028431,
-0.026936043053865433,
-0.05008038505911827,
-0.030359340831637383,
-0.026012253016233444,
0.01787322200834751,
0.040056630969047546,
0.0018847304163500667,
0.03143751621246338,
0.02053963951766491,
0.02924288623034954,
-0.016080733388662338,
0.06231299415230751,
-0.007926727645099163,
-0.0014850464649498463,
-0.033796582370996475,
-0.06817710399627686,
0.07416994124650955,
0.0026769391261041164,
0.010196242481470108,
-0.1019948273897171,
0.05769028514623642,
-0.020356185734272003,
-0.009137576445937157,
-0.0517251193523407,
-0.037392470985651016,
-0.04529528692364693,
0.025500435382127762,
0.05328263342380524,
0.0025999166537076235,
-0.01383792795240879,
0.011838187463581562,
-0.09552323818206787,
0.04762895777821541,
-0.01110275462269783,
0.1056145504117012,
-0.016896821558475494,
0.03329892456531525,
-0.030318772420287132,
0.05556080490350723,
-0.12385835498571396,
-0.11270633339881897,
-0.04083723574876785,
0.11653023213148117,
-0.021911274641752243,
0.00712206494063139,
0.07360180467367172,
0.06829454749822617,
0.05966288968920708,
-0.035682547837495804,
0.0006044490146450698,
0.0308592040091753,
-0.01606370136141777,
-0.021515117958188057,
0.004261321388185024,
-0.029158160090446472,
0.02907075546681881,
-0.04651413857936859,
-0.05906764790415764,
-0.0018564554629847407,
0.02901497855782509,
0.1053648367524147,
-0.002159849274903536,
-0.09501202404499054,
-0.01397776324301958,
0.04873768612742424,
0.07609406113624573,
-0.01691329851746559,
0.006705200765281916,
0.039780158549547195,
0.053443361073732376,
-0.05028225854039192,
0.0650571957230568,
0.018027400597929955,
0.05712689459323883,
-0.03976602479815483,
-0.0023558649700134993,
3.3328905204879554e-33,
-0.005077123176306486,
-0.07299204170703888,
-0.009746519848704338,
0.06647362560033798,
0.031956423074007034,
0.0422806441783905,
0.07711800932884216,
-0.009619532153010368,
-0.07195917516946793,
-0.021822761744260788,
-0.04383300244808197,
-0.013428458012640476,
-0.0008029036107473075,
0.03816975653171539,
0.025214102119207382,
-0.012840213254094124,
0.0380953885614872,
-0.02877930738031864,
0.05879099667072296,
0.016494236886501312,
0.019788455218076706,
-0.05085839703679085,
-0.041124265640974045,
-0.00039897728129290044,
0.012352134101092815,
-0.036772798746824265,
-0.03261414170265198,
0.037272509187459946,
-0.06744280457496643,
-0.03106442280113697,
-0.019370965659618378,
0.042550262063741684,
0.08015017211437225,
0.08939449489116669,
-0.000347898225300014,
-0.015614118427038193,
-0.005200602579861879,
0.030638158321380615,
-0.12256766110658646,
0.010054291225969791,
0.009943214245140553,
0.031784314662218094,
-0.04488959535956383,
0.02077011577785015,
-0.03817680478096008,
-0.05366409569978714,
-0.022732459008693695,
-0.009433533065021038,
0.08487588912248611,
-0.06925056874752045,
-0.08556506782770157,
0.058959219604730606,
0.04949156194925308,
-0.10722502321004868,
0.006092248484492302,
-0.02477112226188183,
0.029193708673119545,
-0.01983482576906681,
-0.03416536748409271,
-0.022126182913780212,
-0.07067734748125076,
0.04532072693109512,
-0.018375219777226448,
0.10168472677469254,
-0.02458898164331913,
0.058849625289440155,
-0.045908380299806595,
-0.0612390860915184,
-0.008132957853376865,
0.027272095903754234,
-0.03388155624270439,
-0.0059396144933998585,
-0.14066773653030396,
-0.04447995871305466,
0.06477108597755432,
0.026830699294805527,
-0.04809017479419708,
0.02129911072552204,
-0.02650107629597187,
-0.07324022054672241,
0.03902623802423477,
0.09292354434728622,
-0.054558973759412766,
0.0066230809316039085,
-0.00030775516643188894,
-0.07065233588218689,
-0.027439629659056664,
0.014709175564348698,
0.118216373026371,
-0.04656147584319115,
0.011852827854454517,
-0.063725046813488,
-0.03379740193486214,
-0.08168792724609375,
-0.05739499628543854,
-5.028804873094071e-33,
0.07483930885791779,
0.07425082474946976,
-0.019419314339756966,
0.0910608097910881,
-0.01183519046753645,
-0.04391572251915932,
0.004097148776054382,
0.0009402904543094337,
-0.08279354125261307,
0.05049992352724075,
-0.04575321823358536,
0.015814265236258507,
0.026751579716801643,
0.033484797924757004,
-0.037106338888406754,
0.06465192139148712,
-0.08514844626188278,
-0.01924361288547516,
0.012038232758641243,
-0.09861335903406143,
0.0076988376677036285,
0.03939614072442055,
0.053601521998643875,
0.013896294869482517,
-0.08357303589582443,
0.01268803235143423,
-0.04437302052974701,
0.05592837184667587,
-0.03817997872829437,
0.015223930589854717,
-0.048156946897506714,
0.04428935796022415,
-0.03365639969706535,
0.028225908055901527,
-0.002773751737549901,
-0.05852296203374863,
0.04486946389079094,
0.1287447065114975,
0.08965744823217392,
0.08666104078292847,
0.028080753982067108,
-0.026967912912368774,
-0.12412906438112259,
-0.0003573202411644161,
0.019455907866358757,
-0.02977563999593258,
0.00763360969722271,
0.0032592415809631348,
0.06881499290466309,
-0.032640326768159866,
0.028147388249635696,
-0.029784852638840675,
-0.058731671422719955,
0.008222969248890877,
0.001041106297634542,
-0.02782287448644638,
-0.07219959050416946,
-0.03598780184984207,
0.07834205031394958,
0.002264930633828044,
-0.01459222286939621,
-0.06496419757604599,
0.060451898723840714,
-0.008426669053733349,
-0.03406192362308502,
-0.03307189419865608,
-0.05305701494216919,
-0.009789417497813702,
0.016959792003035545,
0.021865682676434517,
-0.044818226248025894,
-0.005185133311897516,
0.013486990705132484,
0.0328679122030735,
-0.0028196098282933235,
-0.060639992356300354,
-0.02690369077026844,
0.0147640286013484,
0.08584049344062805,
0.09517758339643478,
0.018855029717087746,
0.039188604801893234,
0.018907710909843445,
0.0004472873988561332,
0.00883861817419529,
0.050900693982839584,
0.010086171329021454,
0.08765667676925659,
-0.018675781786441803,
-0.06000762805342674,
0.03771521896123886,
-0.012980201281607151,
-0.10029499232769012,
-0.02186923287808895,
-0.08258820325136185,
-5.893724619454588e-8,
-0.09323550760746002,
-0.04460752010345459,
-0.05841373652219772,
0.00453081913292408,
-0.07608724385499954,
-0.02301405742764473,
-0.008080859668552876,
-0.06562229245901108,
0.10927921533584595,
0.040546394884586334,
-0.017626196146011353,
0.00801026914268732,
0.01794224977493286,
0.019197259098291397,
-0.02553432248532772,
-0.01990026980638504,
0.025491200387477875,
0.014581051655113697,
-0.03402340039610863,
-0.02099296823143959,
0.023497512564063072,
-0.037773337215185165,
0.04104628413915634,
0.04021332785487175,
0.1131119579076767,
-0.12626832723617554,
0.021625878289341927,
0.009731023572385311,
0.08042974770069122,
0.02544020302593708,
-0.057042669504880905,
0.03635582700371742,
-0.01717332936823368,
0.009067590348422527,
-0.06140507012605667,
-0.016249824315309525,
0.030008625239133835,
-0.015091064386069775,
0.07474246621131897,
0.11102951318025589,
-0.020748304203152657,
-0.009483599103987217,
-0.06637655943632126,
0.016363218426704407,
-0.008974055759608746,
-0.04033031687140465,
-0.023347197100520134,
0.01554957777261734,
0.02768118306994438,
0.004753032699227333,
0.05441949889063835,
-0.04085766151547432,
-0.016692057251930237,
-0.020366724580526352,
-0.03688744083046913,
-0.008587722666561604,
-0.06510654836893082,
0.016166890040040016,
0.0030460827983915806,
-0.05367179214954376,
-0.04182273894548416,
-0.011296122334897518,
0.03566354140639305,
-0.05507105588912964
] | -0.001109
|
this string should omit the trailing slash, as that denotes a path. \*\*Default:\*\* `''`. \* `codeGeneration` {Object} \* `strings` {boolean} If set to false any calls to `eval` or function constructors (`Function`, `GeneratorFunction`, etc) will throw an `EvalError`. \*\*Default:\*\* `true`. \* `wasm` {boolean} If set to false any attempt to compile a WebAssembly module will throw a `WebAssembly.CompileError`. \*\*Default:\*\* `true`. \* `microtaskMode` {string} If set to `afterEvaluate`, microtasks (tasks scheduled through `Promise`s and `async function`s) will be run immediately after a script has run through [`script.runInContext()`][]. They are included in the `timeout` and `breakOnSigint` scopes in that case. \* `importModuleDynamically` {Function|vm.constants.USE\\_MAIN\\_CONTEXT\\_DEFAULT\\_LOADER} Used to specify the how the modules should be loaded when `import()` is called in this context without a referrer script or module. This option is part of the experimental modules API. We do not recommend using it in a production environment. For detailed information, see [Support of dynamic `import()` in compilation APIs][]. \* Returns: {Object} contextified object. If the given `contextObject` is an object, the `vm.createContext()` method will [prepare that object][contextified] and return a reference to it so that it can be used in calls to [`vm.runInContext()`][] or [`script.runInContext()`][]. Inside such scripts, the global object will be wrapped by the `contextObject`, retaining all of its existing properties but also having the built-in objects and functions any standard [global object][] has. Outside of scripts run by the vm module, global variables will remain unchanged. ```js const vm = require('node:vm'); global.globalVar = 3; const context = { globalVar: 1 }; vm.createContext(context); vm.runInContext('globalVar \*= 2;', context); console.log(context); // Prints: { globalVar: 2 } console.log(global.globalVar); // Prints: 3 ``` If `contextObject` is omitted (or passed explicitly as `undefined`), a new, empty [contextified][] object will be returned. When the global object in the newly created context is [contextified][], it has some quirks compared to ordinary global objects. For example, it cannot be frozen. To create a context without the contextifying quirks, pass [`vm.constants.DONT\_CONTEXTIFY`][] as the `contextObject` argument. See the documentation of [`vm.constants.DONT\_CONTEXTIFY`][] for details. The `vm.createContext()` method is primarily useful for creating a single context that can be used to run multiple scripts. For instance, if emulating a web browser, the method can be used to create a single context representing a window's global object, then run all `` tags together within that context. The provided `name` and `origin` of the context are made visible through the Inspector API. ## `vm.isContext(object)` <!-- YAML added: v0.11.7 --> \* `object` {Object} \* Returns: {boolean} Returns `true` if the given `object` object has been [contextified][] using [`vm.createContext()`][], or if it's the global object of a context created using [`vm.constants.DONT\_CONTEXTIFY`][]. ## `vm.measureMemory([options])` <!-- YAML added: v13.10.0 --> > Stability: 1 - Experimental Measure the memory known to V8 and used by all contexts known to the current V8 isolate, or the main context. \* `options` {Object} Optional. \* `mode` {string} Either `'summary'` or `'detailed'`. In summary mode, only the memory measured for the main context will be returned. In detailed mode, the memory measured for all contexts known to the current V8 isolate will be returned. \*\*Default:\*\* `'summary'` \* `execution` {string} Either `'default'` or `'eager'`. With default execution, the promise will not resolve until after the next scheduled garbage collection starts, which may take a while (or never if the program exits before the next GC). With eager execution, the GC will be started right away to measure the memory. \*\*Default:\*\* `'default'` \* Returns: {Promise} If the memory is successfully measured, the promise will resolve with an object containing information about the memory usage. Otherwise it will be rejected with an `ERR\_CONTEXT\_NOT\_INITIALIZED` error. The format of the
|
https://github.com/nodejs/node/blob/main//doc/api/vm.md
|
main
|
nodejs
|
[
-0.05248299986124039,
0.05945510044693947,
-0.04040582850575447,
0.08925284445285797,
0.009714305400848389,
-0.04605785757303238,
0.02608504146337509,
0.045013427734375,
-0.05925474688410759,
-0.013809763826429844,
0.036018505692481995,
-0.08814384043216705,
0.008873593993484974,
0.016440104693174362,
0.00794155988842249,
0.05219018831849098,
0.014626058749854565,
-0.061498142778873444,
-0.031185461208224297,
0.025310499593615532,
0.05888056382536888,
0.03723086044192314,
0.026898501440882683,
0.01006165612488985,
0.05930345878005028,
-0.051811207085847855,
0.0032846620306372643,
-0.002689674263820052,
0.017010357230901718,
0.000737353169824928,
0.05934005603194237,
0.0009547959198243916,
0.010843630880117416,
-0.026156600564718246,
0.1620873063802719,
0.18660074472427368,
0.047222040593624115,
-0.06955358386039734,
-0.030983923003077507,
-0.044853683561086655,
0.060000307857990265,
0.03418884053826332,
-0.02170148678123951,
-0.08877691626548767,
-0.06039702519774437,
-0.05624527856707573,
-0.016288483515381813,
-0.09082289040088654,
-0.12385474145412445,
-0.0011733857681974769,
-0.09274090081453323,
-0.03365616872906685,
0.0008442436810582876,
-0.041333798319101334,
0.08561690896749496,
0.007157410494983196,
-0.0008231690153479576,
0.044341959059238434,
0.032480351626873016,
-0.018659202381968498,
-0.015367629006505013,
-0.055401064455509186,
0.027112476527690887,
-0.012302855029702187,
0.0168758537620306,
-0.003673545317724347,
0.007882405072450638,
-0.03222794830799103,
0.010720695368945599,
0.0044906241819262505,
-0.10292520374059677,
-0.026679132133722305,
-0.0765705332159996,
0.07573359459638596,
-0.013782327994704247,
-0.002471130108460784,
0.05747530609369278,
0.0606195330619812,
0.030913373455405235,
-0.07566932588815689,
-0.0760716125369072,
-0.16160859167575836,
0.026496930047869682,
0.05013814941048622,
0.027421314269304276,
0.025501783937215805,
-0.0334286168217659,
0.029568688943982124,
0.035985153168439865,
0.054184820502996445,
-0.021959831938147545,
-0.098199263215065,
0.0036997199058532715,
0.03559514880180359,
0.05039423704147339,
0.0007289080531336367,
-0.06848949193954468,
-0.01346849650144577,
0.007045741192996502,
0.018784403800964355,
-0.04781711846590042,
-0.04547351971268654,
0.056054022163152695,
-0.040893103927373886,
0.05702032521367073,
0.011876227334141731,
0.030994245782494545,
-0.018469560891389847,
0.10127870738506317,
-0.08255070447921753,
0.0012066429480910301,
0.006377047393471003,
0.052177220582962036,
-0.02215469628572464,
-0.012186587788164616,
0.016088150441646576,
0.06312933564186096,
0.017961367964744568,
0.045336004346609116,
0.1394309550523758,
0.06705878674983978,
0.023629631847143173,
0.09390968084335327,
0.0066151865758001804,
0.01591559499502182,
-0.07730383425951004,
0.0511772595345974,
2.7988318454987118e-33,
0.02235671505331993,
-0.0905957967042923,
-0.03812941163778305,
0.0043645878322422504,
0.09291192889213562,
-0.048600684851408005,
0.0813010111451149,
0.05425826087594032,
-0.029079435393214226,
-0.02800430916249752,
-0.0398535430431366,
-0.01010346319526434,
0.01620546355843544,
0.045644085854291916,
0.010568986646831036,
-0.017887255176901817,
0.0418023020029068,
-0.09967927634716034,
0.05386161804199219,
0.034587014466524124,
0.04079451411962509,
0.011932957917451859,
-0.019554564729332924,
-0.04374600201845169,
-0.04400729760527611,
-0.05259659141302109,
0.0368863120675087,
0.02970174513757229,
0.015957146883010864,
0.024132292717695236,
-0.044757500290870667,
-0.039036188274621964,
-0.028563980013132095,
0.056957442313432693,
0.013246316462755203,
0.07344645261764526,
-0.08123721927404404,
0.017211342230439186,
-0.10048531740903854,
0.013242881745100021,
-0.037587881088256836,
0.015226299874484539,
-0.099275141954422,
0.026872260496020317,
0.036670003086328506,
-0.08531738072633743,
-0.08692990988492966,
0.02543632499873638,
0.06719417124986649,
0.0052308873273432255,
-0.018869075924158096,
0.06181977316737175,
0.14606702327728271,
0.01063079759478569,
-0.010257907211780548,
0.00522700184956193,
-0.01415225025266409,
-0.022894375026226044,
0.028726359829306602,
-0.07128001004457474,
-0.00987643375992775,
0.013297450728714466,
-0.04441073536872864,
0.026035653427243233,
0.009992247447371483,
-0.009340028278529644,
0.03903710097074509,
0.0058596134185791016,
-0.016291126608848572,
0.00946910958737135,
-0.03160923346877098,
-0.03978927806019783,
-0.035371072590351105,
0.060942113399505615,
-0.04919029399752617,
-0.005799965467303991,
0.006628825794905424,
-0.04104132950305939,
-0.03759750351309776,
-0.05956157669425011,
0.03218936175107956,
0.023944759741425514,
0.01841888017952442,
-0.05324741080403328,
-0.0436912402510643,
-0.016712652519345284,
-0.06752905994653702,
-0.04347214475274086,
0.008381777442991734,
0.0005367520498111844,
0.04480557516217232,
-0.14706122875213623,
-0.05639495700597763,
0.015334013849496841,
-0.08505559712648392,
-7.456395766135934e-33,
0.09361109882593155,
0.07695980370044708,
-0.03448722884058952,
0.04982081428170204,
-0.06729341298341751,
-0.0366082563996315,
0.061755817383527756,
-0.009525214321911335,
-0.053490448743104935,
-0.044026121497154236,
-0.017803046852350235,
0.03227904066443443,
0.02619817480444908,
0.0035899453796446323,
0.04173527657985687,
0.11255448311567307,
-0.03291315212845802,
-0.11047074943780899,
0.07498424500226974,
-0.023176826536655426,
-0.013720359653234482,
0.08308197557926178,
0.002481355331838131,
0.03207904472947121,
-0.06534875184297562,
0.014497869648039341,
0.017674556002020836,
-0.04549669474363327,
-0.04572354257106781,
0.054658010601997375,
-0.030524760484695435,
0.09660530835390091,
-0.06687469780445099,
-0.010368465445935726,
-0.02150079235434532,
-0.027769936248660088,
-0.04032747074961662,
-0.01688254624605179,
0.020431505516171455,
-0.07678729295730591,
0.12529315054416656,
0.05232518911361694,
-0.04859032481908798,
0.018807129934430122,
0.011751110665500164,
0.03575393185019493,
-0.04721957445144653,
-0.012875804677605629,
-0.018100325018167496,
-0.01935040019452572,
-0.06113039329648018,
-0.005881513003259897,
-0.004225246608257294,
0.034471869468688965,
-0.05616701394319534,
-0.03826580569148064,
-0.004156280774623156,
-0.0262764859944582,
-0.0566566176712513,
0.019571827724575996,
-0.06685737520456314,
-0.027965795248746872,
0.03202924132347107,
-0.03686513751745224,
-0.04255470633506775,
0.026034804061055183,
-0.09498713910579681,
0.011364255100488663,
-0.000067897628468927,
-0.03569081798195839,
0.015073289163410664,
-0.003067507641389966,
-0.05087495967745781,
-0.01839469186961651,
-0.12421201169490814,
0.0949750766158104,
-0.016387751325964928,
-0.0011918713571503758,
0.031640443950891495,
0.08431258797645569,
0.034031834453344345,
0.06700906157493591,
-0.015242394059896469,
0.0175956878811121,
-0.05468755215406418,
-0.10157892853021622,
-0.02050597220659256,
0.0982629582285881,
-0.0724588930606842,
0.005669185426086187,
0.03822437301278114,
-0.041659850627183914,
-0.010922755114734173,
0.01133959461003542,
-0.012826039455831051,
-5.906709432679236e-8,
-0.019031820818781853,
-0.010465618222951889,
-0.08790678530931473,
0.008037940599024296,
0.003857331583276391,
-0.01022208109498024,
-0.06238068640232086,
-0.05097547173500061,
0.04699043184518814,
0.0053862715139985085,
0.03679396212100983,
-0.010900379158556461,
-0.012253683991730213,
0.04398403316736221,
-0.07618904113769531,
0.032607462257146835,
-0.07064443081617355,
0.06147616729140282,
-0.006928823888301849,
-0.030760785564780235,
0.02933748997747898,
-0.06459193676710129,
-0.035600412636995316,
0.0008881692192517221,
0.07955849915742874,
0.018931658938527107,
-0.030104225501418114,
0.06345491111278534,
-0.07051007449626923,
0.011282559484243393,
-0.034805841743946075,
0.030797479674220085,
-0.0462016724050045,
0.00901526678353548,
-0.09580174833536148,
0.05115331709384918,
0.05556805059313774,
-0.08947400748729706,
0.07806800305843353,
0.022334525361657143,
0.034753963351249695,
0.045213352888822556,
-0.004909538198262453,
-0.0035922599490731955,
-0.009419540874660015,
-0.03915243595838547,
-0.03561241552233696,
0.05891131982207298,
-0.01585974544286728,
-0.01949053443968296,
-0.012400510720908642,
0.0019959555938839912,
-0.08350024372339249,
0.046769026666879654,
0.03080245666205883,
0.021796859800815582,
0.017629316076636314,
0.0009692091844044626,
-0.051025211811065674,
0.027008309960365295,
0.06551752239465714,
-0.015529436059296131,
0.047145284712314606,
-0.11291780322790146
] | 0.057289
|
eager execution, the GC will be started right away to measure the memory. \*\*Default:\*\* `'default'` \* Returns: {Promise} If the memory is successfully measured, the promise will resolve with an object containing information about the memory usage. Otherwise it will be rejected with an `ERR\_CONTEXT\_NOT\_INITIALIZED` error. The format of the object that the returned Promise may resolve with is specific to the V8 engine and may change from one version of V8 to the next. The returned result is different from the statistics returned by `v8.getHeapSpaceStatistics()` in that `vm.measureMemory()` measure the memory reachable by each V8 specific contexts in the current instance of the V8 engine, while the result of `v8.getHeapSpaceStatistics()` measure the memory occupied by each heap space in the current V8 instance. ```js const vm = require('node:vm'); // Measure the memory used by the main context. vm.measureMemory({ mode: 'summary' }) // This is the same as vm.measureMemory() .then((result) => { // The current format is: // { // total: { // jsMemoryEstimate: 2418479, jsMemoryRange: [ 2418479, 2745799 ] // } // } console.log(result); }); const context = vm.createContext({ a: 1 }); vm.measureMemory({ mode: 'detailed', execution: 'eager' }) .then((result) => { // Reference the context here so that it won't be GC'ed // until the measurement is complete. console.log(context.a); // { // total: { // jsMemoryEstimate: 2574732, // jsMemoryRange: [ 2574732, 2904372 ] // }, // current: { // jsMemoryEstimate: 2438996, // jsMemoryRange: [ 2438996, 2768636 ] // }, // other: [ // { // jsMemoryEstimate: 135736, // jsMemoryRange: [ 135736, 465376 ] // } // ] // } console.log(result); }); ``` ## `vm.runInContext(code, contextifiedObject[, options])` <!-- YAML added: v0.3.1 changes: - version: - v21.7.0 - v20.12.0 pr-url: https://github.com/nodejs/node/pull/51244 description: Added support for `vm.constants.USE\_MAIN\_CONTEXT\_DEFAULT\_LOADER`. - version: - v17.0.0 - v16.12.0 pr-url: https://github.com/nodejs/node/pull/40249 description: Added support for import attributes to the `importModuleDynamically` parameter. - version: v6.3.0 pr-url: https://github.com/nodejs/node/pull/6635 description: The `breakOnSigint` option is supported now. --> \* `code` {string} The JavaScript code to compile and run. \* `contextifiedObject` {Object} The [contextified][] object that will be used as the `global` when the `code` is compiled and run. \* `options` {Object|string} \* `filename` {string} Specifies the filename used in stack traces produced by this script. \*\*Default:\*\* `'evalmachine.<anonymous>'`. \* `lineOffset` {number} Specifies the line number offset that is displayed in stack traces produced by this script. \*\*Default:\*\* `0`. \* `columnOffset` {number} Specifies the first-line column number offset that is displayed in stack traces produced by this script. \*\*Default:\*\* `0`. \* `displayErrors` {boolean} When `true`, if an [`Error`][] occurs while compiling the `code`, the line of code causing the error is attached to the stack trace. \*\*Default:\*\* `true`. \* `timeout` {integer} Specifies the number of milliseconds to execute `code` before terminating execution. If execution is terminated, an [`Error`][] will be thrown. This value must be a strictly positive integer. \* `breakOnSigint` {boolean} If `true`, receiving `SIGINT` (<kbd>Ctrl</kbd>+<kbd>C</kbd>) will terminate execution and throw an [`Error`][]. Existing handlers for the event that have been attached via `process.on('SIGINT')` are disabled during script execution, but continue to work after that. \*\*Default:\*\* `false`. \* `cachedData` {Buffer|TypedArray|DataView} Provides an optional `Buffer` or `TypedArray`, or `DataView` with V8's code cache data for the supplied source. \* `importModuleDynamically` {Function|vm.constants.USE\\_MAIN\\_CONTEXT\\_DEFAULT\\_LOADER} Used to specify the how the modules should be loaded during the evaluation of this script when `import()` is called. This option is part of the experimental modules API. We do not recommend using it in a production environment. For detailed information, see [Support of dynamic `import()` in compilation APIs][]. The `vm.runInContext()` method compiles `code`, runs it within the context of the `contextifiedObject`, then returns the result. Running code does not have access
|
https://github.com/nodejs/node/blob/main//doc/api/vm.md
|
main
|
nodejs
|
[
-0.08305878937244415,
0.04413631930947304,
-0.02325531095266342,
0.10025192052125931,
0.028001772239804268,
-0.031195523217320442,
-0.022057561203837395,
0.07908464968204498,
0.017317356541752815,
-0.04355129599571228,
-0.04060039669275284,
0.015782508999109268,
-0.041106995195150375,
-0.040567897260189056,
-0.004563937429338694,
-0.05568942800164223,
0.08225253969430923,
-0.011420204304158688,
-0.02994922734797001,
-0.029279831796884537,
0.09558257460594177,
0.01630626805126667,
0.06676215678453445,
-0.03015582077205181,
0.012316339649260044,
0.03169255331158638,
-0.08503264933824539,
0.015510027296841145,
0.08258549124002457,
-0.00936395488679409,
0.040130868554115295,
-0.01490175910294056,
-0.031222553923726082,
0.05738211050629616,
0.002581800566986203,
0.08296268433332443,
-0.09901870042085648,
-0.09835582226514816,
-0.005413659382611513,
-0.026358123868703842,
0.018805144354701042,
0.12403218448162079,
-0.04680363088846207,
0.03938319906592369,
0.0745343342423439,
0.06100974231958389,
-0.053808629512786865,
0.01958955079317093,
-0.11266088485717773,
-0.017050262540578842,
-0.013212630525231361,
-0.009071830660104752,
-0.028910066932439804,
0.01016012392938137,
-0.030376655980944633,
0.08675228804349899,
-0.017964571714401245,
-0.01122600119560957,
-0.036572568118572235,
0.0690799281001091,
-0.0905972272157669,
-0.08327853679656982,
-0.0027756928466260433,
-0.03504829853773117,
-0.00967853982001543,
-0.05042469501495361,
0.11782855540513992,
0.010995832271873951,
-0.02206302247941494,
0.0052794781513512135,
0.03853989765048027,
0.08376336097717285,
-0.009519635699689388,
-0.03781875967979431,
-0.07063958048820496,
-0.006842807400971651,
-0.0821068063378334,
0.028787454590201378,
0.06695610284805298,
-0.06447550654411316,
0.033763203769922256,
-0.035116251558065414,
-0.03345708176493645,
0.017115704715251923,
-0.025542406365275383,
0.013059480115771294,
0.03851427137851715,
-0.03426352143287659,
0.05190790817141533,
-0.004860464483499527,
-0.020312247797846794,
-0.06890106201171875,
-0.12028653919696808,
0.08757755905389786,
0.00006573386781383306,
-0.009524855762720108,
0.0523003451526165,
-0.026035934686660767,
0.01542886532843113,
-0.007680604699999094,
-0.0008509594481438398,
0.04915798455476761,
0.1101999431848526,
0.06473340094089508,
0.03687848150730133,
0.037887755781412125,
-0.07414326071739197,
0.06856965273618698,
0.002308530267328024,
-0.005548743065446615,
0.05477207526564598,
0.07759105414152145,
0.04467884823679924,
0.03373370319604874,
0.05506749823689461,
-0.007256519049406052,
0.028537606820464134,
-0.05027878284454346,
0.09255550056695938,
0.11146322637796402,
0.07868193835020065,
-0.033371951431035995,
0.09693540632724762,
-0.014032338745892048,
-0.05586601421236992,
-0.048431579023599625,
-0.0519087128341198,
3.025399749083069e-33,
0.00006837387627456337,
-0.11034012585878372,
0.024409206584095955,
0.03162495791912079,
-0.03286011144518852,
0.09361889958381653,
-0.0694490522146225,
0.048811156302690506,
-0.016216669231653214,
0.029895026236772537,
-0.02094016782939434,
0.0934305340051651,
-0.03670371696352959,
-0.0029400873463600874,
0.0462980680167675,
0.056967563927173615,
0.007990412414073944,
0.008448248729109764,
-0.02242058329284191,
0.07030168175697327,
-0.008611490949988365,
0.020136281847953796,
0.0020454968325793743,
0.00479613384231925,
0.055372077971696854,
-0.025505581870675087,
-0.015693800523877144,
0.018082303926348686,
-0.08898888528347015,
-0.007029296830296516,
0.012100214138627052,
0.0027276582550257444,
-0.09914488345384598,
0.034919559955596924,
0.054544106125831604,
0.008093059994280338,
-0.025411784648895264,
-0.05856567621231079,
-0.11678895354270935,
-0.0905059427022934,
0.020306160673499107,
0.03718660771846771,
0.031116360798478127,
-0.11397628486156464,
-0.1230548545718193,
-0.11427424103021622,
-0.019709279760718346,
-0.06552688032388687,
0.08702144026756287,
0.07554920017719269,
0.021122325211763382,
-0.04199884459376335,
-0.00047816173173487186,
0.00292951799929142,
0.03122149035334587,
0.028181051835417747,
0.07453976571559906,
0.024657433852553368,
0.0291086845099926,
0.06516353785991669,
0.005896462593227625,
-0.05249273404479027,
-0.015966620296239853,
0.012594211846590042,
-0.007150718476623297,
0.04548918455839157,
-0.08146029710769653,
0.026625322178006172,
-0.00182406569365412,
0.037548668682575226,
0.005748700350522995,
-0.03315427899360657,
-0.00015381374396383762,
0.043899714946746826,
0.038768377155065536,
-0.03587538003921509,
-0.016637137159705162,
-0.03749792277812958,
-0.11609206348657608,
-0.06538785248994827,
0.10432402044534683,
0.033990927040576935,
-0.028336336836218834,
0.043520502746105194,
-0.07099901884794235,
0.03761885315179825,
0.019862525165081024,
-0.0207871925085783,
0.028644736856222153,
0.04941472411155701,
-0.012346337549388409,
-0.021776840090751648,
0.010960143059492111,
0.018224528059363365,
-0.13878796994686127,
-4.5090890658947823e-33,
0.047588545829057693,
0.023999130353331566,
-0.0048116398975253105,
0.08622977882623672,
0.030105074867606163,
-0.07214509695768356,
0.04376289248466492,
-0.02149137295782566,
-0.04070816934108734,
-0.04310225322842598,
-0.016754359006881714,
0.013420471921563148,
0.06533034890890121,
0.0629250779747963,
0.03354252502322197,
0.0737811028957367,
-0.008848553523421288,
-0.12345217913389206,
0.003571190172806382,
0.0013824992347508669,
0.026374120265245438,
-0.04076053947210312,
0.06070778891444206,
-0.07640483230352402,
-0.03256811201572418,
0.02344493381679058,
-0.04953905940055847,
-0.023756248876452446,
-0.04135981947183609,
-0.07219508290290833,
-0.006329603958874941,
-0.015979968011379242,
-0.06798258423805237,
0.023495733737945557,
0.04570699483156204,
-0.07798099517822266,
0.03919981047511101,
0.056906551122665405,
-0.00557445315644145,
-0.037450335919857025,
0.05839792266488075,
0.03863165155053139,
-0.04086415842175484,
-0.004407198633998632,
-0.017503200098872185,
0.045409318059682846,
0.03317970037460327,
-0.0353025458753109,
0.07486259937286377,
-0.015335957519710064,
0.011361691169440746,
0.024919331073760986,
-0.06440790742635727,
0.10656899958848953,
-0.06025306507945061,
-0.09045542031526566,
0.013690678402781487,
-0.05796597898006439,
0.03614276275038719,
-0.006059179548174143,
0.04152765870094299,
-0.054888393729925156,
-0.06551001965999603,
-0.0680428072810173,
-0.05326320603489876,
-0.010319894179701805,
-0.05011390522122383,
-0.04942571371793747,
0.07254093885421753,
0.037380144000053406,
-0.022847210988402367,
-0.054529689252376556,
-0.002924604108557105,
-0.027975639328360558,
-0.08676384389400482,
0.00725336791947484,
-0.0034489124082028866,
-0.15883594751358032,
0.05764397233724594,
-0.04596768319606781,
-0.0418185293674469,
0.037609077990055084,
-0.010090688243508339,
0.018095837906003,
-0.018014734610915184,
0.009611506015062332,
0.011006933636963367,
0.002951895585283637,
-0.03399643301963806,
0.012342994101345539,
0.01735948771238327,
-0.004406625870615244,
-0.07562287151813507,
-0.0043957713060081005,
-0.002957769203931093,
-4.9883915664850065e-8,
-0.00425760867074132,
-0.023233506828546524,
-0.0013688659528270364,
-0.009531443007290363,
0.05739365145564079,
-0.07473480701446533,
0.011786242946982384,
0.10535731166601181,
0.024062613025307655,
0.027652017772197723,
0.09251999855041504,
0.054035622626543045,
-0.0056797051802277565,
-0.0024369105231016874,
0.00169649301096797,
0.07268853485584259,
0.003930915612727404,
0.02051232010126114,
-0.008929399773478508,
0.0030845231376588345,
-0.02325998805463314,
0.00024336471688002348,
-0.0032192938961088657,
0.012209148146212101,
-0.004425913095474243,
-0.0897892564535141,
0.07498492300510406,
0.09426753222942352,
0.0072240885347127914,
-0.01731286197900772,
-0.04242028295993805,
0.06717106699943542,
0.04840853437781334,
-0.07598786801099777,
-0.03214547410607338,
0.026298288255929947,
-0.04530269652605057,
0.03814928978681564,
0.08510740846395493,
0.027842871844768524,
0.006725413259118795,
0.010843846015632153,
0.0005657917936332524,
0.06260816007852554,
0.018873140215873718,
-0.007055452559143305,
-0.002350034425035119,
-0.01764165237545967,
0.0012494332622736692,
-0.0053090923465788364,
-0.019183209165930748,
-0.019358815625309944,
-0.0924740731716156,
0.08745426684617996,
-0.05243196710944176,
-0.06001032516360283,
0.03221193701028824,
-0.07389047741889954,
-0.004884583409875631,
-0.010384059511125088,
-0.016595041379332542,
0.01606731303036213,
-0.014787324704229832,
-0.04975153133273125
] | 0.078648
|
part of the experimental modules API. We do not recommend using it in a production environment. For detailed information, see [Support of dynamic `import()` in compilation APIs][]. The `vm.runInContext()` method compiles `code`, runs it within the context of the `contextifiedObject`, then returns the result. Running code does not have access to the local scope. The `contextifiedObject` object \_must\_ have been previously [contextified][] using the [`vm.createContext()`][] method. If `options` is a string, then it specifies the filename. The following example compiles and executes different scripts using a single [contextified][] object: ```js const vm = require('node:vm'); const contextObject = { globalVar: 1 }; vm.createContext(contextObject); for (let i = 0; i < 10; ++i) { vm.runInContext('globalVar \*= 2;', contextObject); } console.log(contextObject); // Prints: { globalVar: 1024 } ``` ## `vm.runInNewContext(code[, contextObject[, options]])` <!-- YAML added: v0.3.1 changes: - version: - v22.8.0 - v20.18.0 pr-url: https://github.com/nodejs/node/pull/54394 description: The `contextObject` argument now accepts `vm.constants.DONT\_CONTEXTIFY`. - version: - v21.7.0 - v20.12.0 pr-url: https://github.com/nodejs/node/pull/51244 description: Added support for `vm.constants.USE\_MAIN\_CONTEXT\_DEFAULT\_LOADER`. - version: - v17.0.0 - v16.12.0 pr-url: https://github.com/nodejs/node/pull/40249 description: Added support for import attributes to the `importModuleDynamically` parameter. - version: v14.6.0 pr-url: https://github.com/nodejs/node/pull/34023 description: The `microtaskMode` option is supported now. - version: v10.0.0 pr-url: https://github.com/nodejs/node/pull/19016 description: The `contextCodeGeneration` option is supported now. - version: v6.3.0 pr-url: https://github.com/nodejs/node/pull/6635 description: The `breakOnSigint` option is supported now. --> \* `code` {string} The JavaScript code to compile and run. \* `contextObject` {Object|vm.constants.DONT\\_CONTEXTIFY|undefined} Either [`vm.constants.DONT\_CONTEXTIFY`][] or an object that will be [contextified][]. If `undefined`, an empty contextified object will be created for backwards compatibility. \* `options` {Object|string} \* `filename` {string} Specifies the filename used in stack traces produced by this script. \*\*Default:\*\* `'evalmachine.<anonymous>'`. \* `lineOffset` {number} Specifies the line number offset that is displayed in stack traces produced by this script. \*\*Default:\*\* `0`. \* `columnOffset` {number} Specifies the first-line column number offset that is displayed in stack traces produced by this script. \*\*Default:\*\* `0`. \* `displayErrors` {boolean} When `true`, if an [`Error`][] occurs while compiling the `code`, the line of code causing the error is attached to the stack trace. \*\*Default:\*\* `true`. \* `timeout` {integer} Specifies the number of milliseconds to execute `code` before terminating execution. If execution is terminated, an [`Error`][] will be thrown. This value must be a strictly positive integer. \* `breakOnSigint` {boolean} If `true`, receiving `SIGINT` (<kbd>Ctrl</kbd>+<kbd>C</kbd>) will terminate execution and throw an [`Error`][]. Existing handlers for the event that have been attached via `process.on('SIGINT')` are disabled during script execution, but continue to work after that. \*\*Default:\*\* `false`. \* `contextName` {string} Human-readable name of the newly created context. \*\*Default:\*\* `'VM Context i'`, where `i` is an ascending numerical index of the created context. \* `contextOrigin` {string} [Origin][origin] corresponding to the newly created context for display purposes. The origin should be formatted like a URL, but with only the scheme, host, and port (if necessary), like the value of the [`url.origin`][] property of a [`URL`][] object. Most notably, this string should omit the trailing slash, as that denotes a path. \*\*Default:\*\* `''`. \* `contextCodeGeneration` {Object} \* `strings` {boolean} If set to false any calls to `eval` or function constructors (`Function`, `GeneratorFunction`, etc) will throw an `EvalError`. \*\*Default:\*\* `true`. \* `wasm` {boolean} If set to false any attempt to compile a WebAssembly module will throw a `WebAssembly.CompileError`. \*\*Default:\*\* `true`. \* `cachedData` {Buffer|TypedArray|DataView} Provides an optional `Buffer` or `TypedArray`, or `DataView` with V8's code cache data for the supplied source. \* `importModuleDynamically` {Function|vm.constants.USE\\_MAIN\\_CONTEXT\\_DEFAULT\\_LOADER} Used to specify the how the modules should be loaded during the evaluation of this script when `import()` is called. This option is part of the experimental modules API. We do not recommend using it in a production environment.
|
https://github.com/nodejs/node/blob/main//doc/api/vm.md
|
main
|
nodejs
|
[
-0.05069348216056824,
0.03854374960064888,
-0.05914042517542839,
0.09058461338281631,
0.06521253287792206,
-0.05908907204866409,
0.034297190606594086,
0.10266988724470139,
-0.011765526607632637,
-0.06920627504587173,
0.027077337726950645,
-0.00667016115039587,
-0.03660425543785095,
0.013820254243910313,
0.052092306315898895,
-0.006804728414863348,
0.05662468820810318,
0.01642744243144989,
-0.007229021284729242,
0.036086004227399826,
0.01617109403014183,
0.024757057428359985,
0.025355612859129906,
-0.06297295540571213,
0.03301248699426651,
0.0016750406939536333,
-0.016420554369688034,
0.0027218074537813663,
0.07513075321912766,
0.028056742623448372,
0.0386679507791996,
0.06842952966690063,
-0.06636421382427216,
0.009014876559376717,
-0.012559084221720695,
0.09844600409269333,
-0.05253470689058304,
-0.11310723423957825,
-0.0032788049429655075,
0.0016898015746846795,
0.048613663762807846,
0.1323121339082718,
-0.09521911293268204,
-0.06217874214053154,
-0.016756944358348846,
-0.0637158453464508,
-0.008959025144577026,
-0.008973285555839539,
-0.11062834411859512,
0.0011683845659717917,
-0.054481033235788345,
-0.031236229464411736,
-0.03024083562195301,
-0.08060254156589508,
-0.002434208057820797,
-0.010843804106116295,
0.011913963593542576,
0.04677610471844673,
0.03182734176516533,
0.0944085419178009,
-0.06778010725975037,
-0.003203909145668149,
-0.0046961018815636635,
-0.017882978543639183,
0.06027727946639061,
0.03283669054508209,
0.016888974234461784,
0.03011447750031948,
0.0501229427754879,
-0.0670892745256424,
-0.06498751789331436,
0.046657610684633255,
0.030607381835579872,
0.02047990821301937,
-0.04164958372712135,
-0.0188266783952713,
-0.03591051325201988,
0.024736229330301285,
0.04095005244016647,
-0.07402924448251724,
0.031668949872255325,
-0.0724005326628685,
-0.009282885119318962,
0.03147107735276222,
-0.0504864826798439,
0.12394315004348755,
-0.021522901952266693,
0.025947727262973785,
0.06823624670505524,
-0.000509702309500426,
-0.05021188408136368,
-0.12531764805316925,
-0.045551612973213196,
0.02948295883834362,
0.0729311928153038,
-0.010436395183205605,
-0.02957017347216606,
0.021192161366343498,
0.06245335191488266,
-0.015365385450422764,
-0.04844839498400688,
-0.04072503000497818,
0.0066698212176561356,
0.031411197036504745,
0.046247709542512894,
0.02167632430791855,
0.033682405948638916,
-0.020920969545841217,
-0.006556729786098003,
-0.013172369450330734,
-0.016182836145162582,
0.10765810310840607,
0.01203768141567707,
-0.0768907219171524,
-0.033201560378074646,
-0.021805264055728912,
0.07713545113801956,
-0.0378359891474247,
0.020536188036203384,
0.12255895882844925,
0.07881321012973785,
-0.045106902718544006,
0.03394697979092598,
-0.03790541738271713,
-0.04943007975816727,
-0.0647161677479744,
0.004559374414384365,
4.125287588957413e-33,
-0.020155537873506546,
-0.135238379240036,
0.05185322090983391,
0.13083922863006592,
0.0440254844725132,
-0.016261599957942963,
0.03950822725892067,
0.005209718830883503,
-0.07454048842191696,
-0.006529008969664574,
-0.009221671149134636,
0.059379223734140396,
0.011219659820199013,
0.0338050052523613,
0.060862503945827484,
0.010134448297321796,
0.01582549698650837,
0.017847826704382896,
0.04387456178665161,
0.042096201330423355,
0.020907077938318253,
0.044798921793699265,
0.009190601296722889,
-0.0004614242061506957,
0.015057621523737907,
0.012289492413401604,
0.03613675758242607,
-0.003833220573142171,
-0.023441072553396225,
-0.011371510103344917,
0.003890656866133213,
-0.009751229546964169,
-0.010386962443590164,
0.10353199392557144,
0.005431469529867172,
0.02501051314175129,
-0.07006753981113434,
0.01690746657550335,
-0.14573128521442413,
0.0060510472394526005,
0.08644320070743561,
0.008812567219138145,
-0.03535985201597214,
0.03213432803750038,
-0.08581792563199997,
-0.006566249765455723,
-0.09813928604125977,
0.062190450727939606,
0.021427588537335396,
-0.03328588232398033,
-0.0454513318836689,
0.14210563898086548,
0.03579938784241676,
-0.03143807500600815,
0.11111915856599808,
0.053260378539562225,
-0.010882977396249771,
-0.027280550450086594,
0.004888870753347874,
-0.000946304586250335,
-0.016182487830519676,
0.015538138337433338,
-0.09458240866661072,
0.1385914832353592,
-0.028109535574913025,
0.0029071676544845104,
0.014348967000842094,
-0.10573052614927292,
0.024639710783958435,
0.009261742234230042,
-0.024184472858905792,
0.027934670448303223,
-0.11050844937562943,
-0.027358656749129295,
0.06490516662597656,
-0.036969054490327835,
-0.05212188512086868,
0.043675728142261505,
-0.044005975127220154,
-0.07898791134357452,
0.03495302051305771,
0.008003462105989456,
-0.04066286236047745,
0.02273394912481308,
0.012307721190154552,
0.0410819835960865,
-0.06691649556159973,
-0.04997670277953148,
0.04367648810148239,
-0.0815281867980957,
0.04968646541237831,
-0.07283923774957657,
-0.07463321834802628,
-0.10499099642038345,
-0.019057348370552063,
-5.690528846738338e-33,
0.07446127384901047,
-0.0046295663341879845,
-0.035218335688114166,
0.06336718797683716,
-0.005765469744801521,
-0.024531764909625053,
-0.023904383182525635,
0.015867961570620537,
-0.05247983708977699,
0.02108451910316944,
-0.056283917278051376,
0.06067131087183952,
-0.01083840150386095,
0.020437950268387794,
0.01630016602575779,
0.07387307286262512,
-0.13758237659931183,
-0.09073639661073685,
0.08909288793802261,
-0.07299673557281494,
-0.015590785071253777,
0.016182594001293182,
0.08556623011827469,
-0.03989064320921898,
-0.029344120994210243,
-0.028377804905176163,
-0.09531521797180176,
0.02578034996986389,
-0.030956905335187912,
-0.013304367661476135,
-0.07193059474229813,
0.056040190160274506,
-0.09281155467033386,
0.016181303188204765,
-0.0012926553608849645,
-0.019395168870687485,
0.027794329449534416,
0.05054217576980591,
0.07184828072786331,
-0.016752028837800026,
-0.012107546441257,
0.016559218987822533,
-0.016675783321261406,
0.00964824203401804,
-0.027519870549440384,
0.03376609832048416,
-0.008805442601442337,
0.03214485943317413,
0.06765513122081757,
-0.07764894515275955,
-0.005512206349521875,
-0.03573325276374817,
-0.05509369447827339,
0.003723359201103449,
-0.00031174285686574876,
-0.06341441720724106,
0.05172356218099594,
-0.04461067169904709,
-0.0018622538773342967,
0.06983455270528793,
0.10410850495100021,
-0.09215720742940903,
-0.0127073023468256,
-0.013684188015758991,
-0.04674609377980232,
0.012788246385753155,
-0.03857657313346863,
-0.050961341708898544,
0.05162224546074867,
-0.033371616154909134,
-0.023767894133925438,
-0.050637658685445786,
-0.05492541193962097,
0.015584460459649563,
-0.043129321187734604,
0.06672275066375732,
-0.0037786192260682583,
-0.10222215950489044,
0.027102574706077576,
0.03196841850876808,
0.01646728813648224,
0.0002972267393488437,
-0.06968095153570175,
0.01090318989008665,
0.03838320076465607,
-0.017898079007864,
-0.04170134291052818,
0.0760452076792717,
0.026058683171868324,
0.038774363696575165,
0.03936993330717087,
-0.01091224979609251,
-0.0678103119134903,
0.01922226883471012,
-0.032279036939144135,
-6.610671476892094e-8,
-0.07456128299236298,
0.046264585107564926,
-0.0788121148943901,
-0.020017046481370926,
-0.029746660962700844,
0.03549813851714134,
0.024270130321383476,
0.005181911401450634,
0.08885367214679718,
0.029199650511145592,
0.0028958285693079233,
-0.052312642335891724,
0.03337258845567703,
0.0645730048418045,
-0.030197549611330032,
0.029788993299007416,
-0.0004222282732371241,
0.0841151624917984,
-0.026857541874051094,
0.06494370102882385,
0.05187128111720085,
0.06684740632772446,
0.04027417674660683,
0.03320593759417534,
0.03535698354244232,
-0.017658615484833717,
0.04791712015867233,
0.07517305016517639,
-0.018845999613404274,
0.03435855731368065,
-0.03416405990719795,
0.06410063058137894,
-0.0377340205013752,
0.004893401172012091,
-0.15757854282855988,
0.04904883727431297,
0.001584824058227241,
-0.0588088296353817,
0.05737334489822388,
0.008360758423805237,
-0.003981869667768478,
-0.020794687792658806,
-0.03704226389527321,
0.030439812690019608,
-0.001494184136390686,
-0.02735934592783451,
0.008040126413106918,
0.0019856207072734833,
-0.011757987551391125,
-0.0062257577665150166,
-0.027596617117524147,
-0.000545879767742008,
-0.06098012998700142,
0.04663865268230438,
0.009903259575366974,
-0.01747717522084713,
0.017547577619552612,
-0.02255396731197834,
0.030418669804930687,
-0.00427706353366375,
-0.0727122351527214,
-0.008141588419675827,
0.0590512752532959,
-0.045241858810186386
] | 0.104505
|
V8's code cache data for the supplied source. \* `importModuleDynamically` {Function|vm.constants.USE\\_MAIN\\_CONTEXT\\_DEFAULT\\_LOADER} Used to specify the how the modules should be loaded during the evaluation of this script when `import()` is called. This option is part of the experimental modules API. We do not recommend using it in a production environment. For detailed information, see [Support of dynamic `import()` in compilation APIs][]. \* `microtaskMode` {string} If set to `afterEvaluate`, microtasks (tasks scheduled through `Promise`s and `async function`s) will be run immediately after the script has run. They are included in the `timeout` and `breakOnSigint` scopes in that case. \* Returns: {any} the result of the very last statement executed in the script. This method is a shortcut to `(new vm.Script(code, options)).runInContext(vm.createContext(options), options)`. If `options` is a string, then it specifies the filename. It does several things at once: 1. Creates a new context. 2. If `contextObject` is an object, [contextifies][contextified] it with the new context. If `contextObject` is undefined, creates a new object and [contextifies][contextified] it. If `contextObject` is [`vm.constants.DONT\_CONTEXTIFY`][], don't [contextify][contextified] anything. 3. Compiles the code as a`vm.Script` 4. Runs the compield code within the created context. The code does not have access to the scope in which this method is called. 5. Returns the result. The following example compiles and executes code that increments a global variable and sets a new one. These globals are contained in the `contextObject`. ```js const vm = require('node:vm'); const contextObject = { animal: 'cat', count: 2, }; vm.runInNewContext('count += 1; name = "kitty"', contextObject); console.log(contextObject); // Prints: { animal: 'cat', count: 3, name: 'kitty' } // This would throw if the context is created from a contextified object. // vm.constants.DONT\_CONTEXTIFY allows creating contexts with ordinary global objects that // can be frozen. const frozenContext = vm.runInNewContext('Object.freeze(globalThis); globalThis;', vm.constants.DONT\_CONTEXTIFY); ``` ## `vm.runInThisContext(code[, options])` <!-- YAML added: v0.3.1 changes: - version: - v21.7.0 - v20.12.0 pr-url: https://github.com/nodejs/node/pull/51244 description: Added support for `vm.constants.USE\_MAIN\_CONTEXT\_DEFAULT\_LOADER`. - version: - v17.0.0 - v16.12.0 pr-url: https://github.com/nodejs/node/pull/40249 description: Added support for import attributes to the `importModuleDynamically` parameter. - version: v6.3.0 pr-url: https://github.com/nodejs/node/pull/6635 description: The `breakOnSigint` option is supported now. --> \* `code` {string} The JavaScript code to compile and run. \* `options` {Object|string} \* `filename` {string} Specifies the filename used in stack traces produced by this script. \*\*Default:\*\* `'evalmachine.<anonymous>'`. \* `lineOffset` {number} Specifies the line number offset that is displayed in stack traces produced by this script. \*\*Default:\*\* `0`. \* `columnOffset` {number} Specifies the first-line column number offset that is displayed in stack traces produced by this script. \*\*Default:\*\* `0`. \* `displayErrors` {boolean} When `true`, if an [`Error`][] occurs while compiling the `code`, the line of code causing the error is attached to the stack trace. \*\*Default:\*\* `true`. \* `timeout` {integer} Specifies the number of milliseconds to execute `code` before terminating execution. If execution is terminated, an [`Error`][] will be thrown. This value must be a strictly positive integer. \* `breakOnSigint` {boolean} If `true`, receiving `SIGINT` (<kbd>Ctrl</kbd>+<kbd>C</kbd>) will terminate execution and throw an [`Error`][]. Existing handlers for the event that have been attached via `process.on('SIGINT')` are disabled during script execution, but continue to work after that. \*\*Default:\*\* `false`. \* `cachedData` {Buffer|TypedArray|DataView} Provides an optional `Buffer` or `TypedArray`, or `DataView` with V8's code cache data for the supplied source. \* `importModuleDynamically` {Function|vm.constants.USE\\_MAIN\\_CONTEXT\\_DEFAULT\\_LOADER} Used to specify the how the modules should be loaded during the evaluation of this script when `import()` is called. This option is part of the experimental modules API. We do not recommend using it in a production environment. For detailed information, see [Support of dynamic `import()` in compilation APIs][]. \* Returns: {any} the result of the very last statement executed
|
https://github.com/nodejs/node/blob/main//doc/api/vm.md
|
main
|
nodejs
|
[
-0.10100885480642319,
-0.00043174982420168817,
-0.027903513982892036,
0.09998910129070282,
0.0480259470641613,
-0.028775546699762344,
-0.0385618731379509,
0.04211290180683136,
-0.0374809093773365,
-0.0633544847369194,
-0.000494369538500905,
0.03188115730881691,
-0.04115423560142517,
-0.006491489242762327,
-0.020594052970409393,
-0.02222624607384205,
0.06174652650952339,
-0.06471032649278641,
-0.030539853498339653,
-0.044360410422086716,
0.035020146518945694,
-0.03289363533258438,
-0.004473977256566286,
-0.008596032857894897,
0.018818417564034462,
0.03393300622701645,
-0.05355215445160866,
-0.08497995883226395,
0.053768519312143326,
0.0038953092880547047,
-0.04259170591831207,
-0.03065076470375061,
0.015076086856424809,
-0.0029840099159628153,
0.05358363315463066,
0.17242451012134552,
-0.04608110338449478,
-0.07479066401720047,
-0.066587895154953,
-0.032914694398641586,
0.06537306308746338,
-0.031009841710329056,
-0.07595133036375046,
-0.026712516322731972,
0.017067035660147667,
-0.033917076885700226,
0.0007313841488212347,
-0.05769268795847893,
-0.10729080438613892,
-0.012761034071445465,
-0.06080009415745735,
-0.008640723302960396,
-0.026507647708058357,
0.02625797502696514,
-0.012644719332456589,
0.056306350976228714,
0.038196370005607605,
0.0018295778427273035,
-0.0027570698875933886,
0.023800795897841454,
-0.06313250213861465,
-0.022544510662555695,
0.06588436663150787,
-0.003983468282967806,
0.026235608384013176,
-0.013491922058165073,
0.018274765461683273,
-0.046374186873435974,
0.0340285561978817,
-0.02461562305688858,
-0.06396715342998505,
0.0406046099960804,
-0.06224818527698517,
0.008513681590557098,
0.004974344279617071,
-0.023060547187924385,
-0.028291568160057068,
0.032022517174482346,
0.046574048697948456,
-0.0884518027305603,
-0.00755957281216979,
-0.08022292703390121,
-0.07156333327293396,
-0.00707729859277606,
0.010793947614729404,
0.06836151331663132,
0.03018924593925476,
-0.018124040216207504,
0.10920663177967072,
0.03776004537940025,
-0.02346714772284031,
-0.08195561170578003,
-0.06747998297214508,
0.07049497216939926,
0.044960737228393555,
0.02092272974550724,
-0.022356970235705376,
0.05249842628836632,
0.03034498356282711,
-0.037287648767232895,
-0.016741368919610977,
0.004962505307048559,
0.037292685359716415,
0.06841440498828888,
0.03541647642850876,
-0.013234702870249748,
0.0023591553326696157,
-0.011575107462704182,
-0.003010554937645793,
-0.03899264708161354,
0.08203805983066559,
0.06009874865412712,
0.08698105067014694,
-0.005219561513513327,
0.04449303448200226,
0.06182723119854927,
0.06294256448745728,
0.018944106996059418,
0.006804601289331913,
0.12382999807596207,
0.05622709542512894,
0.03119223564863205,
0.07240144163370132,
-0.06286553293466568,
0.026507142931222916,
0.02321486547589302,
-0.023505745455622673,
2.7490617820268808e-33,
-0.04861966148018837,
-0.10008677840232849,
-0.029670866206288338,
0.055115580558776855,
-0.03309188410639763,
-0.003291107015684247,
0.051109492778778076,
0.05507394298911095,
-0.03930548205971718,
-0.032683853060007095,
-0.07484107464551926,
0.05352257192134857,
-0.006092915777117014,
0.09391564130783081,
-0.009781495667994022,
0.009142933413386345,
0.05308595672249794,
-0.07093263417482376,
0.10818246006965637,
0.06726102530956268,
0.04057735577225685,
-0.05722304806113243,
-0.027419812977313995,
0.03043527901172638,
0.05235138162970543,
0.04348503425717354,
0.04687899351119995,
-0.012643042020499706,
-0.04226917400956154,
0.005460334941744804,
-0.05746425688266754,
-0.0074455104768276215,
-0.1039450466632843,
0.02245902083814144,
0.0060708289965987206,
0.01963987946510315,
-0.0651995912194252,
-0.015127045102417469,
-0.10001640021800995,
0.040189627557992935,
0.015307459980249405,
0.06632445752620697,
-0.0642109140753746,
-0.023226255550980568,
-0.0318133570253849,
-0.0574813187122345,
-0.0677984207868576,
0.05667790770530701,
0.08942090719938278,
-0.002617715625092387,
0.024383358657360077,
-0.007446947507560253,
0.0614653080701828,
-0.11915858834981918,
0.013995782472193241,
0.036909688264131546,
0.041595641523599625,
-0.03601212054491043,
0.04938342794775963,
0.0018576907459646463,
0.0009120555478148162,
-0.08140736073255539,
-0.0061800479888916016,
0.09637914597988129,
0.05278702825307846,
0.03769869729876518,
-0.06898954510688782,
0.0010207329178228974,
-0.02906176820397377,
0.04483424872159958,
0.039729706943035126,
0.008715080097317696,
-0.029648717492818832,
0.010963331907987595,
0.06432653963565826,
-0.006564783398061991,
-0.05929845944046974,
-0.04731007665395737,
-0.05009280517697334,
-0.03145012632012367,
0.1148756593465805,
0.005404227878898382,
-0.027034427970647812,
-0.04032942280173302,
-0.05988115817308426,
0.019108524546027184,
-0.04127030819654465,
-0.09134823828935623,
0.08671349287033081,
-0.0042891004122793674,
0.028439071029424667,
-0.0904095321893692,
-0.02242969162762165,
-0.0146411694586277,
-0.10914883762598038,
-4.279663425340981e-33,
0.1566014289855957,
0.013582906685769558,
-0.014119667001068592,
0.13001035153865814,
0.011928433552384377,
0.031247975304722786,
0.009564598090946674,
0.051004134118556976,
-0.018612077459692955,
0.0016399308806285262,
-0.07324714213609695,
-0.013792981393635273,
-0.011733843944966793,
-0.0012048878706991673,
0.032771579921245575,
0.08739139884710312,
-0.03987528756260872,
-0.06727021187543869,
0.046514466404914856,
-0.010458435863256454,
0.0004437111783772707,
0.007703977636992931,
0.015740646049380302,
0.03972873464226723,
-0.007790497038513422,
-0.026526160538196564,
-0.05032893270254135,
0.02278418466448784,
-0.08740952610969543,
-0.019597366452217102,
-0.03933015465736389,
0.023120036348700523,
-0.06541566550731659,
-0.018604518845677376,
0.02755899913609028,
0.03603893518447876,
0.04368717223405838,
0.04655585065484047,
0.04692409187555313,
-0.0023041353560984135,
0.12623231112957,
0.03063095547258854,
-0.06497983634471893,
0.040717560797929764,
-0.025455700233578682,
0.021018344908952713,
-0.0557837076485157,
-0.03579071909189224,
0.007464327849447727,
-0.02179240807890892,
-0.011256884783506393,
-0.02958698943257332,
-0.038365378975868225,
0.02604299783706665,
-0.026166271418333054,
-0.0007307583000510931,
0.04482872784137726,
-0.011622249148786068,
0.0037606237456202507,
0.0016260856064036489,
0.00586027093231678,
-0.05371791869401932,
0.016051705926656723,
-0.09628861397504807,
-0.06629787385463715,
0.04055749624967575,
-0.013090565800666809,
-0.028304537758231163,
0.05719424784183502,
-0.006935027427971363,
0.01523700449615717,
-0.09816797077655792,
0.013330161571502686,
-0.047030970454216,
-0.14919504523277283,
0.014196823351085186,
0.0035859609488397837,
-0.07766392081975937,
0.0476859025657177,
0.036806005984544754,
-0.015691889449954033,
-0.03730730339884758,
0.028139691799879074,
-0.011324591003358364,
-0.04599335044622421,
0.016598522663116455,
0.04190446436405182,
0.11578617990016937,
0.018116360530257225,
0.05535457655787468,
0.010688519105315208,
-0.024841105565428734,
-0.02398618310689926,
0.011991131119430065,
0.020577823743224144,
-6.143133646219212e-8,
0.04515867680311203,
0.014712898060679436,
-0.047836944460868835,
0.0660235583782196,
0.0633774921298027,
-0.023395253345370293,
0.006574701517820358,
0.07559071481227875,
0.05691254138946533,
0.058200910687446594,
0.021497972309589386,
-0.03048674948513508,
0.03789458051323891,
0.06652551889419556,
0.006080416962504387,
0.1262989342212677,
0.01932314969599247,
0.015339172445237637,
-0.029370052739977837,
-0.06868197023868561,
-0.0033810273744165897,
0.05633134767413139,
0.03528781235218048,
0.05077477917075157,
0.0030258053448051214,
-0.05214596167206764,
0.026962894946336746,
0.0604066401720047,
0.01701061613857746,
-0.05055815353989601,
-0.1101275309920311,
0.07600661367177963,
-0.022084005177021027,
-0.026077181100845337,
-0.09183252602815628,
0.018873654305934906,
0.057338181883096695,
-0.03733735904097557,
0.11222971975803375,
-0.0034651318565011024,
-0.04605614021420479,
0.008153004571795464,
-0.003845637198537588,
-0.04295419529080391,
-0.011879131197929382,
-0.017139194533228874,
-0.121346615254879,
0.028828853741288185,
-0.05700067803263664,
0.060404375195503235,
0.013218552805483341,
-0.009206006303429604,
-0.09097964316606522,
0.08849941194057465,
0.025643905624747276,
-0.032924313098192215,
0.038693878799676895,
-0.08846587687730789,
0.008937248028814793,
-0.05513953045010567,
-0.029455943033099174,
-0.02865448407828808,
0.037883855402469635,
-0.1179419681429863
] | 0.094023
|
the evaluation of this script when `import()` is called. This option is part of the experimental modules API. We do not recommend using it in a production environment. For detailed information, see [Support of dynamic `import()` in compilation APIs][]. \* Returns: {any} the result of the very last statement executed in the script. `vm.runInThisContext()` compiles `code`, runs it within the context of the current `global` and returns the result. Running code does not have access to local scope, but does have access to the current `global` object. If `options` is a string, then it specifies the filename. The following example illustrates using both `vm.runInThisContext()` and the JavaScript [`eval()`][] function to run the same code: <!-- eslint-disable prefer-const --> ```js const vm = require('node:vm'); let localVar = 'initial value'; const vmResult = vm.runInThisContext('localVar = "vm";'); console.log(`vmResult: '${vmResult}', localVar: '${localVar}'`); // Prints: vmResult: 'vm', localVar: 'initial value' const evalResult = eval('localVar = "eval";'); console.log(`evalResult: '${evalResult}', localVar: '${localVar}'`); // Prints: evalResult: 'eval', localVar: 'eval' ``` Because `vm.runInThisContext()` does not have access to the local scope, `localVar` is unchanged. In contrast, a direct `eval()` call \_does\_ have access to the local scope, so the value `localVar` is changed. In this way `vm.runInThisContext()` is much like an [indirect `eval()` call][], e.g. `(0,eval)('code')`. ## Example: Running an HTTP server within a VM When using either [`script.runInThisContext()`][] or [`vm.runInThisContext()`][], the code is executed within the current V8 global context. The code passed to this VM context will have its own isolated scope. In order to run a simple web server using the `node:http` module the code passed to the context must either call `require('node:http')` on its own, or have a reference to the `node:http` module passed to it. For instance: ```js 'use strict'; const vm = require('node:vm'); const code = ` ((require) => { const http = require('node:http'); http.createServer((request, response) => { response.writeHead(200, { 'Content-Type': 'text/plain' }); response.end('Hello World\\n'); }).listen(8124); console.log('Server running at http://127.0.0.1:8124/'); })`; vm.runInThisContext(code)(require); ``` The `require()` in the above case shares the state with the context it is passed from. This may introduce risks when untrusted code is executed, e.g. altering objects in the context in unwanted ways. ## What does it mean to "contextify" an object? All JavaScript executed within Node.js runs within the scope of a "context". According to the [V8 Embedder's Guide][]: > In V8, a context is an execution environment that allows separate, unrelated, > JavaScript applications to run in a single instance of V8. You must explicitly > specify the context in which you want any JavaScript code to be run. When the method `vm.createContext()` is called with an object, the `contextObject` argument will be used to wrap the global object of a new instance of a V8 Context (if `contextObject` is `undefined`, a new object will be created from the current context before its contextified). This V8 Context provides the `code` run using the `node:vm` module's methods with an isolated global environment within which it can operate. The process of creating the V8 Context and associating it with the `contextObject` in the outer context is what this document refers to as "contextifying" the object. The contextifying would introduce some quirks to the `globalThis` value in the context. For example, it cannot be frozen, and it is not reference equal to the `contextObject` in the outer context. ```js const vm = require('node:vm'); // An undefined `contextObject` option makes the global object contextified. const context = vm.createContext(); console.log(vm.runInContext('globalThis', context) === context); // false // A contextified global object cannot be frozen. try { vm.runInContext('Object.freeze(globalThis);', context); } catch (e) { console.log(e); // TypeError: Cannot freeze } console.log(vm.runInContext('globalThis.foo = 1; foo;', context));
|
https://github.com/nodejs/node/blob/main//doc/api/vm.md
|
main
|
nodejs
|
[
-0.07331940531730652,
0.06597357243299484,
-0.033810410648584366,
0.08151759207248688,
0.13120383024215698,
-0.03569146245718002,
0.0463358573615551,
0.08365561068058014,
-0.02905293181538582,
-0.05480445176362991,
0.0313907265663147,
0.031418632715940475,
-0.058258358389139175,
0.016669435426592827,
-0.008385139517486095,
-0.02820318378508091,
-0.013585210777819157,
-0.04223350062966347,
-0.013268191367387772,
0.005141558591276407,
0.043705835938453674,
0.0010908768745139241,
0.016411438584327698,
-0.06646683067083359,
0.027394773438572884,
0.017510028555989265,
-0.01939762942492962,
-0.021912481635808945,
0.050757817924022675,
-0.006213093176484108,
-0.029354704543948174,
0.05629975348711014,
-0.05452203005552292,
0.03482653573155403,
-0.04290086776018143,
0.11827877908945084,
-0.04754870384931564,
-0.10117059201002121,
-0.01068819034844637,
0.017766350880265236,
0.06477757543325424,
0.07226110994815826,
-0.08190878480672836,
-0.0484638549387455,
-0.003253846662119031,
-0.03607911244034767,
-0.037995416671037674,
-0.028450019657611847,
-0.1170881986618042,
0.009457911364734173,
-0.04116729646921158,
-0.0009878042619675398,
-0.02944827638566494,
-0.07150852680206299,
-0.012354258447885513,
0.043670155107975006,
0.03095819242298603,
0.00456983782351017,
0.017643148079514503,
0.06644792854785919,
-0.06072065979242325,
-0.00028994758031331003,
0.02617521770298481,
0.010451550595462322,
0.03695782274007797,
-0.01806284859776497,
-0.03462107107043266,
0.030841434374451637,
-0.010229796171188354,
-0.06561080366373062,
-0.09518741816282272,
0.07396508008241653,
-0.005119910929352045,
0.03189743310213089,
-0.010517135262489319,
-0.0531315878033638,
-0.0400671623647213,
0.050237517803907394,
0.048283517360687256,
-0.03193633630871773,
0.03785635903477669,
-0.0889519527554512,
-0.0451924093067646,
-0.0023965260479599237,
-0.0034726487938314676,
0.13028939068317413,
-0.018111038953065872,
-0.003480316139757633,
0.1089635044336319,
0.03650074079632759,
-0.06738694757223129,
-0.13896961510181427,
-0.07031621783971786,
0.07378993183374405,
0.06669454276561737,
0.02611064910888672,
-0.034686002880334854,
0.016723845154047012,
0.03237142786383629,
-0.02505478449165821,
-0.027418440207839012,
-0.01914059743285179,
0.015066059306263924,
-0.01885497383773327,
0.011347399093210697,
-0.022435413673520088,
0.07132190465927124,
-0.03699139878153801,
0.000534048187546432,
-0.06038818135857582,
0.011267381720244884,
0.06924676895141602,
0.0847979411482811,
-0.08688603341579437,
-0.03351030871272087,
0.050021350383758545,
0.06869395822286606,
-0.02312966249883175,
0.009773307479918003,
0.08135263621807098,
0.07641977071762085,
0.0088332649320364,
0.07164479047060013,
-0.050488024950027466,
-0.01793491840362549,
-0.05846846103668213,
0.06142859533429146,
2.3720862538479427e-33,
-0.059061743319034576,
-0.12513290345668793,
-0.00045756131294183433,
0.06589851528406143,
0.0007357890135608613,
-0.024612415581941605,
0.0554141066968441,
0.03863025829195976,
-0.13722939789295197,
0.006157638970762491,
-0.06191388890147209,
0.0678185373544693,
0.015407831408083439,
0.08482008427381516,
0.026476634666323662,
0.0921473577618599,
0.022737901657819748,
0.024872465059161186,
0.07008657604455948,
0.03804580122232437,
0.05302923172712326,
0.0035205092281103134,
0.014487771317362785,
0.028758827596902847,
0.037226125597953796,
0.01978534273803234,
0.009318417869508266,
-0.020332232117652893,
-0.011354496702551842,
-0.009437499567866325,
0.0020337472669780254,
-0.01489026378840208,
-0.014289992861449718,
0.08749325573444366,
0.0533670037984848,
0.033663444221019745,
-0.07722146809101105,
-0.014933560974895954,
-0.1157367080450058,
0.04628337174654007,
0.06644175201654434,
0.007071255706250668,
-0.01990552991628647,
0.04265537112951279,
-0.05977201834321022,
-0.02552778646349907,
-0.08851996809244156,
0.058415234088897705,
0.021209320053458214,
-0.011876959353685379,
-0.06842705607414246,
0.10102582722902298,
0.06589573621749878,
-0.0853990837931633,
0.0721375048160553,
0.07051090896129608,
-0.00021820447000209242,
-0.0343531109392643,
-0.02635432593524456,
-0.002648148685693741,
0.03909968212246895,
0.0089919688180089,
-0.06839290261268616,
0.09716060012578964,
-0.013263016939163208,
0.011111312545835972,
-0.037845395505428314,
-0.08680006861686707,
0.014550692401826382,
0.00897790864109993,
-0.0036952330265194178,
0.010356406681239605,
-0.06622952967882156,
-0.03866312652826309,
0.09877564758062363,
-0.02272392436861992,
-0.04449828714132309,
0.04355720803141594,
0.0440494678914547,
-0.05873918533325195,
0.02355981059372425,
-0.04488152638077736,
-0.04217606410384178,
-0.0279921293258667,
0.02622700110077858,
0.055701687932014465,
-0.07789115607738495,
-0.07500406354665756,
0.11407970637083054,
-0.04562791436910629,
0.06422170996665955,
-0.07190553843975067,
-0.08946596831083298,
-0.08031637966632843,
-0.011499583721160889,
-4.707705366855516e-33,
0.13453322649002075,
0.0332283154129982,
-0.01638844422996044,
0.06465055793523788,
-0.027245113626122475,
0.010730375535786152,
0.021892467513680458,
0.04973501339554787,
0.026974696666002274,
0.027224788442254066,
-0.06234193593263626,
0.07239719480276108,
0.007884117774665356,
-0.01390011701732874,
0.04731939360499382,
0.09319125860929489,
-0.12607917189598083,
-0.08848749101161957,
0.03213106840848923,
-0.06429672986268997,
-0.009290964342653751,
-0.005661319009959698,
0.0737452283501625,
0.013780809938907623,
-0.020508067682385445,
-0.007426467724144459,
0.0141440499573946,
0.01929072104394436,
-0.09787934273481369,
0.01353259477764368,
-0.08098325878381729,
0.025675440207123756,
-0.09074072539806366,
0.04679707810282707,
-0.018850846216082573,
-0.016945861279964447,
0.08223732560873032,
0.019758189097046852,
0.05943959206342697,
0.010573714971542358,
-0.015304011292755604,
0.022016700357198715,
-0.04387468844652176,
-0.00867854617536068,
-0.06318643689155579,
0.03020881488919258,
-0.04125216603279114,
0.0616004578769207,
0.03719218075275421,
-0.07564473152160645,
-0.024922121316194534,
-0.010962573811411858,
-0.023169292137026787,
0.010519045405089855,
0.003932584542781115,
-0.034141357988119125,
0.001954923616722226,
-0.03095860965549946,
-0.028382040560245514,
0.05556705594062805,
0.07836557179689407,
-0.030187571421265602,
-0.029083840548992157,
-0.02731850929558277,
-0.09038833528757095,
-0.006703292950987816,
-0.041073933243751526,
-0.013438668102025986,
0.07284340262413025,
-0.0572466216981411,
0.023791955783963203,
-0.0687725767493248,
-0.04550279676914215,
-0.03122071549296379,
-0.08380503207445145,
0.061212290078401566,
0.02755853347480297,
-0.1014709547162056,
0.01934119127690792,
0.05319405347108841,
0.044609829783439636,
0.0033412922639399767,
-0.027574855834245682,
-0.019708476960659027,
0.01121960673481226,
-0.0038377917371690273,
-0.04382758587598801,
0.09632010012865067,
0.017690526321530342,
0.022374751046299934,
0.019473230466246605,
-0.0040033296681940556,
-0.08637095242738724,
-0.029290542006492615,
-0.020585840567946434,
-5.682569792497816e-8,
-0.09389820694923401,
0.01373420562595129,
-0.07097077369689941,
-0.028918376192450523,
-0.04204342141747475,
0.03149578720331192,
0.03162086382508278,
0.027082614600658417,
0.056243911385536194,
0.05866178497672081,
0.02888028509914875,
-0.006428522989153862,
0.05885877087712288,
0.023068329319357872,
-0.03865402936935425,
0.0436735562980175,
0.03508923202753067,
0.08726336061954498,
-0.028960173949599266,
0.055000633001327515,
0.048771556466817856,
0.03987297788262367,
0.07538696378469467,
0.03745541349053383,
0.014545770362019539,
-0.021751655265688896,
-0.00014671921962872148,
0.04461122676730156,
-0.03413897007703781,
-0.037785887718200684,
-0.03336586058139801,
0.0807531327009201,
-0.020672649145126343,
0.027981167659163475,
-0.11034690588712692,
0.048630595207214355,
0.018646856769919395,
-0.045891743153333664,
0.04560770094394684,
-0.006672564893960953,
-0.023458663374185562,
-0.01964116096496582,
-0.03115413896739483,
-0.005605102051049471,
-0.04374603554606438,
-0.016825690865516663,
-0.022022133693099022,
-0.019870879128575325,
0.0065152873285114765,
0.0009037894778884947,
-0.002873373683542013,
-0.011562350206077099,
-0.07593072205781937,
0.060875922441482544,
0.045851707458496094,
-0.013850703835487366,
0.004343830514699221,
-0.05449177324771881,
-0.018752364441752434,
-0.02074251137673855,
-0.04485474154353142,
-0.03358437493443489,
0.06469106674194336,
-0.05597206577658653
] | 0.113501
|
vm = require('node:vm'); // An undefined `contextObject` option makes the global object contextified. const context = vm.createContext(); console.log(vm.runInContext('globalThis', context) === context); // false // A contextified global object cannot be frozen. try { vm.runInContext('Object.freeze(globalThis);', context); } catch (e) { console.log(e); // TypeError: Cannot freeze } console.log(vm.runInContext('globalThis.foo = 1; foo;', context)); // 1 ``` To create a context with an ordinary global object and get access to a global proxy in the outer context with fewer quirks, specify `vm.constants.DONT\_CONTEXTIFY` as the `contextObject` argument. ### `vm.constants.DONT\_CONTEXTIFY` This constant, when used as the `contextObject` argument in vm APIs, instructs Node.js to create a context without wrapping its global object with another object in a Node.js-specific manner. As a result, the `globalThis` value inside the new context would behave more closely to an ordinary one. ```js const vm = require('node:vm'); // Use vm.constants.DONT\_CONTEXTIFY to freeze the global object. const context = vm.createContext(vm.constants.DONT\_CONTEXTIFY); vm.runInContext('Object.freeze(globalThis);', context); try { vm.runInContext('bar = 1; bar;', context); } catch (e) { console.log(e); // Uncaught ReferenceError: bar is not defined } ``` When `vm.constants.DONT\_CONTEXTIFY` is used as the `contextObject` argument to [`vm.createContext()`][], the returned object is a proxy-like object to the global object in the newly created context with fewer Node.js-specific quirks. It is reference equal to the `globalThis` value in the new context, can be modified from outside the context, and can be used to access built-ins in the new context directly. ```js const vm = require('node:vm'); const context = vm.createContext(vm.constants.DONT\_CONTEXTIFY); // Returned object is reference equal to globalThis in the new context. console.log(vm.runInContext('globalThis', context) === context); // true // Can be used to access globals in the new context directly. console.log(context.Array); // [Function: Array] vm.runInContext('foo = 1;', context); console.log(context.foo); // 1 context.bar = 1; console.log(vm.runInContext('bar;', context)); // 1 // Can be frozen and it affects the inner context. Object.freeze(context); try { vm.runInContext('baz = 1; baz;', context); } catch (e) { console.log(e); // Uncaught ReferenceError: baz is not defined } ``` ## Timeout interactions with asynchronous tasks and Promises `Promise`s and `async function`s can schedule tasks run by the JavaScript engine asynchronously. By default, these tasks are run after all JavaScript functions on the current stack are done executing. This allows escaping the functionality of the `timeout` and `breakOnSigint` options. For example, the following code executed by `vm.runInNewContext()` with a timeout of 5 milliseconds schedules an infinite loop to run after a promise resolves. The scheduled loop is never interrupted by the timeout: ```js const vm = require('node:vm'); function loop() { console.log('entering loop'); while (1) console.log(Date.now()); } vm.runInNewContext( 'Promise.resolve().then(() => loop());', { loop, console }, { timeout: 5 }, ); // This is printed \*before\* 'entering loop' (!) console.log('done executing'); ``` This can be addressed by passing `microtaskMode: 'afterEvaluate'` to the code that creates the `Context`: ```js const vm = require('node:vm'); function loop() { while (1) console.log(Date.now()); } vm.runInNewContext( 'Promise.resolve().then(() => loop());', { loop, console }, { timeout: 5, microtaskMode: 'afterEvaluate' }, ); ``` In this case, the microtask scheduled through `promise.then()` will be run before returning from `vm.runInNewContext()`, and will be interrupted by the `timeout` functionality. This applies only to code running in a `vm.Context`, so e.g. [`vm.runInThisContext()`][] does not take this option. Promise callbacks are entered into the microtask queue of the context in which they were created. For example, if `() => loop()` is replaced with just `loop` in the above example, then `loop` will be pushed into the global microtask queue, because it is a function from the outer (main) context, and thus will also be able to escape the timeout. If asynchronous scheduling functions such as `process.nextTick()`, `queueMicrotask()`, `setTimeout()`, `setImmediate()`, etc. are made available inside
|
https://github.com/nodejs/node/blob/main//doc/api/vm.md
|
main
|
nodejs
|
[
-0.03518351539969444,
0.009674863889813423,
-0.015658149495720863,
0.06492874771356583,
0.0590466633439064,
-0.018089570105075836,
0.037164390087127686,
0.022771652787923813,
-0.035626281052827835,
-0.018219009041786194,
-0.04091286286711693,
-0.04769834131002426,
-0.024513958021998405,
0.005905155558139086,
0.06851113587617874,
0.02561083808541298,
0.08270006626844406,
0.051533035933971405,
-0.03475278615951538,
0.04908405616879463,
0.02865307219326496,
0.0015029015485197306,
0.011372583918273449,
-0.044114869087934494,
-0.04436889663338661,
-0.028175020590424538,
-0.0735774040222168,
-0.019454391673207283,
0.13838572800159454,
0.048029787838459015,
-0.01484287716448307,
0.06468009948730469,
-0.13963103294372559,
0.030323529615998268,
-0.029198678210377693,
0.11675871908664703,
-0.06866318732500076,
-0.07841897755861282,
-0.013328143395483494,
0.003662737086415291,
0.09633411467075348,
0.11129651963710785,
-0.11527430266141891,
-0.06123456731438637,
0.03671836480498314,
0.0022670163307338953,
0.01276748813688755,
0.07473084330558777,
-0.02836230769753456,
-0.02374710887670517,
-0.031257860362529755,
-0.03835839033126831,
-0.019596228376030922,
0.002955607371404767,
-0.00754945632070303,
0.02580886147916317,
0.08406437933444977,
0.028626227751374245,
0.006339225918054581,
0.023801209405064583,
-0.06930473446846008,
0.00504681933671236,
0.05228530243039131,
-0.0017392176669090986,
0.023713817819952965,
0.015368040651082993,
-0.021357007324695587,
0.05949898809194565,
0.03614146634936333,
0.013535614125430584,
-0.06403211504220963,
0.02153347246348858,
0.0272336658090353,
0.0646248459815979,
-0.03653883561491966,
-0.006222992204129696,
-0.0339343287050724,
-0.023681072518229485,
0.058588556945323944,
0.017683696001768112,
0.07353325188159943,
0.012164522893726826,
-0.045418936759233475,
-0.015872685238718987,
0.01218966394662857,
0.07178254425525665,
0.04811958596110344,
-0.05185869336128235,
0.04141975939273834,
0.05475175753235817,
-0.035150494426488876,
-0.08899453282356262,
0.021068567410111427,
0.0147346006706357,
0.06517913937568665,
-0.06560251861810684,
0.023110466077923775,
-0.03512952849268913,
0.0006022542947903275,
0.023396827280521393,
-0.01754133030772209,
-0.06181209161877632,
0.06433433294296265,
0.04553484171628952,
0.044557150453329086,
0.03190705180168152,
-0.03342919796705246,
-0.005847406107932329,
-0.027205567806959152,
0.026027129963040352,
-0.06721638888120651,
0.10678795725107193,
-0.019091233611106873,
-0.060503967106342316,
-0.0549643449485302,
-0.018379533663392067,
0.08924470096826553,
-0.09293181449174881,
0.07598590850830078,
0.08930797874927521,
0.05614086240530014,
-0.041632961481809616,
0.04087265580892563,
-0.008705178275704384,
-0.05791087821125984,
-0.04413550719618797,
0.020470764487981796,
2.7952318940493185e-33,
0.027592109516263008,
-0.1227867379784584,
0.034079018980264664,
0.12169516831636429,
0.08601208031177521,
0.07854847609996796,
0.02988279052078724,
0.06292185187339783,
-0.05288480594754219,
0.014101335778832436,
0.010596776381134987,
0.05169321224093437,
0.009836769662797451,
0.02318548783659935,
0.07605787366628647,
-0.00025971702416427433,
0.04981613531708717,
0.006927299778908491,
0.05724595859646797,
0.013690873049199581,
-0.02599923126399517,
-0.09031321853399277,
-0.018655547872185707,
-0.0416201688349247,
0.005302343517541885,
0.008844486437737942,
-0.0045846072025597095,
-0.02036728337407112,
-0.02366706356406212,
0.0058496324345469475,
-0.0271163247525692,
0.011796606704592705,
-0.016028055921196938,
0.08314171433448792,
-0.02107776142656803,
-0.0026121092960238457,
-0.0097119165584445,
0.01587527245283127,
-0.13519273698329926,
-0.1000540554523468,
-0.009286127984523773,
0.043162040412425995,
0.04200301319360733,
-0.03054497390985489,
-0.05991452932357788,
-0.12476656585931778,
-0.05053013563156128,
0.045851126313209534,
0.04127158969640732,
0.014218409545719624,
0.011851598508656025,
0.058423660695552826,
-0.004537890199571848,
-0.07588391751050949,
0.07543078809976578,
0.028638331219553947,
0.022141238674521446,
-0.0036663184873759747,
-0.030377864837646484,
-0.04332783445715904,
0.004497446119785309,
-0.05988321825861931,
-0.03171911835670471,
0.11273888498544693,
0.023247642442584038,
0.05123209208250046,
-0.11072631180286407,
-0.062334094196558,
-0.007674978114664555,
-0.039403632283210754,
-0.01316953357309103,
0.03555556386709213,
-0.05212343856692314,
-0.011253749020397663,
-0.01081849168986082,
-0.016047894954681396,
-0.04669474437832832,
-0.001138455467298627,
-0.0781017318367958,
-0.038490548729896545,
0.05303822085261345,
0.013595547527074814,
-0.009248259477317333,
0.031144125387072563,
-0.04252585396170616,
0.05131188780069351,
0.01552142109721899,
-0.01708887331187725,
0.04600793868303299,
-0.040240831673145294,
-0.011911749839782715,
-0.07543129473924637,
0.007449611090123653,
-0.09090171009302139,
-0.10296395421028137,
-4.756234181761276e-33,
0.031774722039699554,
-0.0037060517352074385,
-0.04958125203847885,
0.028269212692975998,
0.07034985721111298,
-0.030842086300253868,
-0.04543942213058472,
0.027553757652640343,
-0.12184081226587296,
-0.006103722844272852,
-0.03465982899069786,
0.08044759929180145,
0.07993839681148529,
0.08771029859781265,
0.035538144409656525,
0.05728046968579292,
-0.06426148116588593,
-0.06398352980613708,
0.018297908827662468,
-0.007353209424763918,
0.05427613481879234,
-0.04925775155425072,
0.015207746997475624,
-0.02645721100270748,
-0.05757299065589905,
-0.00649472139775753,
-0.10697213560342789,
-0.0031105063389986753,
-0.03530202805995941,
0.07187004387378693,
-0.06469671428203583,
0.0746142640709877,
-0.053439658135175705,
0.014762429520487785,
0.006245770957320929,
-0.054287467151880264,
-0.009607862681150436,
0.053807321935892105,
-0.006685113068670034,
-0.10552952438592911,
0.07193121314048767,
0.0135934604331851,
-0.025544779375195503,
-0.03019009530544281,
0.015575071796774864,
-0.01636074297130108,
-0.0406084768474102,
-0.00810336321592331,
0.03528166189789772,
0.008612140081822872,
-0.07841934263706207,
-0.034699659794569016,
-0.029153527691960335,
0.009994354099035263,
-0.05496468394994736,
-0.043361276388168335,
-0.027238981798291206,
0.011952605098485947,
0.03582809120416641,
-0.051897261291742325,
0.09196482598781586,
-0.06140494346618652,
-0.07332062721252441,
0.020125405862927437,
0.016199354082345963,
-0.016894925385713577,
-0.06138382479548454,
-0.036730341613292694,
0.04098844528198242,
-0.03600583225488663,
-0.023156730458140373,
0.048160675913095474,
-0.08411089330911636,
-0.026680156588554382,
-0.052916549146175385,
0.049365583807229996,
0.03085162118077278,
-0.12129057198762894,
0.04310494661331177,
0.051277048885822296,
0.03891298174858093,
-0.005581095814704895,
-0.030765272676944733,
0.017044128850102425,
0.015987297520041466,
-0.03423609957098961,
-0.03391672670841217,
0.07796256244182587,
-0.007837845012545586,
0.01956827938556671,
-0.015852538868784904,
-0.026580892503261566,
-0.15777114033699036,
-0.0064726416021585464,
-0.011256112717092037,
-5.4704113239267826e-8,
-0.06899423152208328,
0.09644763171672821,
-0.060220539569854736,
0.017707936465740204,
-0.050886958837509155,
0.012488802894949913,
0.033957067877054214,
-0.025570698082447052,
0.03470040112733841,
0.09888870269060135,
-0.0320282056927681,
0.005204289220273495,
0.055839136242866516,
0.0029705807100981474,
-0.031170718371868134,
0.020933441817760468,
-0.060879673808813095,
0.005799871403723955,
-0.005889250431209803,
0.022213580086827278,
0.019236885011196136,
0.04456556960940361,
0.005928024183958769,
0.03999213129281998,
-0.001088963937945664,
-0.0438222661614418,
0.04353233799338341,
0.045462410897016525,
0.04574134573340416,
-0.03603319823741913,
-0.09504371136426926,
0.07717698812484741,
-0.00901030469685793,
0.021266210824251175,
-0.15717385709285736,
0.07528391480445862,
-0.0784483253955841,
0.027070991694927216,
0.02473660372197628,
-0.010293260216712952,
0.08437851071357727,
0.013487226329743862,
-0.008817322552204132,
0.01347045786678791,
-0.00872963760048151,
0.06339733302593231,
0.026098841801285744,
0.07254531979560852,
0.03473447263240814,
0.0852506160736084,
-0.007959387265145779,
0.04000100493431091,
-0.10003357380628586,
0.05944456532597542,
-0.021530913189053535,
-0.034762997180223465,
0.002869226271286607,
0.012656653299927711,
0.007976376451551914,
0.005275038070976734,
-0.06370934098958969,
0.0060962168499827385,
-0.03762802854180336,
0.00953358318656683
] | 0.075791
|
`loop` in the above example, then `loop` will be pushed into the global microtask queue, because it is a function from the outer (main) context, and thus will also be able to escape the timeout. If asynchronous scheduling functions such as `process.nextTick()`, `queueMicrotask()`, `setTimeout()`, `setImmediate()`, etc. are made available inside a `vm.Context`, functions passed to them will be added to global queues, which are shared by all contexts. Therefore, callbacks passed to those functions are not controllable through the timeout either. ### When `microtaskMode` is `'afterEvaluate'`, beware sharing Promises between Contexts In `'afterEvaluate'` mode, the `Context` has its own microtask queue, separate from the global microtask queue used by the outer (main) context. While this mode is necessary to enforce `timeout` and enable `breakOnSigint` with asynchronous tasks, it also makes sharing promises between contexts challenging. In the example below, a promise is created in the inner context and shared with the outer context. When the outer context `await` on the promise, the execution flow of the outer context is disrupted in a surprising way: the log statement is never executed. ```mjs import \* as vm from 'node:vm'; const inner\_context = vm.createContext({}, { microtaskMode: 'afterEvaluate' }); // runInContext() returns a Promise created in the inner context. const inner\_promise = vm.runInContext( 'Promise.resolve()', context, ); // As part of performing `await`, the JavaScript runtime must enqueue a task // on the microtask queue of the context where `inner\_promise` was created. // A task is added on the inner microtask queue, but \*\*it will not be run // automatically\*\*: this task will remain pending indefinitely. // // Since the outer microtask queue is empty, execution in the outer module // falls through, and the log statement below is never executed. await inner\_promise; console.log('this will NOT be printed'); ``` To successfully share promises between contexts with different microtask queues, it is necessary to ensure that tasks on the inner microtask queue will be run \*\*whenever\*\* the outer context enqueues a task on the inner microtask queue. The tasks on the microtask queue of a given context are run whenever `runInContext()` or `SourceTextModule.evaluate()` are invoked on a script or module using this context. In our example, the normal execution flow can be restored by scheduling a second call to `runInContext()` \_before\_ `await inner\_promise`. ```mjs // Schedule `runInContext()` to manually drain the inner context microtask // queue; it will run after the `await` statement below. setImmediate(() => { vm.runInContext('', context); }); await inner\_promise; console.log('OK'); ``` \*\*Note:\*\* Strictly speaking, in this mode, `node:vm` departs from the letter of the ECMAScript specification for [enqueing jobs][], by allowing asynchronous tasks from different contexts to run in a different order than they were enqueued. ## Support of dynamic `import()` in compilation APIs The following APIs support an `importModuleDynamically` option to enable dynamic `import()` in code compiled by the vm module. \* `new vm.Script` \* `vm.compileFunction()` \* `new vm.SourceTextModule` \* `vm.runInThisContext()` \* `vm.runInContext()` \* `vm.runInNewContext()` \* `vm.createContext()` This option is still part of the experimental modules API. We do not recommend using it in a production environment. ### When the `importModuleDynamically` option is not specified or undefined If this option is not specified, or if it's `undefined`, code containing `import()` can still be compiled by the vm APIs, but when the compiled code is executed and it actually calls `import()`, the result will reject with [`ERR\_VM\_DYNAMIC\_IMPORT\_CALLBACK\_MISSING`][]. ### When `importModuleDynamically` is `vm.constants.USE\_MAIN\_CONTEXT\_DEFAULT\_LOADER` This option is currently not supported for `vm.SourceTextModule`. With this option, when an `import()` is initiated in the compiled code, Node.js would use the default ESM loader from the main context to load the requested module and return it to the
|
https://github.com/nodejs/node/blob/main//doc/api/vm.md
|
main
|
nodejs
|
[
-0.07683014869689941,
0.03788295388221741,
-0.0613228976726532,
0.05741261690855026,
0.005292722024023533,
-0.022125212475657463,
0.03162660822272301,
-0.01143653690814972,
0.05155325308442116,
-0.04738638177514076,
0.031173940747976303,
0.021462827920913696,
-0.027955152094364166,
-0.04701656475663185,
0.0008688883972354233,
-0.023235779255628586,
0.002995232818648219,
-0.023251568898558617,
-0.05534844100475311,
-0.05950436368584633,
0.11712121218442917,
0.011817025020718575,
0.010509977117180824,
-0.016335610300302505,
-0.07366761565208435,
0.005120915826410055,
-0.11719062924385071,
-0.039379965513944626,
0.09806661307811737,
0.03685454651713371,
0.027712946757674217,
-0.020688770338892937,
-0.0371532179415226,
-0.011835944838821888,
0.016414383426308632,
0.13457393646240234,
-0.029362119734287262,
-0.01295405998826027,
-0.09073978662490845,
0.011294166557490826,
0.07089556008577347,
-0.011281410232186317,
-0.0669441819190979,
-0.07903789728879929,
0.03190236538648605,
-0.0006028369534760714,
-0.022613871842622757,
-0.05074751749634743,
-0.10571126639842987,
0.08019378036260605,
-0.0620759055018425,
0.006890005432069302,
-0.04247886687517166,
0.02319672517478466,
0.057382114231586456,
0.06320678442716599,
0.02644306607544422,
0.04517906531691551,
0.0036636032164096832,
-0.038902733474969864,
-0.028444021940231323,
-0.08742114901542664,
-0.030746059492230415,
0.05223426967859268,
0.05003121867775917,
-0.009987031109631062,
0.013388894498348236,
-0.05019093304872513,
0.05066963657736778,
0.03409350663423538,
0.031075090169906616,
-0.012685402296483517,
-0.05569751188158989,
-0.0010944968089461327,
0.02722284011542797,
0.07538988441228867,
0.008772237226366997,
-0.021708045154809952,
-0.028360936790704727,
-0.08292385190725327,
0.04687576740980148,
-0.007214412558823824,
-0.029588408768177032,
-0.05033404007554054,
-0.004492130130529404,
-0.03095974773168564,
0.04362117871642113,
-0.005493149161338806,
0.089919313788414,
-0.009489047341048717,
-0.052809253334999084,
-0.033488787710666656,
-0.0710282251238823,
0.013850332237780094,
0.03011443093419075,
-0.044140465557575226,
-0.006573720835149288,
-0.01908743754029274,
-0.03337862342596054,
-0.025146717205643654,
-0.013450801372528076,
-0.011306685395538807,
0.008549781516194344,
0.011449606157839298,
0.05957954749464989,
-0.004445236176252365,
-0.006553065963089466,
-0.03234461322426796,
-0.03159170597791672,
-0.02960268035531044,
0.006764337420463562,
0.10677386075258255,
0.081345334649086,
0.036100856959819794,
0.026799215003848076,
0.08401944488286972,
0.07601238042116165,
0.0027370047755539417,
0.10885236412286758,
0.046700578182935715,
0.0640488713979721,
0.04780741035938263,
0.003617494599893689,
-0.11049477010965347,
-0.02476758323609829,
-0.023745309561491013,
0.045396532863378525,
1.754525786635061e-33,
-0.02316226065158844,
-0.14611227810382843,
0.003708615666255355,
-0.0454106479883194,
0.07718044519424438,
0.02711877040565014,
0.03448524326086044,
-0.030357740819454193,
-0.023972058668732643,
-0.03193838149309158,
0.024478817358613014,
-0.025305943563580513,
-0.009054334834218025,
0.04479755461215973,
-0.0004908404080197215,
-0.01887606456875801,
0.1285598874092102,
-0.08347389101982117,
0.07276929169893265,
0.0708896741271019,
0.035133618861436844,
-0.07648076117038727,
-0.05616823583841324,
0.026414601132273674,
-0.007027024403214455,
0.042149052023887634,
0.02531585842370987,
0.03429768607020378,
-0.014278477057814598,
0.03308100998401642,
-0.06459809839725494,
0.049798961728811264,
-0.12309882044792175,
-0.009908485226333141,
0.022244639694690704,
0.04748191684484482,
-0.036883898079395294,
-0.02211935631930828,
-0.042076535522937775,
-0.01761668547987938,
-0.02891620621085167,
0.021961910650134087,
-0.07670094072818756,
0.03142610192298889,
-0.05823686718940735,
-0.10009119659662247,
-0.03156751021742821,
0.03344586119055748,
0.01929210126399994,
0.04751395061612129,
0.0028792819939553738,
0.018022559583187103,
0.06490353494882584,
-0.08463965356349945,
0.02879563346505165,
0.01982874423265457,
0.024869192391633987,
0.03243698179721832,
-0.05695398151874542,
0.07471232116222382,
0.009754098951816559,
-0.0620596781373024,
-0.020626889541745186,
0.05958937481045723,
-0.016584567725658417,
0.04095829278230667,
-0.08166788518428802,
-0.01054757833480835,
0.0160512812435627,
0.031066633760929108,
-0.01849241927266121,
0.07990513741970062,
-0.028301671147346497,
0.10228034108877182,
-0.0008794227032922208,
0.020059799775481224,
-0.07698868960142136,
-0.07110866904258728,
-0.06395784765481949,
-0.05319702625274658,
0.09033973515033722,
-0.01196795329451561,
-0.07200814038515091,
-0.018113650381565094,
-0.03736194968223572,
-0.001088106189854443,
0.023355552926659584,
-0.08524341881275177,
0.0017894806805998087,
0.003156831255182624,
-0.08217734843492508,
-0.03490464389324188,
0.11450602859258652,
-0.014369681477546692,
-0.1284031718969345,
-4.563570657661503e-33,
0.07411769032478333,
-0.022495567798614502,
-0.05568977817893028,
0.07803913950920105,
0.013759762980043888,
0.04502405226230621,
-0.008146488107740879,
0.0017850107979029417,
-0.08910644799470901,
-0.017143836244940758,
-0.09113423526287079,
0.00929902121424675,
0.01307766791433096,
-0.004248540382832289,
0.006391061469912529,
0.04913925379514694,
0.0537058562040329,
-0.0699567124247551,
0.05996901914477348,
-0.013253886252641678,
0.005881655961275101,
0.006165037397295237,
0.0123851727694273,
0.07619946449995041,
-0.09091290831565857,
0.007342695724219084,
-0.023918453603982925,
-0.008437875658273697,
0.00021571195975411683,
-0.04154817387461662,
-0.053344953805208206,
-0.04681851342320442,
-0.017106899991631508,
0.06420180946588516,
0.07654115557670593,
-0.011091463267803192,
-0.000052117826271569356,
0.0016100653447210789,
-0.021385908126831055,
-0.031080063432455063,
0.14719608426094055,
0.021834567189216614,
-0.023953057825565338,
0.006796084810048342,
0.0003550390247255564,
0.056507982313632965,
-0.027381066232919693,
-0.05575951561331749,
-0.0826328843832016,
-0.022239182144403458,
-0.0581463985145092,
-0.06339331716299057,
0.012228291481733322,
0.10555331408977509,
-0.06070186570286751,
-0.023569919168949127,
0.06335558742284775,
-0.02812998555600643,
0.03144446387887001,
0.006702689453959465,
0.005912124644964933,
-0.07364203035831451,
0.07337351888418198,
-0.041874293237924576,
0.06710044294595718,
0.025372792035341263,
0.0256993155926466,
-0.07147783786058426,
0.0885918140411377,
0.012853692285716534,
0.04727647826075554,
-0.03466184437274933,
-0.017088208347558975,
-0.04418574646115303,
-0.08169006556272507,
0.10193537175655365,
-0.04854830354452133,
-0.17434631288051605,
0.0216398723423481,
-0.03681536018848419,
-0.002584951464086771,
-0.016822725534439087,
0.035501692444086075,
0.07495790719985962,
-0.03756053000688553,
0.043164461851119995,
0.021156806498765945,
0.08841177821159363,
-0.004240082576870918,
0.010748944245278835,
0.020149601623415947,
-0.013780507259070873,
-0.058137692511081696,
0.04882502183318138,
-0.007520115934312344,
-5.162246097256684e-8,
0.0427381694316864,
0.028943801298737526,
-0.051869429647922516,
0.04272861406207085,
-0.009453866630792618,
-0.07911733537912369,
0.04692569002509117,
-0.0038301798049360514,
0.03178686276078224,
0.026796234771609306,
0.03639448434114456,
-0.08784477412700653,
0.12734661996364594,
0.027061795815825462,
0.025084320455789566,
0.05975961312651634,
0.029130008071660995,
0.029714440926909447,
0.011820304207503796,
-0.003322814591228962,
-0.0322641022503376,
0.001928090350702405,
-0.04407895728945732,
-0.009767772629857063,
-0.02880275808274746,
-0.00016868230886757374,
0.047637879848480225,
0.10551010817289352,
0.008398040197789669,
-0.04490824043750763,
-0.04637114703655243,
0.031109724193811417,
-0.0367623046040535,
0.0937115028500557,
-0.11869445443153381,
-0.0443311482667923,
0.019386395812034607,
-0.03513840585947037,
0.12059599906206131,
-0.002746131271123886,
-0.006211687345057726,
-0.032303519546985626,
-0.028384320437908173,
0.01709381863474846,
-0.011682926677167416,
0.0021388342138379812,
-0.018791692331433296,
0.025471510365605354,
-0.055116765201091766,
0.056419555097818375,
-0.05992935225367546,
-0.007500510662794113,
-0.0207640640437603,
0.0405251607298851,
0.0463746041059494,
-0.042895495891571045,
0.062215663492679596,
-0.034856077283620834,
0.05318594351410866,
0.02594546042382717,
-0.04339338839054108,
-0.010396557860076427,
-0.03275274485349655,
-0.0036583063192665577
] | 0.085756
|
will reject with [`ERR\_VM\_DYNAMIC\_IMPORT\_CALLBACK\_MISSING`][]. ### When `importModuleDynamically` is `vm.constants.USE\_MAIN\_CONTEXT\_DEFAULT\_LOADER` This option is currently not supported for `vm.SourceTextModule`. With this option, when an `import()` is initiated in the compiled code, Node.js would use the default ESM loader from the main context to load the requested module and return it to the code being executed. This gives access to Node.js built-in modules such as `fs` or `http` to the code being compiled. If the code is executed in a different context, be aware that the objects created by modules loaded from the main context are still from the main context and not `instanceof` built-in classes in the new context. ```cjs const { Script, constants } = require('node:vm'); const script = new Script( 'import("node:fs").then(({readFile}) => readFile instanceof Function)', { importModuleDynamically: constants.USE\_MAIN\_CONTEXT\_DEFAULT\_LOADER }); // false: URL loaded from the main context is not an instance of the Function // class in the new context. script.runInNewContext().then(console.log); ``` ```mjs import { Script, constants } from 'node:vm'; const script = new Script( 'import("node:fs").then(({readFile}) => readFile instanceof Function)', { importModuleDynamically: constants.USE\_MAIN\_CONTEXT\_DEFAULT\_LOADER }); // false: URL loaded from the main context is not an instance of the Function // class in the new context. script.runInNewContext().then(console.log); ``` This option also allows the script or function to load user modules: ```mjs import { Script, constants } from 'node:vm'; import { resolve } from 'node:path'; import { writeFileSync } from 'node:fs'; // Write test.js and test.txt to the directory where the current script // being run is located. writeFileSync(resolve(import.meta.dirname, 'test.mjs'), 'export const filename = "./test.json";'); writeFileSync(resolve(import.meta.dirname, 'test.json'), '{"hello": "world"}'); // Compile a script that loads test.mjs and then test.json // as if the script is placed in the same directory. const script = new Script( `(async function() { const { filename } = await import('./test.mjs'); return import(filename, { with: { type: 'json' } }) })();`, { filename: resolve(import.meta.dirname, 'test-with-default.js'), importModuleDynamically: constants.USE\_MAIN\_CONTEXT\_DEFAULT\_LOADER, }); // { default: { hello: 'world' } } script.runInThisContext().then(console.log); ``` ```cjs const { Script, constants } = require('node:vm'); const { resolve } = require('node:path'); const { writeFileSync } = require('node:fs'); // Write test.js and test.txt to the directory where the current script // being run is located. writeFileSync(resolve(\_\_dirname, 'test.mjs'), 'export const filename = "./test.json";'); writeFileSync(resolve(\_\_dirname, 'test.json'), '{"hello": "world"}'); // Compile a script that loads test.mjs and then test.json // as if the script is placed in the same directory. const script = new Script( `(async function() { const { filename } = await import('./test.mjs'); return import(filename, { with: { type: 'json' } }) })();`, { filename: resolve(\_\_dirname, 'test-with-default.js'), importModuleDynamically: constants.USE\_MAIN\_CONTEXT\_DEFAULT\_LOADER, }); // { default: { hello: 'world' } } script.runInThisContext().then(console.log); ``` There are a few caveats with loading user modules using the default loader from the main context: 1. The module being resolved would be relative to the `filename` option passed to `vm.Script` or `vm.compileFunction()`. The resolution can work with a `filename` that's either an absolute path or a URL string. If `filename` is a string that's neither an absolute path or a URL, or if it's undefined, the resolution will be relative to the current working directory of the process. In the case of `vm.createContext()`, the resolution is always relative to the current working directory since this option is only used when there isn't a referrer script or module. 2. For any given `filename` that resolves to a specific path, once the process manages to load a particular module from that path, the result may be cached, and subsequent load of the same module from the same path would return the same thing. If the `filename` is a URL string, the cache would not be hit if it has
|
https://github.com/nodejs/node/blob/main//doc/api/vm.md
|
main
|
nodejs
|
[
-0.06528764963150024,
0.06310360133647919,
-0.007255039643496275,
0.07594680041074753,
0.10317105799913406,
-0.020166322588920593,
0.0021066840272396803,
0.04354262351989746,
-0.0207634586840868,
-0.04455718398094177,
0.004316572565585375,
-0.02343575842678547,
0.025974411517381668,
-0.03070155158638954,
0.0569722056388855,
0.0020842256490141153,
0.07901952415704727,
0.07728814333677292,
0.06447628885507584,
0.059827182441949844,
0.00622917152941227,
0.009462541900575161,
0.025281352922320366,
-0.007271142210811377,
-0.025789648294448853,
0.03225738927721977,
-0.05570418760180473,
-0.015284836292266846,
0.08378100395202637,
-0.0098572988063097,
-0.06587014347314835,
0.04990893229842186,
-0.08376015722751617,
0.0691383108496666,
-0.0619654506444931,
0.11621920764446259,
-0.05747535079717636,
-0.12466783821582794,
-0.05104653909802437,
0.003599073039367795,
0.04707169160246849,
0.11263683438301086,
-0.03969285264611244,
-0.03201194107532501,
-0.0009538284502923489,
-0.06937523186206818,
-0.027210595086216927,
-0.00018965001800097525,
-0.039462242275476456,
-0.026626529172062874,
-0.019021114334464073,
-0.039627041667699814,
-0.0465238094329834,
-0.025760825723409653,
-0.08368590474128723,
0.036781683564186096,
0.03939785808324814,
0.0140062952414155,
0.014727814123034477,
0.06590215116739273,
-0.018868504092097282,
-0.0017295210855081677,
0.08153953403234482,
-0.008763999678194523,
0.028648164123296738,
0.0272181648761034,
-0.012128050439059734,
0.04061931371688843,
-0.009760408662259579,
0.023895781487226486,
-0.018881557509303093,
0.029647091403603554,
-0.03746432438492775,
0.05047057196497917,
-0.03943284600973129,
-0.06211448460817337,
-0.060892254114151,
0.03216506913304329,
0.034344132989645004,
0.006373205222189426,
-0.01105352770537138,
-0.05779312178492546,
-0.027927542105317116,
-0.007173657417297363,
-0.04108687490224838,
0.09540717303752899,
-0.03025098890066147,
-0.00021502743766177446,
0.07087992131710052,
0.04863014072179794,
-0.06796062737703323,
-0.11495546251535416,
-0.036305852234363556,
0.08500272780656815,
0.027776319533586502,
0.016035309061408043,
-0.02750789187848568,
0.06349080055952072,
0.041355766355991364,
-0.022281628102064133,
-0.03614220768213272,
-0.008087576366961002,
0.009072561748325825,
0.036290962249040604,
0.027963805943727493,
-0.0016875069122761488,
0.03310656175017357,
-0.03915569931268692,
-0.03704030066728592,
-0.00643939571455121,
0.04909896105527878,
0.0589962862432003,
0.06592577695846558,
-0.08514425158500671,
0.016837630420923233,
0.015155981294810772,
0.1550988256931305,
-0.0680459663271904,
0.0002700747863855213,
0.0958690196275711,
0.03673872724175453,
0.0074445451609790325,
0.09855412691831589,
-0.06347066909074783,
-0.0006599059561267495,
-0.09931501001119614,
0.016478441655635834,
2.335075814212303e-33,
-0.04344470798969269,
-0.04112843796610832,
0.006359184626489878,
0.09319788217544556,
0.04889538511633873,
0.036954399198293686,
0.07339396327733994,
-0.00450191181153059,
-0.08982966095209122,
-0.05339017137885094,
-0.035297051072120667,
0.04886677488684654,
0.01742829941213131,
0.054689597338438034,
0.032809026539325714,
-0.0025211682077497244,
0.08764967322349548,
-0.05961450934410095,
0.1175379529595375,
-0.01478121243417263,
0.0031768307089805603,
-0.06874287873506546,
0.02807830274105072,
0.014626014977693558,
0.027441641315817833,
-0.0035946695134043694,
-0.034364428371191025,
0.002046723384410143,
0.005926768761128187,
-0.024942820891737938,
-0.003696154337376356,
0.0167232658714056,
0.01946070045232773,
0.07306955009698868,
0.031204771250486374,
-0.024981819093227386,
-0.010729415342211723,
0.04130367562174797,
-0.13692022860050201,
-0.02653004415333271,
0.03949754312634468,
0.0887693464756012,
-0.03883364424109459,
-0.016146061941981316,
-0.06295613944530487,
-0.06883395463228226,
-0.04089969024062157,
-0.033536117523908615,
0.03212705999612808,
-0.018493328243494034,
-0.03302549943327904,
0.041181862354278564,
0.04771057143807411,
-0.06903818994760513,
0.05950289964675903,
0.02361069619655609,
-0.010165463201701641,
-0.06989753991365433,
0.011389863677322865,
-0.005672781728208065,
0.03794126957654953,
-0.03715304285287857,
-0.010061651468276978,
0.11493100970983505,
0.02496579848229885,
0.041427694261074066,
-0.09941216558218002,
-0.06716588139533997,
-0.05832461267709732,
-0.039063259959220886,
-0.013367549516260624,
-0.010566347278654575,
-0.08982256799936295,
0.011520680040121078,
0.07806514203548431,
-0.016999097540974617,
-0.05136130750179291,
-0.028696462512016296,
-0.010372103191912174,
-0.036190636456012726,
0.054278455674648285,
-0.03943881019949913,
0.010706983506679535,
-0.001094935229048133,
-0.004505746066570282,
0.025852544233202934,
-0.04928244277834892,
-0.05118884891271591,
0.1549312174320221,
-0.008124415762722492,
0.060842495411634445,
-0.09717722982168198,
-0.06226316839456558,
-0.0806320384144783,
-0.07371468096971512,
-4.037209633960222e-33,
0.039524145424366,
0.052521754056215286,
-0.039403628557920456,
0.08119694888591766,
-0.011010436341166496,
-0.0045150150544941425,
-0.024960611015558243,
-0.003914041444659233,
0.027763500809669495,
0.04293692111968994,
-0.0075497617945075035,
0.011045009829103947,
0.0701960101723671,
0.05120527744293213,
-0.015139229595661163,
0.11202197521924973,
-0.09768817573785782,
-0.04351570084691048,
-0.015271023847162724,
-0.046613555401563644,
0.021685030311346054,
-0.0001644071890041232,
0.03983882814645767,
-0.033481620252132416,
-0.07311532646417618,
-0.01243001688271761,
-0.12502633035182953,
-0.00446234829723835,
-0.05561625584959984,
-0.028908269479870796,
-0.07546988129615784,
0.04312426596879959,
-0.04660317674279213,
0.007802423555403948,
-0.021168716251850128,
-0.007776447106152773,
0.019059380516409874,
0.12266981601715088,
0.04235219582915306,
-0.042302001267671585,
0.09201913326978683,
0.029619531705975533,
-0.11196625977754593,
-0.034607913345098495,
-0.03947506099939346,
-0.015254554338753223,
-0.00260904710739851,
0.009208702482283115,
0.028218949213624,
-0.0345262736082077,
-0.0849529430270195,
-0.022243769839406013,
-0.040645845234394073,
0.050080522894859314,
-0.022771090269088745,
-0.053936272859573364,
0.05996321141719818,
0.07372588664293289,
0.03607815504074097,
-0.008247883059084415,
0.047839488834142685,
-0.054798536002635956,
-0.06289117783308029,
-0.07486393302679062,
0.0012836267706006765,
-0.002254216931760311,
-0.03845381736755371,
0.032008759677410126,
0.11393988132476807,
-0.024375908076763153,
-0.023775698617100716,
-0.003473434364423156,
0.005231977440416813,
0.024732382968068123,
-0.02070769853889942,
0.013125658966600895,
0.021223843097686768,
-0.05426832288503647,
0.020714811980724335,
0.07780653238296509,
0.03549056127667427,
0.015569821000099182,
-0.007588516920804977,
0.04158376529812813,
0.010667710565030575,
0.014794832095503807,
-0.020190218463540077,
0.016386454924941063,
-0.0014472210314124823,
0.018406862393021584,
0.00631158659234643,
-0.066754549741745,
-0.08958923071622849,
0.0036257822066545486,
0.012795249000191689,
-5.518326062770029e-8,
-0.10025254637002945,
0.030222775414586067,
-0.1046467199921608,
-0.0279997568577528,
0.029243776574730873,
-0.0014246664941310883,
0.015923861414194107,
0.005433999467641115,
0.08106012642383575,
0.05477108806371689,
-0.029844973236322403,
0.005186840426176786,
0.04243403673171997,
0.01786782220005989,
-0.02614555135369301,
0.0923730656504631,
0.00542270066216588,
0.057812076061964035,
0.000491527549456805,
-0.007709362544119358,
0.0033854178618639708,
0.03505750745534897,
0.07052599638700485,
0.13310104608535767,
0.05048823729157448,
-0.017199283465743065,
0.013925760984420776,
0.010004292242228985,
-0.053844425827264786,
-0.0036619086749851704,
-0.07038042694330215,
0.07508225739002228,
-0.08128075301647186,
-0.033077213913202286,
-0.1510334312915802,
0.025294959545135498,
0.043541956692934036,
-0.05376311391592026,
0.020429523661732674,
0.024463817477226257,
-0.019362464547157288,
-0.015732284635305405,
-0.05075100436806679,
-0.0032868054695427418,
-0.011510252952575684,
0.0203434769064188,
0.00032406498212367296,
-0.03854699060320854,
-0.011297116056084633,
-0.011088847182691097,
0.040238820016384125,
-0.015571054071187973,
-0.0583866685628891,
0.054006531834602356,
-0.0030153789557516575,
-0.02870391309261322,
0.007421760819852352,
-0.0032239449210464954,
-0.03758390620350838,
-0.07557234168052673,
0.011184458620846272,
0.0031372890807688236,
0.11548839509487152,
-0.08145613223314285
] | 0.070458
|
path, once the process manages to load a particular module from that path, the result may be cached, and subsequent load of the same module from the same path would return the same thing. If the `filename` is a URL string, the cache would not be hit if it has different search parameters. For `filename`s that are not URL strings, there is currently no way to bypass the caching behavior. ### When `importModuleDynamically` is a function When `importModuleDynamically` is a function, it will be invoked when `import()` is called in the compiled code for users to customize how the requested module should be compiled and evaluated. Currently, the Node.js instance must be launched with the `--experimental-vm-modules` flag for this option to work. If the flag isn't set, this callback will be ignored. If the code evaluated actually calls to `import()`, the result will reject with [`ERR\_VM\_DYNAMIC\_IMPORT\_CALLBACK\_MISSING\_FLAG`][]. The callback `importModuleDynamically(specifier, referrer, importAttributes)` has the following signature: \* `specifier` {string} specifier passed to `import()` \* `referrer` {vm.Script|Function|vm.SourceTextModule|Object} The referrer is the compiled `vm.Script` for `new vm.Script`, `vm.runInThisContext`, `vm.runInContext` and `vm.runInNewContext`. It's the compiled `Function` for `vm.compileFunction`, the compiled `vm.SourceTextModule` for `new vm.SourceTextModule`, and the context `Object` for `vm.createContext()`. \* `importAttributes` {Object} The `"with"` value passed to the [`optionsExpression`][] optional parameter, or an empty object if no value was provided. \* `phase` {string} The phase of the dynamic import (`"source"` or `"evaluation"`). \* Returns: {Module Namespace Object|vm.Module} Returning a `vm.Module` is recommended in order to take advantage of error tracking, and to avoid issues with namespaces that contain `then` function exports. ```mjs // This script must be run with --experimental-vm-modules. import { Script, SyntheticModule } from 'node:vm'; const script = new Script('import("foo.json", { with: { type: "json" } })', { async importModuleDynamically(specifier, referrer, importAttributes) { console.log(specifier); // 'foo.json' console.log(referrer); // The compiled script console.log(importAttributes); // { type: 'json' } const m = new SyntheticModule(['bar'], () => { }); await m.link(() => { }); m.setExport('bar', { hello: 'world' }); return m; }, }); const result = await script.runInThisContext(); console.log(result); // { bar: { hello: 'world' } } ``` ```cjs // This script must be run with --experimental-vm-modules. const { Script, SyntheticModule } = require('node:vm'); (async function main() { const script = new Script('import("foo.json", { with: { type: "json" } })', { async importModuleDynamically(specifier, referrer, importAttributes) { console.log(specifier); // 'foo.json' console.log(referrer); // The compiled script console.log(importAttributes); // { type: 'json' } const m = new SyntheticModule(['bar'], () => { }); await m.link(() => { }); m.setExport('bar', { hello: 'world' }); return m; }, }); const result = await script.runInThisContext(); console.log(result); // { bar: { hello: 'world' } } })(); ``` [Cyclic Module Record]: https://tc39.es/ecma262/#sec-cyclic-module-records [ECMAScript Module Loader]: esm.md#modules-ecmascript-modules [Evaluate() concrete method]: https://tc39.es/ecma262/#sec-moduleevaluation [Evaluate() of a Synthetic Module Record]: https://tc39.es/ecma262/#sec-smr-Evaluate [FinishLoadingImportedModule]: https://tc39.es/ecma262/#sec-FinishLoadingImportedModule [GetModuleNamespace]: https://tc39.es/ecma262/#sec-getmodulenamespace [HostLoadImportedModule]: https://tc39.es/ecma262/#sec-HostLoadImportedModule [HostResolveImportedModule]: https://tc39.es/ecma262/#sec-hostresolveimportedmodule [ImportDeclaration]: https://tc39.es/ecma262/#prod-ImportDeclaration [Link() concrete method]: https://tc39.es/ecma262/#sec-moduledeclarationlinking [Module Record]: https://tc39.es/ecma262/#sec-abstract-module-records [Source Text Module Record]: https://tc39.es/ecma262/#sec-source-text-module-records [Support of dynamic `import()` in compilation APIs]: #support-of-dynamic-import-in-compilation-apis [Synthetic Module Record]: https://tc39.es/ecma262/#sec-synthetic-module-records [V8 Embedder's Guide]: https://v8.dev/docs/embed#contexts [WithClause]: https://tc39.es/ecma262/#prod-WithClause [`ERR\_VM\_DYNAMIC\_IMPORT\_CALLBACK\_MISSING\_FLAG`]: errors.md#err\_vm\_dynamic\_import\_callback\_missing\_flag [`ERR\_VM\_DYNAMIC\_IMPORT\_CALLBACK\_MISSING`]: errors.md#err\_vm\_dynamic\_import\_callback\_missing [`Error`]: errors.md#class-error [`URL`]: url.md#class-url [`eval()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/eval [`optionsExpression`]: https://tc39.es/proposal-import-attributes/#sec-evaluate-import-call [`script.runInContext()`]: #scriptrunincontextcontextifiedobject-options [`script.runInThisContext()`]: #scriptruninthiscontextoptions [`sourceTextModule.instantiate()`]: #sourcetextmoduleinstantiate [`sourceTextModule.linkRequests(modules)`]: #sourcetextmodulelinkrequestsmodules [`sourceTextModule.moduleRequests`]: #sourcetextmodulemodulerequests [`url.origin`]: url.md#urlorigin [`vm.compileFunction()`]: #vmcompilefunctioncode-params-options [`vm.constants.DONT\_CONTEXTIFY`]: #vmconstantsdont\_contextify [`vm.createContext()`]: #vmcreatecontextcontextobject-options [`vm.runInContext()`]: #vmrunincontextcode-contextifiedobject-options [`vm.runInThisContext()`]: #vmruninthiscontextcode-options [contextified]: #what-does-it-mean-to-contextify-an-object [enqueing jobs]: https://tc39.es/ecma262/#sec-hostenqueuepromisejob [global object]: https://tc39.es/ecma262/#sec-global-object [indirect `eval()` call]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/eval#direct\_and\_indirect\_eval [origin]: https://developer.mozilla.org/en-US/docs/Glossary/Origin
|
https://github.com/nodejs/node/blob/main//doc/api/vm.md
|
main
|
nodejs
|
[
-0.08330849558115005,
0.012766116298735142,
-0.00953045953065157,
0.0630807876586914,
0.055049214512109756,
-0.07130120694637299,
-0.02864614501595497,
0.003942687530070543,
0.0265455711632967,
-0.050564445555210114,
-0.011459419503808022,
0.10623054951429367,
-0.0009337455267086625,
-0.040982432663440704,
-0.00555452611297369,
-0.012949786148965359,
0.07220187783241272,
0.06862686574459076,
-0.004062833730131388,
-0.021919075399637222,
0.06239050254225731,
0.00029474092298187315,
0.05749530345201492,
-0.02699408307671547,
-0.0765155479311943,
-0.04261453077197075,
-0.04219764098525047,
-0.0372544601559639,
0.02705591358244419,
-0.039861492812633514,
-0.019250839948654175,
0.053221866488456726,
-0.13692082464694977,
0.03083755634725094,
0.024633437395095825,
0.11877333372831345,
-0.12555085122585297,
-0.12695306539535522,
-0.02787945047020912,
-0.038997575640678406,
0.07305873185396194,
0.07839542627334595,
-0.07212437689304352,
-0.061298806220293045,
0.008250934071838856,
-0.041237011551856995,
-0.009373609907925129,
-0.026191623881459236,
-0.09658748656511307,
-0.05157119035720825,
-0.011531374417245388,
-0.053764473646879196,
-0.07669557631015778,
-0.03845455124974251,
-0.017826519906520844,
0.0325431153178215,
0.03955414518713951,
0.034217625856399536,
-0.029683200642466545,
0.07374345511198044,
-0.017664486542344093,
-0.04765862599015236,
0.008709944784641266,
-0.06797434389591217,
0.03440004587173462,
0.039856359362602234,
0.016039786860346794,
-0.059532925486564636,
0.08589640259742737,
-0.029758362099528313,
-0.004490509629249573,
0.06778834015130997,
-0.027899080887436867,
0.027722148224711418,
-0.025527790188789368,
-0.025638531893491745,
-0.028696801513433456,
0.03236354514956474,
0.022404618561267853,
-0.08465497195720673,
0.01865113154053688,
-0.11324784904718399,
0.007750582415610552,
-0.02105264738202095,
-0.00008037412044359371,
0.024791479110717773,
0.007747117429971695,
-0.017580237239599228,
0.13034220039844513,
0.03326910734176636,
-0.031147833913564682,
-0.07234343141317368,
-0.04243753105401993,
0.03792605549097061,
-0.010816659778356552,
0.012405750341713428,
0.029943788424134254,
0.1433825045824051,
0.046937521547079086,
-0.0422392338514328,
0.013246990740299225,
0.02968771569430828,
0.016227513551712036,
0.024080509319901466,
0.11129821091890335,
0.04006054997444153,
0.042061518877744675,
-0.00930323451757431,
-0.02612393908202648,
-0.04247969388961792,
0.011317156255245209,
0.00311552407220006,
0.10325942933559418,
-0.03873948007822037,
-0.0311029814183712,
0.026483090594410896,
0.08489803969860077,
0.0174658615142107,
-0.014516116119921207,
0.1273730993270874,
0.04936348646879196,
0.01908164657652378,
0.11931876093149185,
-0.06383964419364929,
0.00700967013835907,
-0.057987015694379807,
0.006416857708245516,
1.3461283761036815e-33,
-0.10455139726400375,
-0.050408318638801575,
0.021718082949519157,
0.06539007276296616,
0.001348427147604525,
-0.04881031811237335,
0.09699790179729462,
0.021039171144366264,
-0.05987432971596718,
-0.021385949105024338,
-0.04893560707569122,
0.036510977894067764,
-0.03452687710523605,
0.039513327181339264,
0.0016155573539435863,
0.0710279569029808,
0.011798938736319542,
-0.052620429545640945,
0.0594245009124279,
0.028510838747024536,
0.05466176196932793,
0.00782803911715746,
0.01295611821115017,
-0.004990344401448965,
0.019325148314237595,
-0.02559168078005314,
0.04037553071975708,
-0.04477642849087715,
-0.026687202975153923,
-0.007121627684682608,
0.05162297934293747,
0.014012305065989494,
-0.010751881636679173,
0.0925317257642746,
0.014130366034805775,
0.040920406579971313,
0.020618446171283722,
0.05882618948817253,
-0.15522348880767822,
0.0348314493894577,
0.03994041681289673,
0.09217660129070282,
-0.010925112292170525,
0.008945237845182419,
-0.06886664777994156,
-0.09052760899066925,
-0.04570950195193291,
-0.008509919047355652,
0.02616947889328003,
-0.025284752249717712,
0.006387597415596247,
0.06790702790021896,
0.10575293004512787,
-0.045053936541080475,
0.012701252475380898,
-0.010384563356637955,
0.058827564120292664,
-0.07781222462654114,
-0.03336188197135925,
-0.008648921735584736,
0.027864262461662292,
-0.03815193474292755,
-0.033018097281455994,
0.08553143590688705,
-0.014331568032503128,
0.07838419079780579,
0.0008304995717480779,
-0.03275685012340546,
-0.037045665085315704,
0.0440501868724823,
-0.005948662757873535,
-0.023934517055749893,
-0.04163812845945358,
-0.0657472237944603,
0.025836525484919548,
-0.032103560864925385,
-0.10681146383285522,
-0.030747856944799423,
-0.0024238142650574446,
-0.05573707073926926,
0.016621410846710205,
-0.045013997703790665,
-0.016008911654353142,
0.06345757842063904,
-0.03231000900268555,
-0.04425977170467377,
-0.05761752277612686,
-0.055340476334095,
0.08371979743242264,
-0.033962227404117584,
0.08464942127466202,
-0.013583407737314701,
-0.019474655389785767,
-0.0010371959069743752,
-0.03804376348853111,
-2.1664742921318776e-33,
0.06468963623046875,
0.005232493858784437,
0.013625465333461761,
0.11078523099422455,
0.0037908039521425962,
-0.0076418002136051655,
-0.030783889815211296,
-0.027858063578605652,
0.019395949319005013,
0.019663704559206963,
-0.057544734328985214,
0.00943262130022049,
0.03148256242275238,
0.026987217366695404,
-0.008033450692892075,
0.12323243170976639,
-0.0711706131696701,
-0.04821545258164406,
-0.03639872372150421,
-0.01768304407596588,
-0.03703530877828598,
0.011808343231678009,
0.02254515141248703,
-0.004158128052949905,
-0.03772492706775665,
0.02080368623137474,
-0.0449291355907917,
-0.053047336637973785,
0.010709945112466812,
-0.00574315432459116,
-0.04061901569366455,
0.04708089306950569,
-0.05425453186035156,
-0.07732543349266052,
-0.014331254176795483,
0.06547098606824875,
0.02457413822412491,
0.07660587131977081,
0.0631500780582428,
0.010469791479408741,
0.015255670063197613,
0.04469047114253044,
-0.0780530646443367,
0.003310790751129389,
0.047664232552051544,
-0.044594697654247284,
-0.06080469861626625,
0.023145511746406555,
0.02418813295662403,
-0.013299449346959591,
0.007300861179828644,
0.039872635155916214,
-0.0310180876404047,
0.034035712480545044,
0.04907664656639099,
-0.005844493396580219,
-0.030823320150375366,
0.05766133591532707,
-0.012031758204102516,
0.03562566637992859,
0.10199262946844101,
-0.08106449991464615,
-0.1017414927482605,
-0.0660056322813034,
-0.09054410457611084,
0.027761904522776604,
-0.052925046533346176,
-0.043285589665174484,
0.11649775505065918,
-0.03145740553736687,
0.015127154998481274,
0.000559483130928129,
-0.047441571950912476,
-0.00600772351026535,
-0.028946319594979286,
0.0294689629226923,
0.04828936234116554,
-0.03414599597454071,
0.009847715497016907,
0.07654686272144318,
-0.013676520437002182,
0.05706961452960968,
-0.02585577964782715,
0.0019453429849818349,
-0.004025875590741634,
-0.006927099544554949,
-0.06073371693491936,
0.08036328852176666,
0.0004753482644446194,
0.035619426518678665,
0.08973188698291779,
-0.04295715317130089,
-0.06829710304737091,
-0.06021793559193611,
-0.04249034821987152,
-5.6670479864351364e-8,
-0.04144393280148506,
0.01901908405125141,
-0.06522134691476822,
0.056525226682424545,
0.027528107166290283,
0.007423201110213995,
0.039559781551361084,
0.10624831169843674,
0.08898698538541794,
0.04703831672668457,
0.04517485201358795,
0.022121747955679893,
0.005925740115344524,
0.0411030538380146,
-0.009535671211779118,
0.08978614956140518,
0.01704992540180683,
0.057073287665843964,
-0.040199507027864456,
-0.02844052202999592,
-0.03333711624145508,
0.06450945138931274,
-0.019063645973801613,
0.09419870376586914,
-0.022846965119242668,
-0.02140122279524803,
0.0529317706823349,
0.0015997615410014987,
-0.03344627842307091,
0.0021250955760478973,
-0.062332239001989365,
0.03723258897662163,
-0.05026569589972496,
-0.04308454692363739,
-0.07365412265062332,
0.02265377901494503,
0.00952520314604044,
-0.04190509393811226,
0.05785994231700897,
0.08360124379396439,
-0.015734301880002022,
0.014027956873178482,
0.015567746944725513,
0.014079106040298939,
0.00747715262696147,
-0.045268911868333817,
-0.0072735995054244995,
-0.021540524438023567,
-0.048910267651081085,
0.03970417380332947,
0.0542248860001564,
-0.07676023244857788,
-0.10985410958528519,
-0.0025066405069082975,
0.020958295091986656,
0.003797929035499692,
0.03364505246281624,
-0.04018902778625488,
0.008404533378779888,
-0.027459152042865753,
0.032679472118616104,
-0.04945746809244156,
0.0658440813422203,
-0.11271437257528305
] | 0.016025
|
# C++ addons \_Addons\_ are dynamically-linked shared objects written in C++. The [`require()`][require] function can load addons as ordinary Node.js modules. Addons provide an interface between JavaScript and C/C++ libraries. There are three options for implementing addons: \* Node-API \* `nan` ([Native Abstractions for Node.js][]) \* direct use of internal V8, libuv, and Node.js libraries Unless there is a need for direct access to functionality which is not\ exposed by Node-API, use Node-API. Refer to [C/C++ addons with Node-API](n-api.md) for more information on Node-API. When not using Node-API, implementing addons becomes more complex, requiring\ knowledge of multiple components and APIs: \* [V8][]: the C++ library Node.js uses to provide the JavaScript implementation. It provides the mechanisms for creating objects, calling functions, etc. The V8's API is documented mostly in the `v8.h` header file (`deps/v8/include/v8.h` in the Node.js source tree), and is also available [online][v8-docs]. \* [libuv][]: The C library that implements the Node.js event loop, its worker threads and all of the asynchronous behaviors of the platform. It also serves as a cross-platform abstraction library, giving easy, POSIX-like access across all major operating systems to many common system tasks, such as interacting with the file system, sockets, timers, and system events. libuv also provides a threading abstraction similar to POSIX threads for more sophisticated asynchronous addons that need to move beyond the standard event loop. Addon authors should avoid blocking the event loop with I/O or other time-intensive tasks by offloading work via libuv to non-blocking system operations, worker threads, or a custom use of libuv threads. \* Internal Node.js libraries: Node.js itself exports C++ APIs that addons can use, the most important of which is the `node::ObjectWrap` class. \* Other statically linked libraries (including OpenSSL): These other libraries are located in the `deps/` directory in the Node.js source tree. Only the libuv, OpenSSL, V8, and zlib symbols are purposefully re-exported by Node.js and may be used to various extents by addons. See [Linking to libraries included with Node.js][] for additional information. All of the following examples are available for [download][] and may be used as the starting-point for an addon. ## Hello world This "Hello world" example is a simple addon, written in C++, that is the equivalent of the following JavaScript code: ```js module.exports.hello = () => 'world'; ``` First, create the file `hello.cc`: ```cpp // hello.cc #include namespace demo { using v8::FunctionCallbackInfo; using v8::Isolate; using v8::Local; using v8::NewStringType; using v8::Object; using v8::String; using v8::Value; void Method(const FunctionCallbackInfo& args) { Isolate\* isolate = args.GetIsolate(); args.GetReturnValue().Set(String::NewFromUtf8( isolate, "world", NewStringType::kNormal).ToLocalChecked()); } void Initialize(Local exports) { NODE\_SET\_METHOD(exports, "hello", Method); } NODE\_MODULE(NODE\_GYP\_MODULE\_NAME, Initialize) } // namespace demo ``` All Node.js addons must export an initialization function following the pattern: ```cpp void Initialize(Local exports); NODE\_MODULE(NODE\_GYP\_MODULE\_NAME, Initialize) ``` There is no semi-colon after `NODE\_MODULE` as it's not a function (see `node.h`). The `module\_name` must match the filename of the final binary (excluding the `.node` suffix). In the `hello.cc` example, then, the initialization function is `Initialize` and the addon module name is `addon`. When building addons with `node-gyp`, using the macro `NODE\_GYP\_MODULE\_NAME` as the first parameter of `NODE\_MODULE()` will ensure that the name of the final binary will be passed to `NODE\_MODULE()`. Addons defined with `NODE\_MODULE()` can not be loaded in multiple contexts or multiple threads at the same time. ### Context-aware addons There are environments in which Node.js addons may need to be loaded multiple times in multiple contexts. For example, the [Electron][] runtime runs multiple instances of Node.js in a single process. Each instance will have its own `require()` cache, and thus each instance will need a native addon to behave correctly when
|
https://github.com/nodejs/node/blob/main//doc/api/addons.md
|
main
|
nodejs
|
[
-0.13670791685581207,
-0.029452277347445488,
0.01241814810782671,
0.039625175297260284,
0.04315444082021713,
0.0015888961497694254,
-0.05764845386147499,
0.05335857719182968,
0.009810823947191238,
-0.062275443226099014,
0.008410608395934105,
-0.02213788405060768,
-0.05797354876995087,
-0.039047062397003174,
0.0685211569070816,
0.02671913243830204,
0.01504506729543209,
0.012307166121900082,
-0.0030846865847706795,
-0.058709342032670975,
0.0067190187983214855,
-0.006186634302139282,
-0.08472201973199844,
-0.005123973358422518,
0.010917642153799534,
-0.0715029165148735,
-0.04321076720952988,
-0.011854794807732105,
0.09210072457790375,
0.07952655106782913,
0.04823003336787224,
-0.08890270441770554,
-0.03537893667817116,
0.059657566249370575,
-0.11774883419275284,
0.09875573217868805,
0.056493423879146576,
-0.1547744870185852,
-0.0830220952630043,
-0.0588589645922184,
0.0007219146355055273,
0.12376119196414948,
-0.07425197958946228,
-0.04553594812750816,
-0.00577865494415164,
0.004239825997501612,
-0.05219152197241783,
-0.014742514118552208,
-0.017129428684711456,
-0.03354630991816521,
0.08310333639383316,
0.03257427364587784,
-0.006161458790302277,
-0.056525636464357376,
0.00802138727158308,
0.013542287051677704,
-0.04677668586373329,
-0.0056446995586156845,
0.011504769325256348,
0.08865514397621155,
-0.00605121860280633,
-0.014398602768778801,
0.09935110062360764,
0.002112686401233077,
0.019808609038591385,
-0.00611293688416481,
-0.05491606891155243,
0.05838639661669731,
0.02254405990242958,
-0.009389431215822697,
-0.01733672060072422,
0.049546483904123306,
-0.02216249331831932,
0.016325311735272408,
-0.09243612736463547,
-0.059991806745529175,
-0.012858744710683823,
-0.013794120401144028,
-0.030528482049703598,
-0.009599016048014164,
-0.03407566621899605,
0.040692683309316635,
0.007803523447364569,
0.06085263937711716,
-0.04307955503463745,
0.0892036110162735,
-0.011283481493592262,
0.01104919146746397,
-0.011011232621967793,
0.05814213305711746,
-0.015223987400531769,
-0.0729052722454071,
-0.13351547718048096,
-0.011665258556604385,
0.10035280883312225,
-0.010213261470198631,
0.06562772393226624,
-0.005371296778321266,
-0.09066504240036011,
-0.01666394993662834,
-0.06162693351507187,
0.009426423348486423,
0.024762308225035667,
-0.007243633270263672,
0.034494854509830475,
0.017359167337417603,
-0.04611355811357498,
-0.04572290554642677,
-0.007869752123951912,
0.023180723190307617,
0.021913040429353714,
0.0789068415760994,
-0.02919449843466282,
-0.07818568497896194,
-0.053130168467760086,
0.005972808226943016,
0.037446144968271255,
-0.09662479162216187,
0.12072398513555527,
0.03355259448289871,
0.07935750484466553,
0.026981180533766747,
0.01576366275548935,
0.04527450352907181,
0.007298098411411047,
-0.06641284376382828,
-0.051682908087968826,
4.3128020804586e-33,
-0.012634671293199062,
-0.05257105454802513,
-0.012992093339562416,
0.09708788990974426,
0.017407536506652832,
0.03185829520225525,
0.025853406637907028,
0.05526679754257202,
-0.10681258887052536,
-0.04832923412322998,
-0.042997896671295166,
0.06434331089258194,
0.008699704892933369,
0.0762806385755539,
0.018980927765369415,
-0.04410364478826523,
0.08812465518712997,
-0.04926428943872452,
0.05443071573972702,
0.0157571230083704,
-0.024151545017957687,
0.02936808206140995,
0.01713746227324009,
0.13554647564888,
0.058933716267347336,
0.03103400580585003,
0.00045020529069006443,
-0.0010423045605421066,
-0.024306975305080414,
-0.015778018161654472,
0.018730444833636284,
0.0002891603799071163,
-0.05827527120709419,
0.04878346621990204,
0.04198087379336357,
0.026805240660905838,
0.004508487414568663,
-0.02072305791079998,
-0.06114773824810982,
-0.04979591816663742,
0.06268172711133957,
0.019784176722168922,
-0.1034008264541626,
-0.07547467201948166,
-0.02669486775994301,
-0.005674372427165508,
0.015548832714557648,
-0.09752374142408371,
0.02593282423913479,
-0.06474615633487701,
-0.07968245446681976,
0.04418078437447548,
-0.005421229172497988,
-0.012762150727212429,
0.011342366226017475,
-0.018430233001708984,
-0.043990761041641235,
-0.06446622312068939,
0.012069507502019405,
0.03058995120227337,
0.06452687084674835,
0.002724178833886981,
-0.00022735432139597833,
0.07739023864269257,
0.0017638407880440354,
0.008408582769334316,
-0.0666154995560646,
0.03130722790956497,
0.0714632123708725,
-0.0009097456932067871,
-0.010576295666396618,
0.03555988892912865,
0.006338777486234903,
0.013758677057921886,
0.022647881880402565,
0.005932217929512262,
-0.07858347147703171,
-0.06536014378070831,
0.0003813095099758357,
-0.009556190110743046,
0.01712421327829361,
-0.012909897603094578,
0.01722346432507038,
0.008629155345261097,
0.042431607842445374,
-0.00952544342726469,
-0.03683687373995781,
0.03029179386794567,
0.043947983533144,
-0.003914826083928347,
0.05292551964521408,
-0.06537351757287979,
-0.004007347393780947,
-0.012345870956778526,
-0.09722879528999329,
-7.829582161743394e-33,
-0.01893308013677597,
-0.00502754608169198,
-0.020238816738128662,
-0.014066522009670734,
-0.035578399896621704,
0.004828644450753927,
-0.07507767528295517,
-0.10769307613372803,
0.04664551466703415,
-0.01780731789767742,
-0.06806008517742157,
0.03211633116006851,
0.0379909873008728,
0.028304491192102432,
0.010966849513351917,
0.09223142266273499,
-0.17994579672813416,
-0.021002398803830147,
0.03141335770487785,
-0.031363293528556824,
-0.03995165973901749,
-0.002812820253893733,
0.10867225378751755,
-0.08030214160680771,
0.0354403592646122,
-0.020362820476293564,
-0.07474000006914139,
-0.024442624300718307,
-0.035787466913461685,
-0.04922039434313774,
-0.0510481558740139,
0.05874079465866089,
0.010552496649324894,
0.01156944502145052,
0.06149626895785332,
-0.0233008973300457,
0.0322578027844429,
0.06484011560678482,
0.046124495565891266,
-0.10648856312036514,
0.07877624779939651,
-0.03138025850057602,
0.0019301793072372675,
-0.008509470149874687,
0.0038382867351174355,
0.009369848296046257,
-0.07059495896100998,
0.034116100519895554,
-0.03912393003702164,
-0.03366797789931297,
0.0017265994101762772,
-0.09776744991540909,
-0.028330672532320023,
0.024227652698755264,
-0.03689943253993988,
-0.024416418746113777,
0.017196254804730415,
0.09047208726406097,
0.10763122141361237,
0.022743171080946922,
0.0029353455174714327,
-0.09076869487762451,
-0.08345059305429459,
0.0006994653376750648,
-0.07370996475219727,
-0.040757931768894196,
-0.08710555732250214,
-0.07910744100809097,
0.0692102313041687,
-0.010270372033119202,
-0.04478057846426964,
0.013842131942510605,
0.017441537231206894,
-0.026657963171601295,
-0.09850585460662842,
0.01605173759162426,
0.050674740225076675,
-0.058745015412569046,
0.03170214965939522,
0.012845361605286598,
-0.09387169778347015,
0.030783362686634064,
0.0031117694452404976,
0.01482683140784502,
0.01542233768850565,
-0.0023532144259661436,
0.03476455807685852,
0.041305702179670334,
-0.060782045125961304,
0.014830282889306545,
-0.0037235014606267214,
0.1039741039276123,
-0.07379629462957382,
0.02406976744532585,
-0.06981946527957916,
-5.538956315831456e-8,
0.031236613169312477,
-0.05209125578403473,
-0.0970502719283104,
-0.07874864339828491,
0.037507154047489166,
-0.015486587770283222,
0.08376672863960266,
0.0682399645447731,
-0.04405069723725319,
0.034734029322862625,
0.02782534621655941,
0.021796168759465218,
0.012264779768884182,
-0.06607136875391006,
-0.03691571578383446,
0.045681703835725784,
-0.04137707129120827,
-0.00042534805834293365,
0.03108294866979122,
0.016912342980504036,
0.017796531319618225,
0.03635609522461891,
-0.011213138699531555,
0.08887669444084167,
-0.04758458584547043,
-0.03882681205868721,
0.08423992246389389,
0.02889903075993061,
-0.010349975898861885,
0.03978455811738968,
-0.020249050110578537,
0.05779686197638512,
-0.0324220210313797,
0.018165819346904755,
0.03006594255566597,
0.049393534660339355,
-0.037714432924985886,
0.012933200225234032,
0.0024940117727965117,
0.03776838630437851,
0.029146045446395874,
0.0597931407392025,
0.04146056994795799,
0.007368245627731085,
0.04039291664958,
0.029445750638842583,
-0.03586215525865555,
0.02236097678542137,
-0.007007551845163107,
0.04582766816020012,
0.06767886877059937,
0.009545118547976017,
-0.007365230470895767,
0.05832670256495476,
-0.060429759323596954,
0.04019298776984215,
-0.04420693963766098,
-0.05014631152153015,
0.04677435755729675,
0.05578552186489105,
-0.024215899407863617,
0.00571404630318284,
0.1193157210946083,
-0.003146167378872633
] | 0.113297
|
environments in which Node.js addons may need to be loaded multiple times in multiple contexts. For example, the [Electron][] runtime runs multiple instances of Node.js in a single process. Each instance will have its own `require()` cache, and thus each instance will need a native addon to behave correctly when loaded via `require()`. This means that the addon must support multiple initializations. A context-aware addon can be constructed by using the macro `NODE\_MODULE\_INITIALIZER`, which expands to the name of a function which Node.js will expect to find when it loads an addon. An addon can thus be initialized as in the following example: ```cpp using namespace v8; extern "C" NODE\_MODULE\_EXPORT void NODE\_MODULE\_INITIALIZER(Local exports, Local module, Local context) { /\* Perform addon initialization steps here. \*/ } ``` Another option is to use the macro `NODE\_MODULE\_INIT()`, which will also construct a context-aware addon. Unlike `NODE\_MODULE()`, which is used to construct an addon around a given addon initializer function, `NODE\_MODULE\_INIT()` serves as the declaration of such an initializer to be followed by a function body. The following three variables may be used inside the function body following an invocation of `NODE\_MODULE\_INIT()`: \* `Local exports`, \* `Local module`, and \* `Local context` Building a context-aware addon requires careful management of global static data to ensure stability and correctness. Since the addon may be loaded multiple times, potentially even from different threads, any global static data stored in the addon must be properly protected, and must not contain any persistent references to JavaScript objects. The reason for this is that JavaScript objects are only valid in one context, and will likely cause a crash when accessed from the wrong context or from a different thread than the one on which they were created. The context-aware addon can be structured to avoid global static data by performing the following steps: \* Define a class which will hold per-addon-instance data and which has a static member of the form ```cpp static void DeleteInstance(void\* data) { // Cast `data` to an instance of the class and delete it. } ``` \* Heap-allocate an instance of this class in the addon initializer. This can be accomplished using the `new` keyword. \* Call `node::AddEnvironmentCleanupHook()`, passing it the above-created instance and a pointer to `DeleteInstance()`. This will ensure the instance is deleted when the environment is torn down. \* Store the instance of the class in a `v8::External`, and \* Pass the `v8::External` to all methods exposed to JavaScript by passing it to `v8::FunctionTemplate::New()` or `v8::Function::New()` which creates the native-backed JavaScript functions. The third parameter of `v8::FunctionTemplate::New()` or `v8::Function::New()` accepts the `v8::External` and makes it available in the native callback using the `v8::FunctionCallbackInfo::Data()` method. This will ensure that the per-addon-instance data reaches each binding that can be called from JavaScript. The per-addon-instance data must also be passed into any asynchronous callbacks the addon may create. The following example illustrates the implementation of a context-aware addon: ```cpp #include using namespace v8; class AddonData { public: explicit AddonData(Isolate\* isolate): call\_count(0) { // Ensure this per-addon-instance data is deleted at environment cleanup. node::AddEnvironmentCleanupHook(isolate, DeleteInstance, this); } // Per-addon data. int call\_count; static void DeleteInstance(void\* data) { delete static\_cast(data); } }; static void Method(const v8::FunctionCallbackInfo& info) { // Retrieve the per-addon-instance data. AddonData\* data = reinterpret\_cast(info.Data().As()->Value()); data->call\_count++; info.GetReturnValue().Set((double)data->call\_count); } // Initialize this addon to be context-aware. NODE\_MODULE\_INIT(/\* exports, module, context \*/) { Isolate\* isolate = Isolate::GetCurrent(); // Create a new instance of `AddonData` for this instance of the addon and // tie its life cycle to that of the Node.js environment. AddonData\* data = new AddonData(isolate); // Wrap the data in a `v8::External` so
|
https://github.com/nodejs/node/blob/main//doc/api/addons.md
|
main
|
nodejs
|
[
-0.09678333252668381,
-0.03264613077044487,
0.018615487962961197,
0.05155215784907341,
0.011690816842019558,
-0.04336514696478844,
0.0033618290908634663,
0.046147577464580536,
0.032317038625478745,
-0.06182681769132614,
0.0025974507443606853,
-0.04784192517399788,
-0.028253130614757538,
-0.005590397398918867,
0.10973692685365677,
0.01547735184431076,
0.0479266531765461,
-0.01126507855951786,
-0.010652944445610046,
-0.02802860178053379,
0.01934160850942135,
-0.007793089374899864,
0.013341336511075497,
-0.02496631257236004,
-0.012213526293635368,
-0.045229535549879074,
-0.02978222630918026,
0.02582644671201706,
0.1018824577331543,
0.029693150892853737,
0.06720983982086182,
0.023635568097233772,
-0.022401317954063416,
0.06276891380548477,
-0.01497575268149376,
0.1536535918712616,
-0.04860959202051163,
-0.10857708752155304,
-0.0760643407702446,
-0.00981138739734888,
0.06676845997571945,
0.09413304924964905,
-0.09795812517404556,
-0.08698196709156036,
0.010486744344234467,
-0.07184596359729767,
-0.023810597136616707,
0.050072766840457916,
-0.037532057613134384,
-0.06749583035707474,
0.05918905511498451,
-0.013428875245153904,
0.021519752219319344,
-0.08146783709526062,
-0.00402679480612278,
0.010038231499493122,
0.011381457559764385,
0.07405643910169601,
0.01576961576938629,
0.058453090488910675,
-0.04202835261821747,
-0.03392351046204567,
0.023578887805342674,
0.0379326194524765,
0.07958114147186279,
0.06865674257278442,
-0.032614950090646744,
-0.015681328251957893,
-0.014213449321687222,
-0.01666896604001522,
0.007031927816569805,
0.02535673789680004,
0.02021363563835621,
0.01945807784795761,
-0.08019175380468369,
-0.08803536742925644,
-0.0210410263389349,
-0.012700867839157581,
-0.036123231053352356,
-0.03696731850504875,
0.002288013929501176,
-0.043867502361536026,
-0.03931306302547455,
0.03058209829032421,
-0.03999415785074234,
0.062133077532052994,
0.014255710877478123,
-0.02087005414068699,
-0.008158271200954914,
0.07673849165439606,
-0.025939617305994034,
-0.09585036337375641,
-0.10052690654993057,
0.02538427710533142,
0.024782057851552963,
-0.009944615885615349,
0.05212919041514397,
0.04825817048549652,
-0.031021371483802795,
-0.04148242995142937,
0.019294723868370056,
-0.01367658656090498,
0.05276023596525192,
0.058504197746515274,
0.053528208285570145,
-0.07017375528812408,
-0.035785648971796036,
-0.01974051259458065,
-0.060577407479286194,
-0.017408065497875214,
0.02836599387228489,
0.0464971587061882,
0.019239580258727074,
-0.05268241465091705,
-0.018064890056848526,
0.024008097127079964,
0.08688077330589294,
-0.06684080511331558,
0.11384420096874237,
0.1263885349035263,
0.056208882480859756,
-0.015018492005765438,
0.0715843215584755,
-0.01139052677899599,
0.01546018198132515,
-0.019445469602942467,
-0.04285900667309761,
5.201522094770313e-34,
-0.041390955448150635,
-0.1161513552069664,
-0.026357630267739296,
0.06836847215890884,
-0.009653262794017792,
0.023010501638054848,
0.0023962135892361403,
0.03436094522476196,
-0.11374647915363312,
-0.07706422358751297,
0.03625253215432167,
0.0708034560084343,
0.03931274637579918,
0.04649155214428902,
0.018390007317066193,
0.00931578129529953,
0.0747748538851738,
0.001162364729680121,
0.06669590622186661,
0.061133094131946564,
0.03892672061920166,
-0.023932501673698425,
-0.015001359395682812,
0.029590953141450882,
0.024599850177764893,
0.021332789212465286,
0.030604127794504166,
0.009077262133359909,
-0.06116176396608353,
-0.01711229979991913,
0.05382832884788513,
0.0560733899474144,
-0.0989806279540062,
0.0952453687787056,
-0.02396579645574093,
0.03769535943865776,
0.04141441732645035,
0.027584554627537727,
-0.0620475709438324,
-0.09468648582696915,
0.038471441715955734,
0.06890041381120682,
-0.08483675122261047,
-0.0297711119055748,
-0.05132145807147026,
-0.07228022068738937,
-0.06676898896694183,
-0.06374896317720413,
0.0400533489882946,
-0.048543624579906464,
-0.027303088456392288,
0.05687987804412842,
0.0572359561920166,
-0.024023592472076416,
0.03224239498376846,
0.03635330870747566,
-0.02439842000603676,
-0.09186750650405884,
0.04754016175866127,
0.0012102121254429221,
0.029968708753585815,
0.0014663374749943614,
-0.09422033280134201,
0.12117506563663483,
0.039423707872629166,
0.028389761224389076,
-0.011287430301308632,
0.015464765019714832,
0.010598762892186642,
0.014397596940398216,
-0.024939361959695816,
-0.01201445423066616,
-0.022725636139512062,
-0.016460010781884193,
0.08416718244552612,
0.03132501244544983,
-0.09559112042188644,
-0.004505937919020653,
-0.050857361406087875,
-0.021202703937888145,
0.012592586688697338,
-0.011468445882201195,
-0.012679695151746273,
0.0708937719464302,
0.029601486399769783,
0.00007392647967208177,
-0.05695753172039986,
0.005653588101267815,
0.022377176210284233,
-0.012243191711604595,
0.0935492217540741,
-0.06680789589881897,
0.02317909337580204,
-0.02235015295445919,
-0.10222350060939789,
-3.9464096748569085e-33,
0.0007902565994299948,
0.0034939399920403957,
-0.039751086384058,
0.02261490747332573,
0.007886726409196854,
-0.009889364242553711,
-0.09623817354440689,
-0.08967442065477371,
-0.0009978453163057566,
-0.0045206742361187935,
-0.0265792328864336,
0.0442187674343586,
0.06992454081773758,
0.010681526735424995,
-0.01658102124929428,
0.11039620637893677,
-0.10595064610242844,
-0.011336213909089565,
0.09008114784955978,
-0.009042521938681602,
0.021737074479460716,
-0.0431765541434288,
0.05311806872487068,
-0.021087704226374626,
-0.048245128244161606,
-0.008863888680934906,
-0.14554135501384735,
-0.07056189328432083,
-0.018106764182448387,
-0.04059108346700668,
-0.07414175570011139,
0.09259974211454391,
0.0026570172049105167,
0.03936074674129486,
0.02061152458190918,
-0.02232305146753788,
-0.08916708827018738,
0.06515978276729584,
0.07625189423561096,
-0.0752253383398056,
0.03354419395327568,
0.01509075053036213,
-0.026579100638628006,
0.007691052742302418,
0.022730039432644844,
-0.0014198170974850655,
-0.035970911383628845,
-0.007765850052237511,
-0.06309805065393448,
0.017045043408870697,
-0.07299762964248657,
0.005962166469544172,
-0.025272415950894356,
0.018627258017659187,
-0.01102523971349001,
-0.007119947578758001,
0.018757879734039307,
0.0690213143825531,
0.08958172053098679,
-0.027489973232150078,
0.04403827339410782,
-0.13213993608951569,
-0.06121791526675224,
-0.013469391502439976,
-0.06597921997308731,
-0.04662620276212692,
-0.09582383930683136,
-0.05413893237709999,
0.045029424130916595,
-0.033599723130464554,
-0.047881316393613815,
0.02130567468702793,
-0.05925730988383293,
-0.05446447804570198,
-0.10895729064941406,
0.0454842634499073,
0.0015652845613658428,
-0.12489829212427139,
0.023635493591427803,
0.022708876058459282,
-0.06472256034612656,
0.06914209574460983,
-0.0630631223320961,
-0.03637151047587395,
-0.01911289431154728,
-0.03485580533742905,
0.010943637229502201,
0.06226199120283127,
-0.002562863752245903,
0.01573335938155651,
0.046735990792512894,
0.036725930869579315,
-0.09514933824539185,
-0.023281170055270195,
-0.07829990237951279,
-5.537684444334445e-8,
-0.022188406437635422,
-0.01705348864197731,
-0.09156365692615509,
-0.02403929829597473,
0.056506507098674774,
-0.06913258880376816,
0.06888862699270248,
0.06408768892288208,
0.05247747525572777,
0.016250213608145714,
0.027683505788445473,
0.06321019679307938,
0.05174173787236214,
-0.03732169792056084,
-0.030025620013475418,
0.07057418674230576,
0.004595125559717417,
-0.02891918085515499,
0.01389891654253006,
0.03892465680837631,
0.03683171048760414,
0.045493096113204956,
0.0014728970127180219,
0.1031988188624382,
-0.04241709038615227,
-0.02415241114795208,
0.04111955687403679,
-0.003760577877983451,
-0.0023443824611604214,
0.001770485076121986,
-0.05611514300107956,
0.058274682611227036,
-0.021019523963332176,
0.040638066828250885,
-0.06405027955770493,
0.013128010556101799,
-0.011014696210622787,
-0.03354979678988457,
0.06217008829116821,
0.022216150537133217,
0.022586511448025703,
-0.03107352741062641,
0.012302394956350327,
0.015094497241079807,
0.0007612772169522941,
0.030974695459008217,
-0.03371908888220787,
-0.00508170435205102,
0.021808551624417305,
0.0158427432179451,
0.024820471182465553,
0.025761960074305534,
-0.04041618853807449,
0.009037871845066547,
0.035435620695352554,
0.06818883121013641,
-0.027980875223875046,
-0.04443102702498436,
0.06484125554561615,
0.06578454375267029,
-0.029377281665802002,
0.001638242625631392,
0.07607465982437134,
-0.03942934796214104
] | 0.076072
|
be context-aware. NODE\_MODULE\_INIT(/\* exports, module, context \*/) { Isolate\* isolate = Isolate::GetCurrent(); // Create a new instance of `AddonData` for this instance of the addon and // tie its life cycle to that of the Node.js environment. AddonData\* data = new AddonData(isolate); // Wrap the data in a `v8::External` so we can pass it to the method we // expose. Local external = External::New(isolate, data); // Expose the method `Method` to JavaScript, and make sure it receives the // per-addon-instance data we created above by passing `external` as the // third parameter to the `FunctionTemplate` constructor. exports->Set(context, String::NewFromUtf8(isolate, "method").ToLocalChecked(), FunctionTemplate::New(isolate, Method, external) ->GetFunction(context).ToLocalChecked()).FromJust(); } ``` #### Worker support In order to be loaded from multiple Node.js environments, such as a main thread and a Worker thread, an add-on needs to either: \* Be an Node-API addon, or \* Be declared as context-aware using `NODE\_MODULE\_INIT()` as described above In order to support [`Worker`][] threads, addons need to clean up any resources they may have allocated when such a thread exits. This can be achieved through the usage of the `AddEnvironmentCleanupHook()` function: ```cpp void AddEnvironmentCleanupHook(v8::Isolate\* isolate, void (\*fun)(void\* arg), void\* arg); ``` This function adds a hook that will run before a given Node.js instance shuts down. If necessary, such hooks can be removed before they are run using `RemoveEnvironmentCleanupHook()`, which has the same signature. Callbacks are run in last-in first-out order. If necessary, there is an additional pair of `AddEnvironmentCleanupHook()` and `RemoveEnvironmentCleanupHook()` overloads, where the cleanup hook takes a callback function. This can be used for shutting down asynchronous resources, such as any libuv handles registered by the addon. The following `addon.cc` uses `AddEnvironmentCleanupHook`: ```cpp // addon.cc #include #include #include using node::AddEnvironmentCleanupHook; using v8::HandleScope; using v8::Isolate; using v8::Local; using v8::Object; // Note: In a real-world application, do not rely on static/global data. static char cookie[] = "yum yum"; static int cleanup\_cb1\_called = 0; static int cleanup\_cb2\_called = 0; static void cleanup\_cb1(void\* arg) { Isolate\* isolate = static\_cast(arg); HandleScope scope(isolate); Local obj = Object::New(isolate); assert(!obj.IsEmpty()); // assert VM is still alive assert(obj->IsObject()); cleanup\_cb1\_called++; } static void cleanup\_cb2(void\* arg) { assert(arg == static\_cast(cookie)); cleanup\_cb2\_called++; } static void sanity\_check(void\*) { assert(cleanup\_cb1\_called == 1); assert(cleanup\_cb2\_called == 1); } // Initialize this addon to be context-aware. NODE\_MODULE\_INIT(/\* exports, module, context \*/) { Isolate\* isolate = Isolate::GetCurrent(); AddEnvironmentCleanupHook(isolate, sanity\_check, nullptr); AddEnvironmentCleanupHook(isolate, cleanup\_cb2, cookie); AddEnvironmentCleanupHook(isolate, cleanup\_cb1, isolate); } ``` Test in JavaScript by running: ```js // test.js require('./build/Release/addon'); ``` ### Building Once the source code has been written, it must be compiled into the binary `addon.node` file. To do so, create a file called `binding.gyp` in the top-level of the project describing the build configuration of the module using a JSON-like format. This file is used by [node-gyp][], a tool written specifically to compile Node.js addons. ```json { "targets": [ { "target\_name": "addon", "sources": [ "hello.cc" ] } ] } ``` A version of the `node-gyp` utility is bundled and distributed with Node.js as part of `npm`. This version is not made directly available for developers to use and is intended only to support the ability to use the `npm install` command to compile and install addons. Developers who wish to use `node-gyp` directly can install it using the command `npm install -g node-gyp`. See the `node-gyp` [installation instructions][] for more information, including platform-specific requirements. Once the `binding.gyp` file has been created, use `node-gyp configure` to generate the appropriate project build files for the current platform. This will generate either a `Makefile` (on Unix platforms) or a `vcxproj` file (on Windows) in the `build/` directory. Next, invoke the `node-gyp build` command to generate the compiled `addon.node` file. This
|
https://github.com/nodejs/node/blob/main//doc/api/addons.md
|
main
|
nodejs
|
[
-0.08403372764587402,
-0.03332498297095299,
-0.007539758458733559,
0.07245149463415146,
0.028036009520292282,
0.012320554815232754,
0.01369682140648365,
0.07581991702318192,
-0.029368039220571518,
-0.01876244880259037,
0.04938386008143425,
-0.04339846968650818,
-0.10237262398004532,
-0.022443633526563644,
0.0748262032866478,
0.030016697943210602,
0.027256865054368973,
-0.032253824174404144,
-0.027774009853601456,
-0.009023510850965977,
0.04385413974523544,
-0.014683403074741364,
0.019749043509364128,
0.02622028812766075,
0.002936782082542777,
-0.02916356734931469,
-0.0384511798620224,
-0.014261315576732159,
0.0678241178393364,
0.04240339249372482,
0.04977019503712654,
-0.014400675892829895,
-0.06862201541662216,
0.0034050873946398497,
-0.03361906856298447,
0.05283687636256218,
-0.022989068180322647,
0.006834668572992086,
-0.07481368631124496,
-0.04477522522211075,
0.04982197284698486,
0.09879196435213089,
-0.06905490159988403,
-0.08343496918678284,
0.07295218855142593,
-0.10400978475809097,
-0.05511774122714996,
0.03064400888979435,
-0.007174644619226456,
-0.00033366066054441035,
0.06288297474384308,
0.012449902482330799,
-0.022848987951874733,
-0.05324224755167961,
0.001967908348888159,
-0.012689940631389618,
0.011798946186900139,
-0.006951272953301668,
0.012261969968676567,
0.06712356209754944,
0.051782235503196716,
-0.03813743218779564,
0.02387944422662258,
0.012359969317913055,
-0.03741311654448509,
0.03202151134610176,
-0.028808128088712692,
0.1057438850402832,
-0.029229769483208656,
0.03575725108385086,
0.0761990174651146,
0.021282026544213295,
0.047985564917325974,
0.006200686097145081,
-0.005753377918154001,
-0.06817503273487091,
-0.049636781215667725,
-0.020717468112707138,
-0.030608637258410454,
-0.03272039443254471,
0.0914996787905693,
-0.0060066538862884045,
-0.015954233705997467,
0.05537740886211395,
-0.03048480860888958,
0.028755057603120804,
-0.008776631206274033,
0.006741963326931,
0.03732025995850563,
0.02938675694167614,
-0.10068556666374207,
-0.014694099314510822,
-0.10975883901119232,
-0.014357734471559525,
-0.0020801329519599676,
-0.00187975843437016,
-0.028113963082432747,
0.0075526162981987,
-0.005905245430767536,
0.014621379785239697,
0.01291596982628107,
-0.009804470464587212,
-0.06753131747245789,
0.009343859739601612,
0.027609413489699364,
-0.00015407183673232794,
-0.02326180785894394,
-0.05115208029747009,
-0.028419408947229385,
0.035195402801036835,
0.03174851834774017,
0.1254882663488388,
-0.009006584994494915,
-0.008610352873802185,
-0.04948761686682701,
-0.026304764673113823,
0.10284167528152466,
-0.09463206678628922,
0.10876844078302383,
0.08264607191085815,
0.14247527718544006,
0.03880340978503227,
0.09508451819419861,
0.012760564684867859,
0.05843015015125275,
0.022205650806427002,
-0.019328024238348007,
-2.795476406057839e-34,
-0.00953668076545,
-0.05099164694547653,
-0.009793616831302643,
0.051397789269685745,
0.019155703485012054,
0.03594696894288063,
0.0032502468675374985,
0.0269699078053236,
-0.07359407842159271,
-0.006613911595195532,
-0.01393297128379345,
0.06910011172294617,
-0.01945522055029869,
-0.01825954020023346,
0.03289788216352463,
0.02016415260732174,
0.03456997126340866,
0.011448671109974384,
0.04951918497681618,
0.024622425436973572,
0.024719318374991417,
-0.038239482790231705,
-0.0020854647736996412,
0.02030090242624283,
0.003750997129827738,
0.022837786003947258,
0.005307065322995186,
0.04472307860851288,
-0.0782179981470108,
0.0038184814620763063,
0.08154676109552383,
0.03261242061853409,
-0.09887445718050003,
0.13916924595832825,
-0.010724321939051151,
0.010027449578046799,
0.01361161470413208,
-0.02479109726846218,
-0.06795360893011093,
0.01657387614250183,
0.08205553144216537,
-0.011712643317878246,
-0.06599865108728409,
-0.029627686366438866,
-0.026067359372973442,
-0.046187158674001694,
-0.0022587997373193502,
-0.0014690516982227564,
0.11302122473716736,
-0.05215447396039963,
-0.06331045925617218,
0.05872046947479248,
0.02364739030599594,
-0.08202770352363586,
0.0005474733770824969,
0.031388070434331894,
-0.03504815697669983,
-0.04097582399845123,
0.09502510726451874,
-0.004005523398518562,
-0.012718052603304386,
-0.007899947464466095,
-0.05518343672156334,
0.08135772496461868,
-0.08308455348014832,
-0.011033798567950726,
-0.04441412538290024,
-0.06341559439897537,
0.016534199938178062,
-0.08499552309513092,
-0.0172183346003294,
0.031906094402074814,
-0.019113950431346893,
0.023313643410801888,
0.08252312242984772,
-0.02298782952129841,
-0.09300947934389114,
0.010947932489216328,
-0.06487985700368881,
-0.05476485192775726,
0.049749407917261124,
-0.006231070961803198,
-0.05136357992887497,
0.12255901098251343,
0.029986143112182617,
0.06924576312303543,
-0.030427012592554092,
0.06543775647878647,
0.045376408845186234,
0.029774729162454605,
-0.011773866601288319,
-0.09583091735839844,
-0.005324938800185919,
-0.10011369735002518,
-0.0052665164694190025,
-2.7707224694926892e-33,
-0.012021968141198158,
0.017230939120054245,
0.006354991812258959,
-0.015124124474823475,
0.03000968135893345,
-0.015919584780931473,
-0.044265735894441605,
0.057468678802251816,
0.07001709938049316,
0.001471523311920464,
-0.054529741406440735,
0.021854758262634277,
0.051509443670511246,
-0.028101524338126183,
-0.03745722398161888,
0.09705255180597305,
-0.12831933796405792,
-0.030763285234570503,
0.020670823752880096,
-0.0887191966176033,
0.002578015672042966,
-0.02514682523906231,
0.06402131170034409,
-0.022759031504392624,
-0.004817739129066467,
-0.026563705876469612,
-0.05941123887896538,
0.014757550321519375,
-0.02641512081027031,
-0.05291622132062912,
-0.09635427594184875,
0.06038260459899902,
0.06478020548820496,
0.010175897739827633,
0.018518880009651184,
0.0191086083650589,
0.010456935502588749,
0.034283604472875595,
0.0102583272382617,
-0.0017242918256670237,
-0.03526998683810234,
-0.04399864375591278,
-0.09084104746580124,
-0.009840591810643673,
-0.0477449931204319,
0.02653469331562519,
-0.07157021760940552,
0.023120900616049767,
-0.0188071820884943,
0.022091839462518692,
-0.025469021871685982,
-0.09007574617862701,
-0.0630311593413353,
0.018630020320415497,
0.021795151755213737,
-0.013677341863512993,
0.07410822063684464,
-0.05248295143246651,
-0.0007036204333417118,
0.05460992828011513,
0.03507155552506447,
-0.17587892711162567,
-0.05240311473608017,
-0.008267177268862724,
0.003843356855213642,
-0.02613692916929722,
-0.028656156733632088,
-0.07469095289707184,
0.03705469146370888,
0.05013218894600868,
-0.03679905831813812,
-0.016949433833360672,
0.0030344873666763306,
-0.04764300957322121,
0.004430119413882494,
0.05160133168101311,
0.011936677619814873,
-0.1389853060245514,
0.059624794870615005,
-0.0008082066779024899,
-0.044095128774642944,
-0.06987932324409485,
0.0017998313996940851,
-0.05940849334001541,
0.05384385213255882,
-0.08719450235366821,
-0.005483259912580252,
0.07159756124019623,
-0.03364137187600136,
-0.009314646013081074,
-0.09734953194856644,
0.0073603978380560875,
-0.10898376256227493,
-0.06832808256149292,
-0.059231169521808624,
-5.8117063161944316e-8,
-0.019353151321411133,
-0.052371326833963394,
-0.09634695947170258,
0.02887440100312233,
0.011316020041704178,
-0.03262929245829582,
0.01764213852584362,
0.08277670294046402,
0.014104644767940044,
-0.010452961549162865,
-0.014104094356298447,
0.0786324143409729,
0.12602992355823517,
0.0016183446859940886,
-0.01748652756214142,
0.014971470460295677,
0.07092220336198807,
0.043171968311071396,
-0.054473090916872025,
0.06593328714370728,
0.0148689029738307,
0.08892074972391129,
0.028579484671354294,
0.015419743955135345,
0.013443833217024803,
-0.017261261120438576,
-0.035842664539813995,
0.01966654509305954,
0.07237644493579865,
0.009713046252727509,
-0.0467764250934124,
-0.02157345786690712,
-0.03606086224317551,
0.09608350694179535,
-0.14759103953838348,
0.04143814742565155,
0.03641849756240845,
0.03510524705052376,
0.01852317340672016,
0.037189602851867676,
0.08177875727415085,
-0.04214603826403618,
-0.08331894129514694,
0.042363040149211884,
0.03159593418240547,
0.002747539198026061,
-0.048091184347867966,
0.004321652464568615,
0.0013032059650868177,
0.04229343309998512,
0.024208370596170425,
0.00414774427190423,
-0.021603886038064957,
-0.010832734405994415,
0.01831139251589775,
-0.0019452307606115937,
-0.03611484169960022,
-0.04372264817357063,
0.035956598818302155,
0.10282062739133835,
-0.0919266790151596,
-0.03422493115067482,
0.06120133399963379,
-0.024693626910448074
] | 0.057605
|
file has been created, use `node-gyp configure` to generate the appropriate project build files for the current platform. This will generate either a `Makefile` (on Unix platforms) or a `vcxproj` file (on Windows) in the `build/` directory. Next, invoke the `node-gyp build` command to generate the compiled `addon.node` file. This will be put into the `build/Release/` directory. When using `npm install` to install a Node.js addon, npm uses its own bundled version of `node-gyp` to perform this same set of actions, generating a compiled version of the addon for the user's platform on demand. Once built, the binary addon can be used from within Node.js by pointing [`require()`][require] to the built `addon.node` module: ```js // hello.js const addon = require('./build/Release/addon'); console.log(addon.hello()); // Prints: 'world' ``` Because the exact path to the compiled addon binary can vary depending on how it is compiled (i.e. sometimes it may be in `./build/Debug/`), addons can use the [bindings][] package to load the compiled module. While the `bindings` package implementation is more sophisticated in how it locates addon modules, it is essentially using a `try…catch` pattern similar to: ```js try { return require('./build/Release/addon.node'); } catch (err) { return require('./build/Debug/addon.node'); } ``` ### Linking to libraries included with Node.js Node.js uses statically linked libraries such as V8, libuv, and OpenSSL. All addons are required to link to V8 and may link to any of the other dependencies as well. Typically, this is as simple as including the appropriate `#include <...>` statements (e.g. `#include `) and `node-gyp` will locate the appropriate headers automatically. However, there are a few caveats to be aware of: \* When `node-gyp` runs, it will detect the specific release version of Node.js and download either the full source tarball or just the headers. If the full source is downloaded, addons will have complete access to the full set of Node.js dependencies. However, if only the Node.js headers are downloaded, then only the symbols exported by Node.js will be available. \* `node-gyp` can be run using the `--nodedir` flag pointing at a local Node.js source image. Using this option, the addon will have access to the full set of dependencies. ### Loading addons using `require()` The filename extension of the compiled addon binary is `.node` (as opposed to `.dll` or `.so`). The [`require()`][require] function is written to look for files with the `.node` file extension and initialize those as dynamically-linked libraries. When calling [`require()`][require], the `.node` extension can usually be omitted and Node.js will still find and initialize the addon. One caveat, however, is that Node.js will first attempt to locate and load modules or JavaScript files that happen to share the same base name. For instance, if there is a file `addon.js` in the same directory as the binary `addon.node`, then [`require('addon')`][require] will give precedence to the `addon.js` file and load it instead. ## Native abstractions for Node.js Each of the examples illustrated in this document directly use the Node.js and V8 APIs for implementing addons. The V8 API can, and has, changed dramatically from one V8 release to the next (and one major Node.js release to the next). With each change, addons may need to be updated and recompiled in order to continue functioning. The Node.js release schedule is designed to minimize the frequency and impact of such changes but there is little that Node.js can do to ensure stability of the V8 APIs. The [Native Abstractions for Node.js][] (or `nan`) provide a set of tools that addon developers are recommended to use to keep compatibility between past and future releases of V8 and Node.js. See the `nan` [examples][] for an illustration
|
https://github.com/nodejs/node/blob/main//doc/api/addons.md
|
main
|
nodejs
|
[
-0.09405826032161713,
0.000009957938345905859,
0.01107056625187397,
0.026574747636914253,
0.08180545270442963,
-0.05523326247930527,
-0.04907482862472534,
0.06382711231708527,
0.02710697427392006,
0.01968821883201599,
0.020236408337950706,
0.0017642220482230186,
-0.07258106023073196,
-0.004471678752452135,
0.08012527227401733,
0.020532434806227684,
-0.011641601100564003,
0.04901319742202759,
0.04346458613872528,
-0.04950910061597824,
0.03596848249435425,
0.0014881689567118883,
0.08357980102300644,
0.003898473223671317,
-0.011334904469549656,
-0.11575107276439667,
0.011840784922242165,
0.07555757462978363,
0.07272740453481674,
0.040297266095876694,
0.012850872240960598,
-0.0028238159138709307,
0.0683152824640274,
0.04002385959029198,
-0.04730020463466644,
0.11543189734220505,
0.05036243051290512,
-0.025518491864204407,
-0.07498272508382797,
-0.08351917564868927,
0.06211547926068306,
0.09915424883365631,
-0.06106415390968323,
-0.007027267478406429,
-0.01814936473965645,
-0.019345037639141083,
-0.04632459208369255,
-0.013715286739170551,
-0.037876807153224945,
0.001747608301229775,
0.01771486923098564,
-0.07367169857025146,
-0.01908656395971775,
-0.1360970139503479,
-0.051662739366292953,
0.048563625663518906,
-0.03986704349517822,
0.05144745111465454,
0.0495300218462944,
0.0446479395031929,
0.011208157986402512,
-0.016825910657644272,
-0.00815030001103878,
-0.019986020401120186,
0.05191179737448692,
0.05443698540329933,
0.027557143941521645,
0.05023302510380745,
0.015855010598897934,
-0.0511714406311512,
0.009439815767109394,
-0.038009583950042725,
-0.04934929683804512,
-0.042637698352336884,
-0.16909152269363403,
-0.03756948560476303,
0.0055466629564762115,
0.02740592695772648,
-0.02086852863430977,
0.048097409307956696,
0.00353117473423481,
-0.03623832389712334,
0.013515056110918522,
0.06766581535339355,
-0.07400375604629517,
0.08508877456188202,
0.06903927028179169,
0.05422360077500343,
0.06649179011583328,
0.0002392806636635214,
-0.08717513084411621,
-0.09113585948944092,
-0.037069376558065414,
-0.03653512895107269,
0.024004414677619934,
0.014741533435881138,
0.04831431061029434,
0.05757814645767212,
-0.029030008241534233,
-0.026825187727808952,
-0.021815257146954536,
-0.06465663015842438,
0.040025483816862106,
-0.02145400643348694,
0.0719546377658844,
0.06314060091972351,
-0.0385744534432888,
0.0244512390345335,
0.011811372824013233,
0.03909784555435181,
-0.015155574306845665,
0.051718179136514664,
0.005429078359156847,
-0.09293579310178757,
-0.07942662388086319,
0.04693804681301117,
0.004877876024693251,
-0.01220433134585619,
0.049556490033864975,
0.07895080745220184,
0.08808105438947678,
0.007839556783437729,
0.04075758904218674,
0.006647572852671146,
-0.040363509207963943,
-0.02529319003224373,
0.030563365668058395,
-5.172829471528191e-34,
0.02508193626999855,
-0.06413338333368301,
0.03510255739092827,
0.09085755050182343,
0.07145513594150543,
-0.012578682973980904,
0.04879334941506386,
0.007005807477980852,
-0.15612435340881348,
-0.04231177270412445,
-0.0018569284584373236,
-0.0010980069637298584,
-0.025325637310743332,
0.09577345848083496,
-0.01009763777256012,
-0.054420582950115204,
0.03241928294301033,
-0.04961150139570236,
0.03258033096790314,
0.04738805815577507,
-0.033193401992321014,
0.02209971658885479,
0.02427530102431774,
0.0705527737736702,
0.051428668200969696,
-0.02406342327594757,
0.03534795343875885,
0.021407604217529297,
-0.008549047634005547,
-0.04579777270555496,
0.021768368780612946,
0.005598146468400955,
-0.02137904427945614,
0.07873834669589996,
0.010479485616087914,
0.009117075242102146,
-0.028856540098786354,
-0.005392259918153286,
-0.010204480960965157,
-0.010309441946446896,
0.09426919370889664,
0.07872139662504196,
-0.04511362314224243,
-0.060262635350227356,
0.01094837300479412,
-0.04054781794548035,
-0.054541926831007004,
-0.07988373935222626,
0.13826040923595428,
-0.0020063971169292927,
-0.03846615180373192,
0.07115905731916428,
-0.03295515105128288,
0.0018424808513373137,
0.06442001461982727,
-0.030557380989193916,
0.019670847803354263,
-0.0971204936504364,
0.03532139211893082,
-0.04384629800915718,
0.06376761943101883,
0.019457079470157623,
-0.04801953583955765,
0.06251738965511322,
-0.023956986144185066,
-0.02357204258441925,
-0.03710750862956047,
-0.0007492777658626437,
0.017186501994729042,
0.07456645369529724,
-0.017944203689694405,
-0.018242690712213516,
-0.012911323457956314,
0.038975659757852554,
0.01587471179664135,
0.0010540197836235166,
-0.07420148700475693,
0.02426951937377453,
-0.004888374358415604,
-0.014746911823749542,
0.007407665718346834,
0.043434932827949524,
-0.040904343128204346,
0.037187762558460236,
0.05172702670097351,
0.017322514206171036,
-0.07398912310600281,
0.028022542595863342,
0.0257525984197855,
-0.020023321732878685,
0.07961160689592361,
-0.08447189629077911,
-0.02552839182317257,
-0.006750157102942467,
-0.10163555294275284,
-2.407553857148128e-33,
-0.03486533463001251,
-0.0034535895101726055,
-0.05531058460474014,
0.02964547462761402,
-0.05761392042040825,
-0.016744522377848625,
-0.09627160429954529,
-0.10247878730297089,
0.03845406323671341,
0.01592983305454254,
-0.10372220724821091,
0.02935437485575676,
0.09998466074466705,
0.04498233273625374,
-0.030593423172831535,
0.04043857380747795,
-0.07329940795898438,
-0.004392991773784161,
0.004083544481545687,
-0.05652197450399399,
0.007726441603153944,
0.008395014330744743,
0.12489576637744904,
-0.0139445336535573,
0.06995407491922379,
-0.07739678770303726,
-0.001275022979825735,
0.016212623566389084,
-0.06945378333330154,
-0.07140689343214035,
-0.049127500504255295,
0.04709301143884659,
-0.07313239574432373,
-0.037697937339544296,
0.03771858289837837,
-0.043383918702602386,
-0.029136406257748604,
0.06940559297800064,
0.030780548229813576,
-0.09623298048973083,
-0.00608156668022275,
-0.07123345136642456,
-0.07402586191892624,
-0.02792351320385933,
0.016174916177988052,
0.03430509567260742,
-0.01002950593829155,
0.0342656709253788,
-0.02493411861360073,
-0.047955743968486786,
-0.0008802058873698115,
-0.0025479295291006565,
-0.001100323162972927,
0.013557770289480686,
0.02227790653705597,
-0.06152518466114998,
-0.028734970837831497,
0.07996156811714172,
0.017798854038119316,
0.014742369763553143,
0.03883327171206474,
-0.09997253865003586,
-0.0194582249969244,
-0.08561862260103226,
-0.07421750575304031,
0.017176348716020584,
-0.1246558427810669,
0.022274117916822433,
0.03718427196145058,
0.029859324917197227,
-0.05137539654970169,
0.0011761978967115283,
-0.012034876272082329,
-0.011432884261012077,
-0.06360959261655807,
0.013860022649168968,
0.028741177171468735,
-0.08705127984285355,
-0.009625844657421112,
-0.0065901014022529125,
-0.019006745889782906,
0.0924002006649971,
-0.004521799273788929,
0.03673829883337021,
0.002727201906964183,
-0.03134101256728172,
0.02145328000187874,
0.04060234874486923,
0.013485160656273365,
0.05735025927424431,
-0.004608411341905594,
0.06053335964679718,
-0.09401541203260422,
0.02350669540464878,
-0.030036553740501404,
-5.122086932374259e-8,
0.022145308554172516,
-0.014887833036482334,
-0.1365935057401657,
-0.061586130410432816,
0.04263680428266525,
0.028270522132515907,
0.09886719286441803,
-0.01913543976843357,
0.0380658321082592,
0.018123570829629898,
0.059983935207128525,
-0.015817338600754738,
-0.02542584389448166,
0.012524749152362347,
-0.054336752742528915,
0.03218848258256912,
-0.033522482961416245,
0.13442541658878326,
0.0003135680453851819,
0.007469108793884516,
0.0013032708084210753,
0.05893655866384506,
-0.029493020847439766,
0.08883886784315109,
-0.023574484512209892,
-0.047716252505779266,
0.04092910885810852,
-0.01505240984261036,
-0.07724794000387192,
0.045893289148807526,
-0.02209111861884594,
-0.00047965647536329925,
-0.03679768741130829,
0.03153460472822189,
-0.00258484180085361,
-0.013447904027998447,
-0.06282957643270493,
0.052469126880168915,
0.10822667181491852,
-0.02609286457300186,
0.013727952726185322,
0.04235000163316727,
0.006082647945731878,
0.030469346791505814,
-0.038317255675792694,
-0.0600406676530838,
-0.03896694257855415,
-0.07515721023082733,
-0.023153217509388924,
0.0038705612532794476,
0.07587410509586334,
0.004873349796980619,
-0.032515399158000946,
0.04340978339314461,
0.012721995823085308,
0.06640464812517166,
-0.03612883388996124,
-0.057304248213768005,
0.05945264920592308,
-0.0003553474380169064,
-0.0133934635668993,
-0.05101380497217178,
0.10054623335599899,
-0.02413160167634487
] | 0.06991
|
little that Node.js can do to ensure stability of the V8 APIs. The [Native Abstractions for Node.js][] (or `nan`) provide a set of tools that addon developers are recommended to use to keep compatibility between past and future releases of V8 and Node.js. See the `nan` [examples][] for an illustration of how it can be used. ## Node-API > Stability: 2 - Stable Node-API is an API for building native addons. It is independent from the underlying JavaScript runtime (e.g. V8) and is maintained as part of Node.js itself. This API will be Application Binary Interface (ABI) stable across versions of Node.js. It is intended to insulate addons from changes in the underlying JavaScript engine and allow modules compiled for one version to run on later versions of Node.js without recompilation. Addons are built/packaged with the same approach/tools outlined in this document (node-gyp, etc.). The only difference is the set of APIs that are used by the native code. Instead of using the V8 or [Native Abstractions for Node.js][] APIs, the functions available in the Node-API are used. Creating and maintaining an addon that benefits from the ABI stability provided by Node-API carries with it certain [implementation considerations][]. To use Node-API in the above "Hello world" example, replace the content of `hello.cc` with the following. All other instructions remain the same. ```cpp // hello.cc using Node-API #include namespace demo { napi\_value Method(napi\_env env, napi\_callback\_info args) { napi\_value greeting; napi\_status status; status = napi\_create\_string\_utf8(env, "world", NAPI\_AUTO\_LENGTH, &greeting); if (status != napi\_ok) return nullptr; return greeting; } napi\_value init(napi\_env env, napi\_value exports) { napi\_status status; napi\_value fn; status = napi\_create\_function(env, nullptr, 0, Method, nullptr, &fn); if (status != napi\_ok) return nullptr; status = napi\_set\_named\_property(env, exports, "hello", fn); if (status != napi\_ok) return nullptr; return exports; } NAPI\_MODULE(NODE\_GYP\_MODULE\_NAME, init) } // namespace demo ``` The functions available and how to use them are documented in [C/C++ addons with Node-API](n-api.md). ## Addon examples Following are some example addons intended to help developers get started. The examples use the V8 APIs. Refer to the online [V8 reference][v8-docs] for help with the various V8 calls, and V8's [Embedder's Guide][] for an explanation of several concepts used such as handles, scopes, function templates, etc. Each of these examples using the following `binding.gyp` file: ```json { "targets": [ { "target\_name": "addon", "sources": [ "addon.cc" ] } ] } ``` In cases where there is more than one `.cc` file, simply add the additional filename to the `sources` array: ```json "sources": ["addon.cc", "myexample.cc"] ``` Once the `binding.gyp` file is ready, the example addons can be configured and built using `node-gyp`: ```bash node-gyp configure build ``` ### Function arguments Addons will typically expose objects and functions that can be accessed from JavaScript running within Node.js. When functions are invoked from JavaScript, the input arguments and return value must be mapped to and from the C/C++ code. The following example illustrates how to read function arguments passed from JavaScript and how to return a result: ```cpp // addon.cc #include namespace demo { using v8::Exception; using v8::FunctionCallbackInfo; using v8::Isolate; using v8::Local; using v8::Number; using v8::Object; using v8::String; using v8::Value; // This is the implementation of the "add" method // Input arguments are passed using the // const FunctionCallbackInfo& args struct void Add(const FunctionCallbackInfo& args) { Isolate\* isolate = args.GetIsolate(); // Check the number of arguments passed. if (args.Length() < 2) { // Throw an Error that is passed back to JavaScript isolate->ThrowException(Exception::TypeError( String::NewFromUtf8(isolate, "Wrong number of arguments").ToLocalChecked())); return; } // Check the argument types if (!args[0]->IsNumber() || !args[1]->IsNumber()) { isolate->ThrowException(Exception::TypeError( String::NewFromUtf8(isolate, "Wrong arguments").ToLocalChecked())); return; } // Perform the operation double value =
|
https://github.com/nodejs/node/blob/main//doc/api/addons.md
|
main
|
nodejs
|
[
-0.1050279289484024,
-0.05479225888848305,
0.04415382817387581,
0.02102033607661724,
0.09436537325382233,
-0.04577330872416496,
-0.12808595597743988,
0.018138812854886055,
-0.029176834970712662,
-0.05604901909828186,
-0.08035285025835037,
0.09314607083797455,
-0.04940227419137955,
-0.05307570844888687,
0.03968164324760437,
0.03785509988665581,
0.05305761843919754,
0.007562506943941116,
-0.014290560968220234,
-0.017128877341747284,
-0.05670575425028801,
-0.0022166655398905277,
0.0012731477618217468,
0.030631769448518753,
-0.02994804084300995,
0.008327963761985302,
-0.056268781423568726,
-0.004581397864967585,
0.08382640033960342,
-0.03672831133008003,
-0.022985538467764854,
-0.03741586580872536,
-0.050561096519231796,
0.017975734546780586,
-0.11819960176944733,
0.05537153035402298,
0.03820721060037613,
-0.061163801699876785,
-0.04768512025475502,
-0.03279702737927437,
-0.03699932247400284,
0.08071105182170868,
-0.05504932999610901,
-0.07315907627344131,
0.05190487578511238,
-0.04264149069786072,
-0.04462946578860283,
-0.016442514955997467,
-0.052511200308799744,
-0.009188801050186157,
0.0670047178864479,
-0.04908348247408867,
0.011978491209447384,
-0.03998889401555061,
0.008461256511509418,
0.0079117426648736,
-0.05983567610383034,
0.05517074465751648,
-0.008842670358717442,
0.1553345024585724,
0.021311907097697258,
-0.013612121343612671,
0.06735751032829285,
-0.0033829384483397007,
0.11012011766433716,
0.01022783201187849,
0.03274088725447655,
-0.0725209042429924,
-0.0042986636981368065,
-0.019366512075066566,
0.01053924672305584,
-0.014128070324659348,
-0.006495747249573469,
-0.010693268850445747,
-0.09449110180139542,
0.011981270276010036,
-0.007640790659934282,
-0.03453498333692551,
0.010722801089286804,
0.03726682439446449,
-0.02305881306529045,
-0.059591349214315414,
-0.028471732512116432,
0.044598352164030075,
-0.03265609219670296,
0.06553518772125244,
0.0294876117259264,
-0.04735681787133217,
-0.006114501506090164,
0.07655154913663864,
-0.008763538673520088,
-0.0041335998103022575,
0.048792753368616104,
0.021228227764368057,
0.03460347279906273,
0.014123290777206421,
0.018474914133548737,
0.021040046587586403,
-0.017224377021193504,
-0.01788630336523056,
-0.014765320345759392,
0.01111937128007412,
0.04135682433843613,
0.011662950739264488,
0.0350218191742897,
-0.012760140933096409,
0.019090773537755013,
-0.01852419599890709,
0.028192777186632156,
0.04154661297798157,
0.04644724726676941,
0.057439323514699936,
-0.0027328329160809517,
-0.014662936329841614,
-0.10734611004590988,
-0.018476560711860657,
-0.015767956152558327,
-0.06384621560573578,
0.06862736493349075,
0.12484360486268997,
0.07146934419870377,
0.0799524337053299,
0.0501212403178215,
0.003659947542473674,
0.03618265688419342,
-0.022735700011253357,
0.0014148434856906533,
2.8496956697297845e-33,
-0.0636155754327774,
-0.06311937421560287,
-0.017243172973394394,
0.06581699848175049,
0.009847886860370636,
-0.0005568611086346209,
-0.04361088573932648,
0.019458789378404617,
-0.12432458251714706,
-0.05336209014058113,
-0.0009346826118417084,
0.04804730415344238,
0.021329885348677635,
-0.026061583310365677,
0.08781445771455765,
-0.02361997589468956,
0.04506201297044754,
-0.05202708765864372,
0.048724494874477386,
0.04165981337428093,
0.014423148706555367,
-0.03946031257510185,
-0.02037082239985466,
0.09253697097301483,
0.05551474168896675,
0.0044768494553864,
0.04161914065480232,
0.08416964113712311,
-0.05589115619659424,
0.002219468355178833,
-0.032532721757888794,
0.03604474291205406,
-0.0904482901096344,
0.030081287026405334,
-0.006639163941144943,
-0.018509071320295334,
-0.04448765888810158,
-0.04604581743478775,
-0.05809739604592323,
-0.011379658244550228,
-0.01584007404744625,
0.10195209085941315,
-0.06313883513212204,
-0.037927836179733276,
0.056481003761291504,
-0.08159039914608002,
0.01855923794209957,
-0.04756179451942444,
0.007354163099080324,
-0.004231738857924938,
-0.0722459927201271,
0.03306035324931145,
-0.01540947612375021,
-0.010906984098255634,
0.0412713848054409,
-0.010907644405961037,
0.05900592729449272,
-0.08183960616588593,
-0.02060650661587715,
0.04286359250545502,
0.07009687274694443,
-0.02132991887629032,
-0.030593998730182648,
-0.0284863393753767,
-0.033862341195344925,
0.079420305788517,
-0.022668132558465004,
-0.0047912332229316235,
-0.013261597603559494,
0.032174356281757355,
0.016578983515501022,
0.0032365466468036175,
0.01931808516383171,
0.002341394778341055,
0.012683349661529064,
-0.05087216943502426,
-0.06441579014062881,
-0.025166623294353485,
0.046452395617961884,
-0.023948466405272484,
0.027811851352453232,
0.011240242049098015,
-0.03525367006659508,
0.08682577311992645,
0.03293075039982796,
-0.022769765928387642,
-0.03995388001203537,
0.07218247652053833,
0.05285807326436043,
0.06164361536502838,
0.11510604619979858,
-0.03911491483449936,
0.008060264401137829,
-0.02529016137123108,
-0.05136333778500557,
-4.2096230638151734e-33,
-0.023416250944137573,
-0.02069704793393612,
-0.08700300008058548,
0.11455442756414413,
-0.08055942505598068,
-0.06067822501063347,
-0.035668499767780304,
-0.038405049592256546,
0.03067002259194851,
-0.04831843823194504,
-0.04731482267379761,
0.03132539242506027,
0.0030400860123336315,
0.028747713193297386,
0.0130862882360816,
0.05993598699569702,
-0.13063788414001465,
-0.06878762692213058,
0.03765334561467171,
-0.03092869557440281,
0.04458974301815033,
-0.008615048602223396,
0.03739480674266815,
-0.02184162102639675,
0.026944952085614204,
-0.027938323095440865,
-0.12345552444458008,
-0.022112514823675156,
0.0032004297245293856,
-0.05746186524629593,
-0.02111978828907013,
0.028991200029850006,
-0.006947650108486414,
0.00207682978361845,
0.07067182660102844,
-0.06516807526350021,
0.006037185434252024,
0.02047809399664402,
0.05076882243156433,
-0.11511357873678207,
0.014640416949987411,
0.022460442036390305,
-0.018192924559116364,
-0.018149729818105698,
0.0605258084833622,
0.10895181447267532,
-0.018588382750749588,
0.06947372108697891,
0.004189962055534124,
-0.03871145471930504,
0.01443816814571619,
-0.027708813548088074,
0.012140277773141861,
0.028443725779652596,
-0.0523412749171257,
-0.05205138027667999,
-0.03151857852935791,
0.06821616739034653,
0.03588011488318443,
0.08215922117233276,
0.05406154319643974,
-0.06841122359037399,
0.002782481722533703,
-0.002650036010891199,
-0.05581740662455559,
0.027088699862360954,
-0.08504564315080643,
-0.004796061664819717,
0.07086610794067383,
0.04958593100309372,
0.008375586941838264,
-0.07881312072277069,
0.025160012766718864,
-0.02171095460653305,
-0.11154036968946457,
0.013973959721624851,
0.06838764995336533,
-0.1348220258951187,
0.012572511099278927,
-0.06338564306497574,
-0.09467076510190964,
0.13036900758743286,
-0.01821489818394184,
0.03729352727532387,
0.022938936948776245,
0.012732245028018951,
0.01578512042760849,
0.020780319347977638,
0.0058986833319067955,
0.04783908277750015,
0.01867252215743065,
0.04289684817194939,
-0.15706484019756317,
-0.03135408088564873,
-0.04712674021720886,
-5.25855270439024e-8,
0.0004994602059014142,
0.011370969004929066,
-0.12430307269096375,
-0.00025361409643664956,
0.06926891952753067,
0.008297167718410492,
0.025327565148472786,
0.04559071734547615,
0.14150992035865784,
0.07224158197641373,
0.01942056231200695,
0.023866208270192146,
-0.006626641843467951,
-0.06290493160486221,
0.03540727496147156,
0.09806229174137115,
-0.0325096920132637,
0.002539952052757144,
-0.003906069090589881,
0.0006823190487921238,
-0.005142246838659048,
0.009278162382543087,
-0.040173519402742386,
0.054964639246463776,
-0.0669563040137291,
-0.06934626400470734,
0.04070737212896347,
0.044036850333213806,
-0.013450710102915764,
-0.008119301870465279,
-0.05521386116743088,
0.059466127306222916,
0.07564418017864227,
0.011666325852274895,
0.01911063678562641,
-0.011048514395952225,
-0.025891728699207306,
0.06835100054740906,
0.07474426925182343,
0.004196683410555124,
0.06094658002257347,
0.0219129491597414,
-0.036090414971113205,
-0.016517940908670425,
0.013610536232590675,
-0.003727988339960575,
-0.003605769481509924,
0.007589122746139765,
-0.015084479935467243,
0.042230747640132904,
0.04834088310599327,
-0.02325810119509697,
-0.056197114288806915,
0.06243901327252388,
0.008083655498921871,
-0.04546898603439331,
0.013512315228581429,
-0.14063714444637299,
0.05408076196908951,
0.027264395728707314,
0.008715099655091763,
-0.03269574046134949,
0.10789813101291656,
-0.03731357306241989
] | 0.121381
|
number of arguments passed. if (args.Length() < 2) { // Throw an Error that is passed back to JavaScript isolate->ThrowException(Exception::TypeError( String::NewFromUtf8(isolate, "Wrong number of arguments").ToLocalChecked())); return; } // Check the argument types if (!args[0]->IsNumber() || !args[1]->IsNumber()) { isolate->ThrowException(Exception::TypeError( String::NewFromUtf8(isolate, "Wrong arguments").ToLocalChecked())); return; } // Perform the operation double value = args[0].As()->Value() + args[1].As()->Value(); Local num = Number::New(isolate, value); // Set the return value (using the passed in // FunctionCallbackInfo&) args.GetReturnValue().Set(num); } void Init(Local exports) { NODE\_SET\_METHOD(exports, "add", Add); } NODE\_MODULE(NODE\_GYP\_MODULE\_NAME, Init) } // namespace demo ``` Once compiled, the example addon can be required and used from within Node.js: ```js // test.js const addon = require('./build/Release/addon'); console.log('This should be eight:', addon.add(3, 5)); ``` ### Callbacks It is common practice within addons to pass JavaScript functions to a C++ function and execute them from there. The following example illustrates how to invoke such callbacks: ```cpp // addon.cc #include namespace demo { using v8::Context; using v8::Function; using v8::FunctionCallbackInfo; using v8::Isolate; using v8::Local; using v8::Null; using v8::Object; using v8::String; using v8::Value; void RunCallback(const FunctionCallbackInfo& args) { Isolate\* isolate = args.GetIsolate(); Local context = isolate->GetCurrentContext(); Local cb = Local::Cast(args[0]); const unsigned argc = 1; Local argv[argc] = { String::NewFromUtf8(isolate, "hello world").ToLocalChecked() }; cb->Call(context, Null(isolate), argc, argv).ToLocalChecked(); } void Init(Local exports, Local module) { NODE\_SET\_METHOD(module, "exports", RunCallback); } NODE\_MODULE(NODE\_GYP\_MODULE\_NAME, Init) } // namespace demo ``` This example uses a two-argument form of `Init()` that receives the full `module` object as the second argument. This allows the addon to completely overwrite `exports` with a single function instead of adding the function as a property of `exports`. To test it, run the following JavaScript: ```js // test.js const addon = require('./build/Release/addon'); addon((msg) => { console.log(msg); // Prints: 'hello world' }); ``` In this example, the callback function is invoked synchronously. ### Object factory Addons can create and return new objects from within a C++ function as illustrated in the following example. An object is created and returned with a property `msg` that echoes the string passed to `createObject()`: ```cpp // addon.cc #include namespace demo { using v8::Context; using v8::FunctionCallbackInfo; using v8::Isolate; using v8::Local; using v8::Object; using v8::String; using v8::Value; void CreateObject(const FunctionCallbackInfo& args) { Isolate\* isolate = args.GetIsolate(); Local context = isolate->GetCurrentContext(); Local obj = Object::New(isolate); obj->Set(context, String::NewFromUtf8(isolate, "msg").ToLocalChecked(), args[0]->ToString(context).ToLocalChecked()) .FromJust(); args.GetReturnValue().Set(obj); } void Init(Local exports, Local module) { NODE\_SET\_METHOD(module, "exports", CreateObject); } NODE\_MODULE(NODE\_GYP\_MODULE\_NAME, Init) } // namespace demo ``` To test it in JavaScript: ```js // test.js const addon = require('./build/Release/addon'); const obj1 = addon('hello'); const obj2 = addon('world'); console.log(obj1.msg, obj2.msg); // Prints: 'hello world' ``` ### Function factory Another common scenario is creating JavaScript functions that wrap C++ functions and returning those back to JavaScript: ```cpp // addon.cc #include namespace demo { using v8::Context; using v8::Function; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; using v8::Isolate; using v8::Local; using v8::Object; using v8::String; using v8::Value; void MyFunction(const FunctionCallbackInfo& args) { Isolate\* isolate = args.GetIsolate(); args.GetReturnValue().Set(String::NewFromUtf8( isolate, "hello world").ToLocalChecked()); } void CreateFunction(const FunctionCallbackInfo& args) { Isolate\* isolate = args.GetIsolate(); Local context = isolate->GetCurrentContext(); Local tpl = FunctionTemplate::New(isolate, MyFunction); Local fn = tpl->GetFunction(context).ToLocalChecked(); // omit this to make it anonymous fn->SetName(String::NewFromUtf8( isolate, "theFunction").ToLocalChecked()); args.GetReturnValue().Set(fn); } void Init(Local exports, Local module) { NODE\_SET\_METHOD(module, "exports", CreateFunction); } NODE\_MODULE(NODE\_GYP\_MODULE\_NAME, Init) } // namespace demo ``` To test: ```js // test.js const addon = require('./build/Release/addon'); const fn = addon(); console.log(fn()); // Prints: 'hello world' ``` ### Wrapping C++ objects It is also possible to wrap C++ objects/classes in a way that allows new instances to be created using the JavaScript `new` operator: ```cpp // addon.cc #include #include "myobject.h" namespace demo { using v8::Local; using v8::Object; void InitAll(Local exports) { MyObject::Init(exports); } NODE\_MODULE(NODE\_GYP\_MODULE\_NAME, InitAll) } // namespace
|
https://github.com/nodejs/node/blob/main//doc/api/addons.md
|
main
|
nodejs
|
[
0.0383680984377861,
0.01389284711331129,
-0.023949073627591133,
0.01994157023727894,
-0.04426959529519081,
0.03240858390927315,
0.07066181302070618,
0.06689811497926712,
0.006476244423538446,
-0.03338778391480446,
-0.040428273379802704,
-0.06251325458288193,
-0.017632123082876205,
-0.02338865026831627,
-0.00199503474868834,
-0.03510843217372894,
-0.10271298885345459,
-0.01695319265127182,
-0.013148968107998371,
-0.04573036730289459,
0.05594300478696823,
0.00033601257018744946,
-0.023288797587156296,
-0.00020529468019958586,
0.018035680055618286,
-0.07824862748384476,
-0.05244745686650276,
-0.04263387620449066,
-0.025945886969566345,
-0.022424619644880295,
0.039714764803647995,
0.07261362671852112,
-0.07899744808673859,
0.01669277995824814,
0.04465130344033241,
0.054140884429216385,
-0.05146424099802971,
0.011616581119596958,
-0.05271545425057411,
0.046070169657468796,
0.0032241004519164562,
0.06734369695186615,
0.009524000808596611,
-0.10415207594633102,
0.054904866963624954,
-0.018206840381026268,
-0.07229930907487869,
0.08102155476808548,
0.03718530014157295,
0.05524120479822159,
0.03970155864953995,
0.06728734076023102,
-0.07647990435361862,
-0.06427246332168579,
0.04942743107676506,
-0.10446488857269287,
-0.053998492658138275,
-0.03667682036757469,
0.047504883259534836,
0.0689588189125061,
0.0005774585297331214,
-0.04562654346227646,
-0.03295332193374634,
-0.018937580287456512,
0.02830023691058159,
-0.00247195060364902,
0.00700660515576601,
-0.05841030925512314,
-0.025143304839730263,
0.10775483399629593,
-0.025406310334801674,
0.061408743262290955,
0.03541067987680435,
0.0673716738820076,
-0.037302687764167786,
0.010916617698967457,
-0.11860257387161255,
-0.0319114550948143,
0.0020759080071002245,
-0.030401885509490967,
0.042999159544706345,
-0.029262607917189598,
-0.04161248356103897,
-0.02507076784968376,
0.06876321882009506,
0.018675629049539566,
-0.01449635811150074,
0.09699169546365738,
0.09587545692920685,
0.021747056394815445,
-0.03894145414233208,
0.029821721836924553,
-0.024488555267453194,
0.12904544174671173,
0.09049589186906815,
0.006578178144991398,
0.009730652906000614,
0.03599933162331581,
-0.04417077824473381,
0.0646098256111145,
-0.015074717812240124,
-0.020533140748739243,
0.07275570929050446,
-0.030499501153826714,
0.06873182952404022,
-0.02605544775724411,
0.04156225547194481,
-0.08600848913192749,
0.023779436945915222,
-0.024051394313573837,
0.027062634006142616,
0.0857781171798706,
0.07599087059497833,
0.044364821165800095,
0.015216237865388393,
0.016941869631409645,
0.16466622054576874,
-0.0569436140358448,
0.017652947455644608,
-0.020746931433677673,
0.07156871259212494,
0.0267973430454731,
0.07714821398258209,
-0.03894851356744766,
0.016747290268540382,
0.054725389927625656,
0.005268547683954239,
3.5882336074254804e-33,
-0.0355135016143322,
-0.016756856814026833,
0.061824992299079895,
0.07129128277301788,
-0.07924864441156387,
0.005486011039465666,
0.0070243291556835175,
-0.011331816203892231,
-0.004894273355603218,
-0.0035047251731157303,
-0.02562182955443859,
-0.023141195997595787,
0.06613045185804367,
-0.004264121875166893,
0.05941722169518471,
-0.04749587923288345,
0.13850393891334534,
0.0605633407831192,
0.03553630784153938,
-0.04414359852671623,
0.010139799676835537,
-0.06680754572153091,
0.01045573502779007,
0.021273082122206688,
-0.009206282906234264,
-0.008215714246034622,
0.0416705422103405,
0.03322992101311684,
-0.03277992829680443,
0.008770645596086979,
0.05967835709452629,
-0.013886315748095512,
-0.047741468995809555,
0.10884154587984085,
0.06589744240045547,
-0.02393339015543461,
-0.024531304836273193,
0.06279110908508301,
0.006527308840304613,
-0.005258745979517698,
-0.09824303537607193,
-0.05690912902355194,
0.01766122877597809,
0.025487106293439865,
0.011029566638171673,
-0.08059274405241013,
-0.08729007840156555,
0.0005091587663628161,
0.07641250640153885,
-0.007602386176586151,
-0.03362669795751572,
0.11368764936923981,
0.04648251086473465,
-0.06630053371191025,
-0.00007140830712160096,
-0.03207554295659065,
0.023124823346734047,
0.02721659652888775,
-0.03462562710046768,
0.03125893697142601,
-0.01757996901869774,
0.06133788451552391,
-0.057560957968235016,
-0.009694199077785015,
-0.07577972859144211,
-0.000017916898286785,
-0.04994577541947365,
-0.0240488238632679,
0.013598468154668808,
-0.012327544391155243,
-0.003482999512925744,
-0.036829400807619095,
0.033848993480205536,
-0.00629743468016386,
-0.0038876747712492943,
-0.020250195637345314,
0.035551659762859344,
-0.002300793072208762,
-0.04426485300064087,
-0.08674085885286331,
0.012792229652404785,
0.052547380328178406,
-0.03903179615736008,
0.0879160463809967,
0.014546508900821209,
0.012585850432515144,
-0.005224956199526787,
0.023980550467967987,
0.018398012965917587,
0.0583026297390461,
-0.020555619150400162,
-0.028513897210359573,
-0.10415823012590408,
-0.12125047296285629,
0.004964060615748167,
-4.716931895483517e-33,
-0.028750214725732803,
0.03818533569574356,
-0.04538781940937042,
0.08253872394561768,
-0.06076817214488983,
-0.012785115279257298,
0.012327561154961586,
0.03995341435074806,
0.0011053784983232617,
-0.0871356949210167,
-0.025312315672636032,
0.04618123918771744,
0.023346539586782455,
-0.014024468138813972,
0.03922899067401886,
-0.028840668499469757,
-0.07282427698373795,
0.007795007433742285,
0.02423154190182686,
-0.02977481298148632,
0.07432068884372711,
0.005999576300382614,
0.023015011101961136,
0.017272967845201492,
-0.07948676496744156,
0.06293679028749466,
-0.00803625863045454,
-0.04337973892688751,
0.0906338319182396,
0.004976470489054918,
0.004388374742120504,
0.013326384127140045,
0.10121604055166245,
0.05293569713830948,
0.03889700397849083,
-0.13681162893772125,
0.09376590698957443,
0.07149473577737808,
-0.011559654958546162,
0.06835586577653885,
-0.04681994765996933,
-0.045842837542295456,
-0.009979969821870327,
-0.008916527032852173,
-0.03151211887598038,
-0.008574217557907104,
0.0764777734875679,
0.020009122788906097,
-0.05103165656328201,
-0.09532080590724945,
-0.01611923798918724,
-0.05279410257935524,
-0.06370782107114792,
0.04802402853965759,
-0.011543267406523228,
0.0042649065144360065,
-0.021811679005622864,
-0.06230730190873146,
0.030862195417284966,
0.03919634595513344,
-0.03677987679839134,
-0.08593201637268066,
0.05140688270330429,
-0.09654924273490906,
0.016984010115265846,
0.038867730647325516,
-0.09715420752763748,
-0.07212519645690918,
-0.037827152758836746,
0.05489325523376465,
-0.03283490985631943,
0.01155319344252348,
-0.04861215129494667,
-0.05722278356552124,
-0.06116780638694763,
-0.03565053641796112,
-0.037907443940639496,
-0.051207467913627625,
0.03186061978340149,
0.04227134957909584,
0.07188892364501953,
-0.03134273365139961,
0.03362647816538811,
0.02976013906300068,
0.0033260297495871782,
-0.0494854673743248,
0.03045549988746643,
0.07235763221979141,
0.0019023598870262504,
0.006901728920638561,
-0.020662371069192886,
0.08135516196489334,
-0.04169318079948425,
-0.04781589284539223,
-0.08955132216215134,
-5.767369870568473e-8,
-0.051304880529642105,
-0.055625271052122116,
-0.03929811343550682,
0.02541888691484928,
-0.05898004397749901,
-0.022145316004753113,
-0.09832734614610672,
-0.01073871273547411,
0.06383499503135681,
-0.043921127915382385,
-0.017800820991396904,
0.047814857214689255,
0.04768574982881546,
0.003708289237692952,
0.03171563521027565,
-0.06830597668886185,
0.020806647837162018,
0.041360411792993546,
-0.05826503783464432,
0.08210024237632751,
-0.016512509435415268,
0.016400547698140144,
-0.04137759655714035,
0.014104179106652737,
0.057782892137765884,
-0.0346892811357975,
0.02014814503490925,
0.08544798195362091,
0.07056442648172379,
-0.0349077545106411,
-0.029131051152944565,
0.03762449696660042,
-0.02763548120856285,
0.04143640026450157,
-0.11620733141899109,
0.05241185799241066,
-0.04053287208080292,
0.04990401118993759,
0.082804836332798,
-0.02165290154516697,
-0.004688514396548271,
-0.019758637994527817,
-0.07823440432548523,
0.056210730224847794,
-0.045465242117643356,
-0.038722794502973557,
-0.06560278683900833,
0.014925205148756504,
-0.031274955719709396,
-0.08399172127246857,
-0.08530236035585403,
0.042439863085746765,
0.05435075983405113,
0.017249908298254013,
-0.04291733354330063,
-0.015051414258778095,
-0.08584907650947571,
-0.07642316073179245,
0.021984409540891647,
0.08581966906785965,
0.02664010412991047,
-0.013129757717251778,
-0.05696328356862068,
0.02063176967203617
] | 0.050727
|
Wrapping C++ objects It is also possible to wrap C++ objects/classes in a way that allows new instances to be created using the JavaScript `new` operator: ```cpp // addon.cc #include #include "myobject.h" namespace demo { using v8::Local; using v8::Object; void InitAll(Local exports) { MyObject::Init(exports); } NODE\_MODULE(NODE\_GYP\_MODULE\_NAME, InitAll) } // namespace demo ``` Then, in `myobject.h`, the wrapper class inherits from `node::ObjectWrap`: ```cpp // myobject.h #ifndef MYOBJECT\_H #define MYOBJECT\_H #include #include namespace demo { class MyObject : public node::ObjectWrap { public: static void Init(v8::Local exports); private: explicit MyObject(double value = 0); ~MyObject(); static void New(const v8::FunctionCallbackInfo& args); static void PlusOne(const v8::FunctionCallbackInfo& args); double value\_; }; } // namespace demo #endif ``` In `myobject.cc`, implement the various methods that are to be exposed. In the following code, the method `plusOne()` is exposed by adding it to the constructor's prototype: ```cpp // myobject.cc #include "myobject.h" namespace demo { using v8::Context; using v8::Function; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; using v8::Isolate; using v8::Local; using v8::Number; using v8::Object; using v8::ObjectTemplate; using v8::String; using v8::Value; MyObject::MyObject(double value) : value\_(value) { } MyObject::~MyObject() { } void MyObject::Init(Local exports) { Isolate\* isolate = Isolate::GetCurrent(); Local context = isolate->GetCurrentContext(); Local addon\_data\_tpl = ObjectTemplate::New(isolate); addon\_data\_tpl->SetInternalFieldCount(1); // 1 field for the MyObject::New() Local addon\_data = addon\_data\_tpl->NewInstance(context).ToLocalChecked(); // Prepare constructor template Local tpl = FunctionTemplate::New(isolate, New, addon\_data); tpl->SetClassName(String::NewFromUtf8(isolate, "MyObject").ToLocalChecked()); tpl->InstanceTemplate()->SetInternalFieldCount(1); // Prototype NODE\_SET\_PROTOTYPE\_METHOD(tpl, "plusOne", PlusOne); Local constructor = tpl->GetFunction(context).ToLocalChecked(); addon\_data->SetInternalField(0, constructor); exports->Set(context, String::NewFromUtf8( isolate, "MyObject").ToLocalChecked(), constructor).FromJust(); } void MyObject::New(const FunctionCallbackInfo& args) { Isolate\* isolate = args.GetIsolate(); Local context = isolate->GetCurrentContext(); if (args.IsConstructCall()) { // Invoked as constructor: `new MyObject(...)` double value = args[0]->IsUndefined() ? 0 : args[0]->NumberValue(context).FromMaybe(0); MyObject\* obj = new MyObject(value); obj->Wrap(args.This()); args.GetReturnValue().Set(args.This()); } else { // Invoked as plain function `MyObject(...)`, turn into construct call. const int argc = 1; Local argv[argc] = { args[0] }; Local cons = args.Data().As()->GetInternalField(0) .As().As(); Local result = cons->NewInstance(context, argc, argv).ToLocalChecked(); args.GetReturnValue().Set(result); } } void MyObject::PlusOne(const FunctionCallbackInfo& args) { Isolate\* isolate = args.GetIsolate(); MyObject\* obj = ObjectWrap::Unwrap(args.This()); obj->value\_ += 1; args.GetReturnValue().Set(Number::New(isolate, obj->value\_)); } } // namespace demo ``` To build this example, the `myobject.cc` file must be added to the `binding.gyp`: ```json { "targets": [ { "target\_name": "addon", "sources": [ "addon.cc", "myobject.cc" ] } ] } ``` Test it with: ```js // test.js const addon = require('./build/Release/addon'); const obj = new addon.MyObject(10); console.log(obj.plusOne()); // Prints: 11 console.log(obj.plusOne()); // Prints: 12 console.log(obj.plusOne()); // Prints: 13 ``` The destructor for a wrapper object will run when the object is garbage-collected. For destructor testing, there are command-line flags that can be used to make it possible to force garbage collection. These flags are provided by the underlying V8 JavaScript engine. They are subject to change or removal at any time. They are not documented by Node.js or V8, and they should never be used outside of testing. During shutdown of the process or worker threads destructors are not called by the JS engine. Therefore it's the responsibility of the user to track these objects and ensure proper destruction to avoid resource leaks. ### Factory of wrapped objects Alternatively, it is possible to use a factory pattern to avoid explicitly creating object instances using the JavaScript `new` operator: ```js const obj = addon.createObject(); // instead of: // const obj = new addon.Object(); ``` First, the `createObject()` method is implemented in `addon.cc`: ```cpp // addon.cc #include #include "myobject.h" namespace demo { using v8::FunctionCallbackInfo; using v8::Isolate; using v8::Local; using v8::Object; using v8::String; using v8::Value; void CreateObject(const FunctionCallbackInfo& args) { MyObject::NewInstance(args); } void InitAll(Local exports, Local module) { MyObject::Init(); NODE\_SET\_METHOD(module, "exports", CreateObject); } NODE\_MODULE(NODE\_GYP\_MODULE\_NAME, InitAll) } // namespace demo ``` In `myobject.h`, the static method `NewInstance()` is added to handle instantiating the object.
|
https://github.com/nodejs/node/blob/main//doc/api/addons.md
|
main
|
nodejs
|
[
-0.11038508266210556,
0.024050194770097733,
0.011996502056717873,
0.07993094623088837,
-0.009075023233890533,
-0.014911784790456295,
-0.010800118558108807,
0.010725241154432297,
-0.06937725841999054,
-0.018678613007068634,
0.017358966171741486,
-0.06404095888137817,
-0.06447848677635193,
-0.003516112919896841,
0.09323618561029434,
0.041496630758047104,
0.01933165453374386,
0.038277044892311096,
-0.02749525010585785,
0.023889359086751938,
0.01807154342532158,
-0.031590498983860016,
-0.05490685626864433,
0.013938942924141884,
-0.02809961698949337,
-0.0529300794005394,
-0.024243678897619247,
0.02567201294004917,
0.0956130176782608,
-0.04103346914052963,
0.0037875575944781303,
-0.049658723175525665,
-0.07240734249353409,
0.10995426774024963,
0.008784119971096516,
0.14065204560756683,
0.04467124864459038,
-0.06255687773227692,
-0.0036213903222233057,
-0.04254620149731636,
0.08927997946739197,
0.11577841639518738,
-0.06625301390886307,
0.01584857888519764,
0.05442001298069954,
0.011330039240419865,
0.02746887505054474,
-0.0034856279380619526,
-0.03881961852312088,
-0.08488302677869797,
0.042933277785778046,
-0.0023120292462408543,
-0.006689100991934538,
-0.05137753486633301,
-0.04340025410056114,
0.022618871182203293,
0.0020464283879846334,
-0.04839029535651207,
0.04651691019535065,
0.09482000023126602,
-0.04824313148856163,
0.06344922631978989,
0.08725004643201828,
0.00043153311708010733,
0.015024911612272263,
-0.021182458847761154,
-0.026905622333288193,
0.09235617518424988,
-0.006590463221073151,
0.07381267845630646,
-0.06487113237380981,
0.018976997584104538,
0.03892045468091965,
0.10003353655338287,
-0.01888486184179783,
-0.04524696245789528,
-0.07524183392524719,
0.041910234838724136,
-0.06664270162582397,
0.04754086956381798,
-0.038366321474313736,
-0.013254307210445404,
-0.01989654265344143,
-0.033423468470573425,
0.011094924062490463,
0.07732698321342468,
0.016163140535354614,
-0.07854943722486496,
-0.030775029212236404,
0.025795532390475273,
-0.06851398944854736,
-0.07275030016899109,
-0.05883099138736725,
0.03661812096834183,
0.01746411807835102,
-0.046053268015384674,
0.05183329060673714,
0.00035816599847748876,
-0.005117637570947409,
0.028103768825531006,
-0.07998137921094894,
0.027693118900060654,
-0.004502486437559128,
-0.03151822090148926,
0.020083850249648094,
0.025727596133947372,
-0.09751367568969727,
-0.06164969876408577,
-0.017617523670196533,
0.014661162160336971,
-0.02475985884666443,
0.08283816277980804,
-0.055128540843725204,
-0.09858910739421844,
-0.032986726611852646,
0.011420979164540768,
0.005091438069939613,
-0.057646289467811584,
0.12849074602127075,
0.07040514796972275,
0.08826728165149689,
-0.032380979508161545,
0.06622602790594101,
0.04808321222662926,
-0.00562473526224494,
-0.031359974294900894,
-0.062480293214321136,
2.731521018589712e-33,
-0.009494902566075325,
-0.0885820984840393,
-0.06655995547771454,
0.11831541359424591,
0.015686996281147003,
0.03282472491264343,
-0.027926865965127945,
0.061426643282175064,
-0.05197400227189064,
-0.00947671476751566,
-0.02736205793917179,
-0.020770419389009476,
0.012575884349644184,
0.012346245348453522,
0.050362780690193176,
-0.0011158051202073693,
-0.014899720437824726,
0.01903017982840538,
0.025799911469221115,
0.022970855236053467,
-0.07229270040988922,
0.0054267654195427895,
-0.014009788632392883,
0.03265587240457535,
0.03189847618341446,
0.04339996352791786,
-0.0026357569731771946,
-0.0853152647614479,
0.05380863696336746,
-0.0016289271879941225,
0.019981982186436653,
0.00830976851284504,
-0.026440804824233055,
0.07781002670526505,
-0.0033817605581134558,
0.019073983654379845,
-0.005737009458243847,
0.01362127996981144,
-0.09734155982732773,
-0.023534487932920456,
0.04121752828359604,
0.009971176274120808,
-0.02517310343682766,
-0.059945523738861084,
0.001575237256474793,
-0.06456274539232254,
0.03141886740922928,
-0.05548597127199173,
-0.005478970240801573,
-0.10037051886320114,
-0.02471683919429779,
0.05507221072912216,
-0.03934376314282417,
-0.04089803993701935,
0.020350893959403038,
0.007311162073165178,
0.03681279718875885,
0.029829490929841995,
0.018941864371299744,
-0.035868868231773376,
-0.011856124736368656,
0.08655024319887161,
-0.03833343833684921,
0.08565390855073929,
-0.038253702223300934,
0.009383565746247768,
-0.04612216725945473,
-0.002664613537490368,
0.04425925388932228,
0.018112152814865112,
0.014764999970793724,
0.0514506958425045,
-0.10947619378566742,
0.05229604244232178,
0.05600900948047638,
0.04246624931693077,
-0.06363044679164886,
-0.00966811366379261,
0.0494365356862545,
-0.07329829037189484,
0.016041943803429604,
-0.012844948098063469,
0.03857043385505676,
0.01194903813302517,
0.004834427032619715,
-0.04590486362576485,
-0.02379165217280388,
0.030374666675925255,
0.023540854454040527,
0.02190229669213295,
0.012663929723203182,
-0.046752698719501495,
-0.009828099980950356,
-0.10441955924034119,
-0.08916528522968292,
-6.550282108851898e-33,
0.04362892732024193,
0.0583995059132576,
-0.019564565271139145,
0.03445956110954285,
-0.03181611746549606,
-0.011691483668982983,
-0.09404079616069794,
-0.026277238503098488,
-0.08430692553520203,
0.013041243888437748,
-0.036925967782735825,
0.026789996773004532,
0.046466052532196045,
0.07638543844223022,
0.03308141976594925,
0.0013164160773158073,
-0.1714317947626114,
-0.07259417325258255,
-0.030078325420618057,
-0.045870713889598846,
0.003654664382338524,
0.02414003014564514,
0.08793622255325317,
-0.021812962368130684,
0.034721337258815765,
-0.017612772062420845,
-0.08420146256685257,
0.11954449117183685,
0.08481311798095703,
-0.030276615172624588,
-0.0495784617960453,
0.009224990382790565,
-0.004310693126171827,
-0.01296206098049879,
-0.0000069873717620794196,
-0.013774511404335499,
-0.010330568999052048,
0.0752578005194664,
0.06745254993438721,
-0.04975016415119171,
0.047211676836013794,
-0.07093951106071472,
-0.10739438235759735,
-0.021548286080360413,
-0.07458136975765228,
-0.016809431836009026,
-0.035942867398262024,
0.0012142847990617156,
0.056351251900196075,
-0.0051706344820559025,
-0.07007338106632233,
-0.02710038237273693,
-0.03821314871311188,
-0.07690167427062988,
-0.045409198850393295,
-0.020719710737466812,
-0.01505520474165678,
-0.011190827935934067,
0.047897353768348694,
0.05024021118879318,
0.032527897506952286,
-0.08346638083457947,
0.023973088711500168,
-0.022202078253030777,
-0.020719390362501144,
-0.013659857213497162,
-0.034473858773708344,
-0.09152214229106903,
0.005467548035085201,
0.015986215323209763,
0.007724626921117306,
0.06051960960030556,
-0.07040578126907349,
-0.04249962419271469,
-0.04791431128978729,
0.030511366203427315,
0.09270266443490982,
-0.03088405914604664,
0.09246018528938293,
0.009326128289103508,
-0.08199967443943024,
-0.024820908904075623,
-0.024975642561912537,
0.03403187915682793,
-0.013612302020192146,
-0.10288766026496887,
0.023543963208794594,
0.08287648111581802,
0.0028171709273010492,
0.010421170853078365,
0.020774997770786285,
0.08253930509090424,
-0.14395461976528168,
-0.012703925371170044,
-0.10132746398448944,
-4.9259206491569785e-8,
-0.03263309970498085,
-0.018931007012724876,
-0.03736418858170509,
0.030730584636330605,
-0.01451283972710371,
0.00162429828196764,
0.007517711725085974,
-0.03255770355463028,
-0.010723311454057693,
-0.017940688878297806,
-0.025241605937480927,
0.048525337129831314,
0.05479735508561134,
-0.038169700652360916,
-0.0308687686920166,
-0.03615516051650047,
-0.05874030292034149,
-0.03516286984086037,
-0.014641701243817806,
0.04029820114374161,
-0.022228773683309555,
0.02891595847904682,
0.030005887150764465,
0.08099989593029022,
-0.03890471160411835,
-0.06570859253406525,
0.02015705406665802,
0.04645722359418869,
0.09120018780231476,
0.04464505612850189,
-0.021849537268280983,
0.08571762591600418,
0.015504654496908188,
0.12959828972816467,
-0.023112475872039795,
0.00030460560810752213,
-0.04603012651205063,
0.04173632338643074,
-0.014025228098034859,
0.06264763325452805,
0.07009626179933548,
-0.02420847676694393,
-0.050799865275621414,
0.04126130789518356,
0.051752619445323944,
0.04013148322701454,
-0.029528236016631126,
0.002039070473983884,
0.01766347512602806,
0.05746455118060112,
0.02273864671587944,
0.055868927389383316,
-0.024504413828253746,
0.06669751554727554,
-0.06226440146565437,
0.01962912641465664,
0.007070084102451801,
-0.0158814899623394,
-0.011512922123074532,
0.013166668824851513,
-0.11575039476156235,
-0.08040463924407959,
0.06091097369790077,
0.05029439181089401
] | 0.057654
|
using v8::FunctionCallbackInfo; using v8::Isolate; using v8::Local; using v8::Object; using v8::String; using v8::Value; void CreateObject(const FunctionCallbackInfo& args) { MyObject::NewInstance(args); } void InitAll(Local exports, Local module) { MyObject::Init(); NODE\_SET\_METHOD(module, "exports", CreateObject); } NODE\_MODULE(NODE\_GYP\_MODULE\_NAME, InitAll) } // namespace demo ``` In `myobject.h`, the static method `NewInstance()` is added to handle instantiating the object. This method takes the place of using `new` in JavaScript: ```cpp // myobject.h #ifndef MYOBJECT\_H #define MYOBJECT\_H #include #include namespace demo { class MyObject : public node::ObjectWrap { public: static void Init(); static void NewInstance(const v8::FunctionCallbackInfo& args); private: explicit MyObject(double value = 0); ~MyObject(); static void New(const v8::FunctionCallbackInfo& args); static void PlusOne(const v8::FunctionCallbackInfo& args); static v8::Global constructor; double value\_; }; } // namespace demo #endif ``` The implementation in `myobject.cc` is similar to the previous example: ```cpp // myobject.cc #include #include "myobject.h" namespace demo { using node::AddEnvironmentCleanupHook; using v8::Context; using v8::Function; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; using v8::Global; using v8::Isolate; using v8::Local; using v8::Number; using v8::Object; using v8::String; using v8::Value; // Warning! This is not thread-safe, this addon cannot be used for worker // threads. Global MyObject::constructor; MyObject::MyObject(double value) : value\_(value) { } MyObject::~MyObject() { } void MyObject::Init() { Isolate\* isolate = Isolate::GetCurrent(); // Prepare constructor template Local tpl = FunctionTemplate::New(isolate, New); tpl->SetClassName(String::NewFromUtf8(isolate, "MyObject").ToLocalChecked()); tpl->InstanceTemplate()->SetInternalFieldCount(1); // Prototype NODE\_SET\_PROTOTYPE\_METHOD(tpl, "plusOne", PlusOne); Local context = isolate->GetCurrentContext(); constructor.Reset(isolate, tpl->GetFunction(context).ToLocalChecked()); AddEnvironmentCleanupHook(isolate, [](void\*) { constructor.Reset(); }, nullptr); } void MyObject::New(const FunctionCallbackInfo& args) { Isolate\* isolate = args.GetIsolate(); Local context = isolate->GetCurrentContext(); if (args.IsConstructCall()) { // Invoked as constructor: `new MyObject(...)` double value = args[0]->IsUndefined() ? 0 : args[0]->NumberValue(context).FromMaybe(0); MyObject\* obj = new MyObject(value); obj->Wrap(args.This()); args.GetReturnValue().Set(args.This()); } else { // Invoked as plain function `MyObject(...)`, turn into construct call. const int argc = 1; Local argv[argc] = { args[0] }; Local cons = Local::New(isolate, constructor); Local instance = cons->NewInstance(context, argc, argv).ToLocalChecked(); args.GetReturnValue().Set(instance); } } void MyObject::NewInstance(const FunctionCallbackInfo& args) { Isolate\* isolate = args.GetIsolate(); const unsigned argc = 1; Local argv[argc] = { args[0] }; Local cons = Local::New(isolate, constructor); Local context = isolate->GetCurrentContext(); Local instance = cons->NewInstance(context, argc, argv).ToLocalChecked(); args.GetReturnValue().Set(instance); } void MyObject::PlusOne(const FunctionCallbackInfo& args) { Isolate\* isolate = args.GetIsolate(); MyObject\* obj = ObjectWrap::Unwrap(args.This()); obj->value\_ += 1; args.GetReturnValue().Set(Number::New(isolate, obj->value\_)); } } // namespace demo ``` Once again, to build this example, the `myobject.cc` file must be added to the `binding.gyp`: ```json { "targets": [ { "target\_name": "addon", "sources": [ "addon.cc", "myobject.cc" ] } ] } ``` Test it with: ```js // test.js const createObject = require('./build/Release/addon'); const obj = createObject(10); console.log(obj.plusOne()); // Prints: 11 console.log(obj.plusOne()); // Prints: 12 console.log(obj.plusOne()); // Prints: 13 const obj2 = createObject(20); console.log(obj2.plusOne()); // Prints: 21 console.log(obj2.plusOne()); // Prints: 22 console.log(obj2.plusOne()); // Prints: 23 ``` ### Passing wrapped objects around In addition to wrapping and returning C++ objects, it is possible to pass wrapped objects around by unwrapping them with the Node.js helper function `node::ObjectWrap::Unwrap`. The following examples shows a function `add()` that can take two `MyObject` objects as input arguments: ```cpp // addon.cc #include #include #include "myobject.h" namespace demo { using v8::Context; using v8::FunctionCallbackInfo; using v8::Isolate; using v8::Local; using v8::Number; using v8::Object; using v8::String; using v8::Value; void CreateObject(const FunctionCallbackInfo& args) { MyObject::NewInstance(args); } void Add(const FunctionCallbackInfo& args) { Isolate\* isolate = args.GetIsolate(); Local context = isolate->GetCurrentContext(); MyObject\* obj1 = node::ObjectWrap::Unwrap( args[0]->ToObject(context).ToLocalChecked()); MyObject\* obj2 = node::ObjectWrap::Unwrap( args[1]->ToObject(context).ToLocalChecked()); double sum = obj1->value() + obj2->value(); args.GetReturnValue().Set(Number::New(isolate, sum)); } void InitAll(Local exports) { MyObject::Init(); NODE\_SET\_METHOD(exports, "createObject", CreateObject); NODE\_SET\_METHOD(exports, "add", Add); } NODE\_MODULE(NODE\_GYP\_MODULE\_NAME, InitAll) } // namespace demo ``` In `myobject.h`, a new public method is added to allow access to private values after unwrapping the object. ```cpp // myobject.h #ifndef MYOBJECT\_H #define MYOBJECT\_H #include #include namespace demo { class MyObject : public node::ObjectWrap { public: static
|
https://github.com/nodejs/node/blob/main//doc/api/addons.md
|
main
|
nodejs
|
[
-0.0958041101694107,
0.011845067143440247,
-0.02323383279144764,
0.05563366413116455,
-0.019604576751589775,
-0.040943898260593414,
0.007157092913985252,
0.06072908639907837,
0.005815601907670498,
-0.04541417211294174,
0.031577251851558685,
-0.07355529814958572,
-0.08247744292020798,
-0.017338614910840988,
0.05993794649839401,
0.022323237732052803,
0.0313689149916172,
-0.005349263083189726,
-0.022122899070382118,
-0.004019940737634897,
0.03998994082212448,
-0.006206380669027567,
-0.04838748276233673,
0.02170795015990734,
0.012059317901730537,
-0.07232041656970978,
-0.036867909133434296,
0.046534400433301926,
0.12517112493515015,
-0.02988286316394806,
0.024948181584477425,
-0.014298388734459877,
-0.061874475330114365,
0.03605405613780022,
-0.01055139023810625,
0.15466301143169403,
-0.006367680616676807,
-0.04454643279314041,
0.009556089527904987,
-0.05803687870502472,
0.05082140862941742,
0.07960275560617447,
-0.07638055086135864,
-0.03203580528497696,
0.054145447909832,
-0.004843353759497404,
-0.012235136702656746,
0.06956992298364639,
-0.03690176084637642,
-0.05823773890733719,
0.005782174412161112,
-0.03013167716562748,
-0.05970054119825363,
-0.07354185730218887,
0.015057417564094067,
0.011616700328886509,
-0.00887237023562193,
-0.04809240624308586,
0.044761817902326584,
0.08178277313709259,
-0.05164644867181778,
0.07917074859142303,
0.07710818946361542,
-0.012091490440070629,
0.02573130838572979,
-0.01554859522730112,
-0.039392150938510895,
0.014597500674426556,
0.00384602602571249,
0.07022900879383087,
-0.07472412288188934,
0.03983412683010101,
0.07235385477542877,
0.07702171802520752,
-0.016404839232563972,
-0.07760226726531982,
-0.06788437068462372,
0.0533590093255043,
-0.030683215707540512,
0.0189377274364233,
0.013021237216889858,
-0.004821956157684326,
-0.019700320437550545,
-0.004989395849406719,
0.0030382813420146704,
0.05821707844734192,
-0.011104661040008068,
-0.02353503741323948,
0.00483806012198329,
0.02292771264910698,
-0.12797492742538452,
-0.03789303079247475,
-0.09072422981262207,
0.032372064888477325,
0.012115741148591042,
-0.07041478902101517,
0.061241623014211655,
0.014081833884119987,
0.02986704371869564,
0.04896629601716995,
-0.07409119606018066,
0.016578292474150658,
0.05208081007003784,
0.005122439470142126,
-0.011889414861798286,
0.030859414488077164,
-0.08623918890953064,
-0.06550329178571701,
0.016872532665729523,
0.012669166550040245,
-0.04815318062901497,
0.09794352203607559,
-0.04917680099606514,
-0.07390198111534119,
-0.015169926919043064,
-0.019567398354411125,
0.0401451550424099,
-0.10410460084676743,
0.1370120346546173,
0.11398017406463623,
0.1349131166934967,
-0.04572287201881409,
0.07326165586709976,
0.009389969520270824,
-0.026175854727625847,
0.03207075595855713,
-0.021635888144373894,
4.3230479830939545e-33,
0.013586733490228653,
-0.06652820855379105,
-0.060505520552396774,
0.10294944047927856,
-0.02048453874886036,
0.041804246604442596,
0.0037686110008507967,
0.050537899136543274,
-0.05200697109103203,
-0.014674541540443897,
-0.01564539223909378,
0.005058789625763893,
0.01712125353515148,
-0.03651675209403038,
0.0682080090045929,
0.01963438279926777,
0.02203863114118576,
-0.026773914694786072,
0.022160880267620087,
0.030501607805490494,
-0.01653911918401718,
0.036518219858407974,
-0.002341469516977668,
0.041999004781246185,
0.013496405445039272,
0.04459037631750107,
0.004209792707115412,
-0.07314861565828323,
-0.02619616687297821,
0.015987267717719078,
0.06596524268388748,
0.009086914360523224,
-0.05991205945611,
0.11348122358322144,
0.00586850568652153,
-0.00420779874548316,
-0.005395649466663599,
-0.009452376514673233,
-0.12884582579135895,
0.0010844432981684804,
0.05067287012934685,
0.008858911693096161,
-0.04079276695847511,
-0.04573608189821243,
0.007370357401669025,
-0.0605187751352787,
-0.036039549857378006,
-0.005216067191213369,
0.04693266749382019,
-0.06270408630371094,
-0.045064352452754974,
0.06268279999494553,
0.010701672174036503,
-0.045613501220941544,
-0.010261083021759987,
0.023505236953496933,
-0.005115161649882793,
-0.02679465152323246,
0.013875683769583702,
-0.04661741480231285,
-0.05282047390937805,
0.0586886927485466,
-0.04143689572811127,
0.11298781633377075,
-0.04143064469099045,
-0.00030163643532432616,
-0.05401758849620819,
-0.035301852971315384,
0.0430014505982399,
0.012580985203385353,
0.03434917330741882,
0.04106760025024414,
-0.08963144570589066,
0.020423272624611855,
0.018730824813246727,
0.029517116025090218,
-0.050030406564474106,
-0.002938359510153532,
-0.016594257205724716,
-0.08345267921686172,
0.008247586898505688,
0.032213591039180756,
-0.02113466151058674,
0.06674755364656448,
0.017138654366135597,
0.01068698987364769,
-0.018449820578098297,
0.010738745331764221,
0.04281070828437805,
0.003500604070723057,
-0.030201105400919914,
-0.06692089885473251,
-0.06286079436540604,
-0.12679749727249146,
-0.04254809394478798,
-8.090929086077743e-33,
0.09362200647592545,
0.038652122020721436,
-0.04559681937098503,
0.09530568867921829,
-0.04378708824515343,
-0.018428953364491463,
-0.040712904185056686,
0.009653482586145401,
-0.049776580184698105,
0.028346208855509758,
-0.06268329918384552,
0.02688024193048477,
0.035524774342775345,
0.03621586412191391,
0.06085912138223648,
0.006893589161336422,
-0.1513930857181549,
-0.0829613134264946,
-0.018180329352617264,
-0.03142447769641876,
0.012732282280921936,
0.009217767976224422,
0.06208647042512894,
-0.05930008366703987,
0.006615726742893457,
-0.04719405621290207,
-0.09592881053686142,
0.08703049272298813,
0.023501809686422348,
-0.034691497683525085,
-0.08735832571983337,
0.07353503257036209,
0.011630740948021412,
0.008367909118533134,
-0.02781946025788784,
-0.02821159176528454,
-0.02135835587978363,
0.03684135898947716,
0.08581770956516266,
-0.043144986033439636,
0.02282150648534298,
-0.021253397688269615,
-0.08464377373456955,
-0.01568414457142353,
-0.055686105042696,
0.02406392991542816,
-0.012914463877677917,
-0.018399953842163086,
0.05121292173862457,
-0.0011830152943730354,
-0.0062551554292440414,
-0.06438329815864563,
-0.07722679525613785,
-0.07066480815410614,
-0.07497496902942657,
0.01228946354240179,
0.023140577599406242,
-0.05734317749738693,
0.03183221071958542,
0.07276806235313416,
0.06273455172777176,
-0.11358551681041718,
-0.0026906051207333803,
-0.0021167583763599396,
-0.04329393804073334,
-0.04112312197685242,
-0.04562908411026001,
-0.04611273109912872,
0.07003661245107651,
-0.008530771359801292,
-0.0442984364926815,
0.03655337169766426,
-0.013960340060293674,
-0.027248485013842583,
-0.046958405524492264,
0.040835537016391754,
0.0475979782640934,
-0.06255059689283371,
0.0836150199174881,
0.021228935569524765,
-0.03670185059309006,
-0.00318237766623497,
-0.01347538735717535,
-0.004369252827018499,
0.011419393122196198,
-0.09897379577159882,
-0.0034099312033504248,
0.10104070603847504,
-0.030443254858255386,
-0.02803097851574421,
0.019687367603182793,
0.09275102615356445,
-0.12097431719303131,
-0.02312537655234337,
-0.09190039336681366,
-5.432249849945947e-8,
-0.04656905680894852,
-0.009680597111582756,
-0.07665672898292542,
0.04103861004114151,
-0.008886991068720818,
0.009680474177002907,
0.01680763065814972,
-0.015922360122203827,
0.0448833592236042,
-0.005407531745731831,
-0.01315024122595787,
0.029068460687994957,
0.08623142540454865,
-0.013826006092131138,
-0.043470948934555054,
-0.001527326530776918,
0.0008782544173300266,
0.007104656659066677,
-0.05783674120903015,
0.01589985564351082,
-0.03994949907064438,
0.020765874534845352,
0.015061421319842339,
0.04555352032184601,
0.003033342305570841,
-0.09591826051473618,
0.01658353954553604,
0.060658469796180725,
0.07807338982820511,
0.03358488529920578,
-0.07359515875577927,
0.11048518866300583,
0.008634787052869797,
0.10594579577445984,
-0.07724259048700333,
0.036625076085329056,
-0.047380752861499786,
0.06398896872997284,
0.039067286998033524,
0.02523110806941986,
0.07326012849807739,
-0.013598015531897545,
-0.08029425144195557,
0.01592082902789116,
-0.007737906649708748,
0.024755729362368584,
-0.04395430162549019,
0.0042645568028092384,
-0.00467288913205266,
0.04091960936784744,
0.004359022248536348,
0.05573366954922676,
-0.0505201555788517,
0.0563012920320034,
0.010376328602433205,
0.01820320449769497,
0.027310611680150032,
-0.07442618161439896,
0.005607080180197954,
-0.009351802989840508,
-0.11485528945922852,
-0.04745420068502426,
0.07239148765802383,
0.0026546907611191273
] | 0.099552
|
CreateObject); NODE\_SET\_METHOD(exports, "add", Add); } NODE\_MODULE(NODE\_GYP\_MODULE\_NAME, InitAll) } // namespace demo ``` In `myobject.h`, a new public method is added to allow access to private values after unwrapping the object. ```cpp // myobject.h #ifndef MYOBJECT\_H #define MYOBJECT\_H #include #include namespace demo { class MyObject : public node::ObjectWrap { public: static void Init(); static void NewInstance(const v8::FunctionCallbackInfo& args); inline double value() const { return value\_; } private: explicit MyObject(double value = 0); ~MyObject(); static void New(const v8::FunctionCallbackInfo& args); static v8::Global constructor; double value\_; }; } // namespace demo #endif ``` The implementation of `myobject.cc` remains similar to the previous version: ```cpp // myobject.cc #include #include "myobject.h" namespace demo { using node::AddEnvironmentCleanupHook; using v8::Context; using v8::Function; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; using v8::Global; using v8::Isolate; using v8::Local; using v8::Object; using v8::String; using v8::Value; // Warning! This is not thread-safe, this addon cannot be used for worker // threads. Global MyObject::constructor; MyObject::MyObject(double value) : value\_(value) { } MyObject::~MyObject() { } void MyObject::Init() { Isolate\* isolate = Isolate::GetCurrent(); // Prepare constructor template Local tpl = FunctionTemplate::New(isolate, New); tpl->SetClassName(String::NewFromUtf8(isolate, "MyObject").ToLocalChecked()); tpl->InstanceTemplate()->SetInternalFieldCount(1); Local context = isolate->GetCurrentContext(); constructor.Reset(isolate, tpl->GetFunction(context).ToLocalChecked()); AddEnvironmentCleanupHook(isolate, [](void\*) { constructor.Reset(); }, nullptr); } void MyObject::New(const FunctionCallbackInfo& args) { Isolate\* isolate = args.GetIsolate(); Local context = isolate->GetCurrentContext(); if (args.IsConstructCall()) { // Invoked as constructor: `new MyObject(...)` double value = args[0]->IsUndefined() ? 0 : args[0]->NumberValue(context).FromMaybe(0); MyObject\* obj = new MyObject(value); obj->Wrap(args.This()); args.GetReturnValue().Set(args.This()); } else { // Invoked as plain function `MyObject(...)`, turn into construct call. const int argc = 1; Local argv[argc] = { args[0] }; Local cons = Local::New(isolate, constructor); Local instance = cons->NewInstance(context, argc, argv).ToLocalChecked(); args.GetReturnValue().Set(instance); } } void MyObject::NewInstance(const FunctionCallbackInfo& args) { Isolate\* isolate = args.GetIsolate(); const unsigned argc = 1; Local argv[argc] = { args[0] }; Local cons = Local::New(isolate, constructor); Local context = isolate->GetCurrentContext(); Local instance = cons->NewInstance(context, argc, argv).ToLocalChecked(); args.GetReturnValue().Set(instance); } } // namespace demo ``` Test it with: ```js // test.js const addon = require('./build/Release/addon'); const obj1 = addon.createObject(10); const obj2 = addon.createObject(20); const result = addon.add(obj1, obj2); console.log(result); // Prints: 30 ``` [Electron]: https://electronjs.org/ [Embedder's Guide]: https://v8.dev/docs/embed [Linking to libraries included with Node.js]: #linking-to-libraries-included-with-nodejs [Native Abstractions for Node.js]: https://github.com/nodejs/nan [V8]: https://v8.dev/ [`Worker`]: worker\_threads.md#class-worker [bindings]: https://github.com/TooTallNate/node-bindings [download]: https://github.com/nodejs/node-addon-examples [examples]: https://github.com/nodejs/nan/tree/HEAD/examples/ [implementation considerations]: n-api.md#implications-of-abi-stability [installation instructions]: https://github.com/nodejs/node-gyp#installation [libuv]: https://github.com/libuv/libuv [node-gyp]: https://github.com/nodejs/node-gyp [require]: modules.md#requireid [v8-docs]: https://v8docs.nodesource.com/
|
https://github.com/nodejs/node/blob/main//doc/api/addons.md
|
main
|
nodejs
|
[
-0.06878652423620224,
0.08881435543298721,
-0.03805248439311981,
0.07084324955940247,
-0.03546849265694618,
0.012355746701359749,
-0.00510849105194211,
0.0808735191822052,
-0.06203056126832962,
-0.007965427823364735,
0.029346883296966553,
-0.08419666439294815,
-0.07930123060941696,
-0.033241529017686844,
0.09123913943767548,
0.015870999544858932,
0.0006485271733254194,
0.05542391166090965,
-0.026560749858617783,
-0.016933145001530647,
0.027670888230204582,
0.007986382581293583,
-0.027649719268083572,
0.041214924305677414,
0.00879379641264677,
-0.07946760952472687,
-0.04008381441235542,
0.06984081864356995,
0.10922720283269882,
0.00035300891613587737,
0.02041270025074482,
-0.03384586423635483,
-0.021554263308644295,
0.05387883260846138,
0.0259350948035717,
0.1320905238389969,
-0.003654442261904478,
-0.06727265566587448,
-0.03684362769126892,
-0.027692509815096855,
0.041683487594127655,
0.07257205247879028,
-0.0968816876411438,
0.008613433688879013,
0.02741020731627941,
-0.006855114828795195,
0.08296012878417969,
0.02871277555823326,
0.010261913761496544,
-0.0887952446937561,
0.041449129581451416,
-0.03461616113781929,
-0.01913801208138466,
-0.08091656863689423,
-0.0011279197642579675,
0.010847163386642933,
-0.009865139611065388,
-0.06400065124034882,
0.0435594841837883,
0.05453110113739967,
-0.0406440831720829,
0.01991885155439377,
0.07046951353549957,
0.0036145192570984364,
0.03158629685640335,
0.010815976187586784,
-0.016848837956786156,
0.04542631283402443,
-0.017684724181890488,
0.04423072934150696,
0.006248484365642071,
0.05223938822746277,
0.10296401381492615,
0.06658760458230972,
-0.025966985151171684,
-0.05822116509079933,
-0.08960472047328949,
0.024078816175460815,
-0.027700601145625114,
0.021024910733103752,
-0.004753340966999531,
-0.008215353824198246,
0.03518212214112282,
0.028846601024270058,
-0.011265886016190052,
0.06966818869113922,
-0.002877732738852501,
-0.03424917533993721,
-0.004040773957967758,
0.06850402057170868,
-0.08733158558607101,
-0.04573803022503853,
-0.13537660241127014,
0.03364471346139908,
-0.004623871296644211,
-0.04568421468138695,
0.028339825570583344,
0.0085292998701334,
-0.015839073807001114,
0.06595131754875183,
-0.014493818394839764,
-0.006150422152131796,
-0.005973678547888994,
-0.04363982379436493,
0.07329573482275009,
-0.006579312030225992,
0.007451397832483053,
-0.03312813490629196,
-0.03197203204035759,
0.030043242499232292,
-0.05489498749375343,
0.08238044381141663,
-0.07716386020183563,
-0.0318157821893692,
0.011375916190445423,
-0.01787891611456871,
0.0217458326369524,
-0.04991945996880531,
0.0720926821231842,
0.01648629643023014,
0.0766802430152893,
-0.05153776332736015,
0.06573101878166199,
0.031699370592832565,
-0.07796847820281982,
-0.030154194682836533,
-0.03368460759520531,
3.552528701203223e-33,
-0.012564735487103462,
-0.07573164254426956,
-0.012126860208809376,
0.080115407705307,
-0.01620386727154255,
0.02826010063290596,
-0.010055397637188435,
0.0053044757805764675,
-0.09452465176582336,
0.009351418353617191,
0.0072995927184820175,
0.01789604313671589,
0.031181374564766884,
0.0016471324488520622,
0.041666921228170395,
-0.023114440962672234,
0.016237124800682068,
0.0009595591109246016,
0.07529264688491821,
0.0036112512461841106,
0.03439703956246376,
-0.017895635217428207,
0.007756666745990515,
-0.0009591691778041422,
-0.01175627764314413,
0.009723696857690811,
-0.0019595897756516933,
-0.0842566266655922,
0.03599980100989342,
0.02357087843120098,
0.06679311394691467,
0.027004383504390717,
0.014419960789382458,
0.10509153455495834,
0.029275905340909958,
-0.07826597988605499,
0.007628901395946741,
0.012176989577710629,
-0.09733425825834274,
-0.006587177515029907,
0.06705689430236816,
-0.0197179913520813,
-0.00022569649445358664,
-0.06949477642774582,
0.020630262792110443,
-0.06825200468301773,
-0.048390232026576996,
0.030773159116506577,
0.005155513994395733,
-0.06753706187009811,
-0.018048381432890892,
0.10567287355661392,
-0.0924043357372284,
-0.05041796714067459,
-0.006052389740943909,
0.027333928272128105,
0.013771007768809795,
-0.016358088701963425,
-0.060139160603284836,
-0.0038252549711614847,
-0.06183731555938721,
0.14038360118865967,
-0.0017537783132866025,
0.03980087861418724,
-0.05422581732273102,
0.032475605607032776,
-0.05808774381875992,
-0.07428812980651855,
0.04239484295248985,
-0.053275711834430695,
-0.009420560672879219,
0.0381803885102272,
-0.07101157307624817,
0.01506422832608223,
-0.008619418367743492,
0.03244350850582123,
-0.049577899277210236,
0.0013083504745736718,
0.017238400876522064,
-0.07475025951862335,
-0.03288498520851135,
0.012548411265015602,
0.014404550194740295,
0.10214629024267197,
0.007735067047178745,
-0.0409543551504612,
-0.06465324759483337,
0.04471712186932564,
0.04400103539228439,
0.011270719580352306,
0.00676789740100503,
-0.03569892793893814,
-0.06371403485536575,
-0.15490636229515076,
-0.05369985103607178,
-6.789357088658011e-33,
0.06595178693532944,
0.07765120267868042,
-0.05770343169569969,
0.052763279527425766,
0.020017893984913826,
-0.043248724192380905,
-0.05620649456977844,
-0.0468924418091774,
-0.005956413224339485,
0.03306625410914421,
-0.026711631566286087,
0.025290869176387787,
0.01669066585600376,
0.02953433245420456,
0.06494716554880142,
-0.02037513442337513,
-0.14292941987514496,
-0.034745391458272934,
-0.03068532794713974,
-0.020570049062371254,
0.011596969328820705,
0.04702719673514366,
0.09801942855119705,
-0.022663870826363564,
0.039767567068338394,
-0.02756979875266552,
-0.0797920823097229,
0.06940888613462448,
0.06330479681491852,
-0.01678401045501232,
-0.06888230890035629,
0.05876782163977623,
-0.01368971262127161,
-0.013406852260231972,
0.024584824219346046,
-0.07218783348798752,
-0.015040714293718338,
0.054269663989543915,
0.02971969172358513,
-0.02603815123438835,
0.07404932379722595,
0.008052862249314785,
-0.11151227355003357,
-0.03519398719072342,
-0.05144061520695686,
0.03781646862626076,
-0.029963459819555283,
-0.03764047846198082,
0.0462457500398159,
0.008239086717367172,
-0.05996551737189293,
-0.09423891454935074,
-0.015349103137850761,
-0.007971614599227905,
-0.0031681072432547808,
-0.017142651602625847,
0.016502922400832176,
-0.046027977019548416,
0.08963335305452347,
0.057093311101198196,
0.0863213911652565,
-0.12016844004392624,
-0.03849082440137863,
0.012354712001979351,
0.014249032363295555,
-0.04759206622838974,
-0.10265406221151352,
-0.0711960420012474,
-0.002168393926694989,
0.032623134553432465,
-0.0035550498869270086,
0.004011948127299547,
-0.008111278526484966,
-0.03868716210126877,
-0.04265236109495163,
0.05780899152159691,
0.024999968707561493,
-0.025159252807497978,
0.027572404593229294,
0.05839170888066292,
0.00020436431805137545,
0.036566171795129776,
-0.047106049954891205,
0.012551193125545979,
0.010702831670641899,
-0.1159527599811554,
0.014582432806491852,
0.07699258625507355,
-0.014541029930114746,
-0.01409383025020361,
-0.004165480844676495,
0.07020331919193268,
-0.15579786896705627,
0.014576736837625504,
-0.11564718931913376,
-5.3132833244262656e-8,
-0.055597852915525436,
-0.042927760630846024,
-0.03390689194202423,
0.0688944086432457,
0.018501462414860725,
-0.023297959938645363,
-0.03534385934472084,
-0.05151243507862091,
0.012206422165036201,
-0.05563521757721901,
-0.005953328683972359,
0.020326070487499237,
0.08123025298118591,
-0.048896320164203644,
-0.05246003344655037,
-0.026447894051671028,
-0.007665088865906,
-0.051164284348487854,
-0.026690522208809853,
-0.0078078024089336395,
-0.06286618858575821,
-0.03343893215060234,
-0.01568691059947014,
0.09609454870223999,
0.007569953333586454,
-0.02970842272043228,
0.012422358617186546,
0.034205593168735504,
0.07069390267133713,
0.07239153236150742,
0.026034699752926826,
0.053013864904642105,
0.042456768453121185,
0.1467217355966568,
-0.06258786469697952,
0.0445999801158905,
-0.0560365691781044,
0.06495426595211029,
0.03997478261590004,
0.061371732503175735,
0.018321054056286812,
0.03993910178542137,
-0.01956416293978691,
0.03338456526398659,
0.05217665061354637,
0.010301089845597744,
0.02188282273709774,
0.01754823327064514,
0.021521875634789467,
0.03865712881088257,
-0.024347959086298943,
0.06951365619897842,
-0.03739892691373825,
0.07212503999471664,
-0.007688454352319241,
0.03304864838719368,
0.003138420172035694,
-0.03802179917693138,
-0.06836720556020737,
0.05941448733210564,
-0.12020678073167801,
-0.06517551839351654,
-0.011914756149053574,
-0.012813999317586422
] | 0.102895
|
# Environment Variables Environment variables are variables associated to the environment the Node.js process runs in. ## CLI Environment Variables There is a set of environment variables that can be defined to customize the behavior of Node.js, for more details refer to the [CLI Environment Variables documentation][]. ## `process.env` The basic API for interacting with environment variables is `process.env`, it consists of an object with pre-populated user environment variables that can be modified and expanded. For more details refer to the [`process.env` documentation][]. ## DotEnv Set of utilities for dealing with additional environment variables defined in `.env` files. > Stability: 2 - Stable ### .env files `.env` files (also known as dotenv files) are files that define environment variables, which Node.js applications can then interact with (popularized by the [dotenv][] package). The following is an example of the content of a basic `.env` file: ```text MY\_VAR\_A = "my variable A" MY\_VAR\_B = "my variable B" ``` This type of file is used in various different programming languages and platforms but there is no formal specification for it, therefore Node.js defines its own specification described below. A `.env` file is a file that contains key-value pairs, each pair is represented by a variable name followed by the equal sign (`=`) followed by a variable value. The name of such files is usually `.env` or it starts with `.env` (like for example `.env.dev` where `dev` indicates a specific target environment). This is the recommended naming scheme but it is not mandatory and dotenv files can have any arbitrary file name. #### Variable Names A valid variable name must contain only letters (uppercase or lowercase), digits and underscores (`\_`) and it can't begin with a digit. More specifically a valid variable name must match the following regular expression: ```text ^[a-zA-Z\_]+[a-zA-Z0-9\_]\*$ ``` The recommended convention is to use capital letters with underscores and digits when necessary, but any variable name respecting the above definition will work just fine. For example, the following are some valid variable names: `MY\_VAR`, `MY\_VAR\_1`, `my\_var`, `my\_var\_1`, `myVar`, `My\_Var123`, while these are instead not valid: `1\_VAR`, `'my-var'`, `"my var"`, `VAR\_#1`. #### Variable Values Variable values are comprised by any arbitrary text, which can optionally be wrapped inside single (`'`) or double (`"`) quotes. Quoted variables can span across multiple lines, while non quoted ones are restricted to a single line. Noting that when parsed by Node.js all values are interpreted as text, meaning that any value will result in a JavaScript string inside Node.js. For example the following values: `0`, `true` and `{ "hello": "world" }` will result in the literal strings `'0'`, `'true'` and `'{ "hello": "world" }'` instead of the number zero, the boolean `true` and an object with the `hello` property respectively. Examples of valid variables: ```text MY\_SIMPLE\_VAR = a simple single line variable MY\_EQUALS\_VAR = "this variable contains an = sign!" MY\_HASH\_VAR = 'this variable contains a # symbol!' MY\_MULTILINE\_VAR = ' this is a multiline variable containing two separate lines\nSorry, I meant three lines' ``` #### Spacing Leading and trailing whitespace characters around variable keys and values are ignored unless they are enclosed within quotes. For example: ```text MY\_VAR\_A = my variable a MY\_VAR\_B = ' my variable b ' ``` will be treated identically to: ```text MY\_VAR\_A = my variable a MY\_VAR\_B = ' my variable b ' ``` #### Comments Hash-tag (`#`) characters denote the beginning of a comment, meaning that the rest of the line will be completely ignored. Hash-tags found within quotes are however treated as any other standard character. For example: ```text # This is a comment MY\_VAR = my
|
https://github.com/nodejs/node/blob/main//doc/api/environment_variables.md
|
main
|
nodejs
|
[
-0.030412472784519196,
-0.02564319036900997,
-0.003879845142364502,
-0.005857291165739298,
0.07391341775655746,
-0.05983993411064148,
0.022660592570900917,
0.04732348024845123,
0.0026806399691849947,
-0.010775637812912464,
-0.08137821406126022,
0.05339621379971504,
0.038273122161626816,
-0.033689770847558975,
0.07105857133865356,
0.06393257528543472,
-0.0028999969363212585,
0.014239047653973103,
-0.024004260078072548,
0.0001982175890589133,
0.03210531920194626,
0.05278453603386879,
-0.0062577687203884125,
-0.005912112072110176,
-0.03377746418118477,
0.005052865948528051,
-0.007830298505723476,
0.05670887231826782,
0.010349469259381294,
-0.0032221509609371424,
0.033881645649671555,
0.05222874507308006,
-0.01714637503027916,
-0.01745065674185753,
-0.027134153991937637,
0.1816055029630661,
0.015952717512845993,
-0.09412730485200882,
-0.044215429574251175,
-0.04100172594189644,
0.02380634844303131,
0.08475296199321747,
-0.10699353367090225,
-0.10773485153913498,
0.05038534104824066,
-0.008447185158729553,
-0.10424885153770447,
-0.053739968687295914,
-0.11741197854280472,
-0.030763637274503708,
0.035079825669527054,
-0.08123648166656494,
-0.04285017400979996,
-0.06836266070604324,
0.011975026689469814,
-0.010802178643643856,
-0.009569749236106873,
0.018896982073783875,
0.03261476010084152,
0.06475985050201416,
-0.007547383196651936,
0.020972196012735367,
0.03524353355169296,
0.05499957501888275,
0.0627254769206047,
-0.027331078425049782,
-0.05278339236974716,
0.0675104632973671,
0.011677373200654984,
-0.06670019775629044,
-0.04473777487874031,
0.05117420479655266,
-0.08718369901180267,
-0.06551623344421387,
-0.07299810647964478,
-0.06256824731826782,
0.0009754252969287336,
-0.0006227662088349462,
-0.012364339083433151,
-0.010410250164568424,
-0.0436754934489727,
-0.009575595147907734,
-0.02970411628484726,
0.07445681095123291,
-0.060896385461091995,
0.053766947239637375,
0.02137777768075466,
-0.023004131391644478,
0.09077371656894684,
0.07337646931409836,
-0.062344811856746674,
-0.09372493624687195,
0.0299778301268816,
0.03837064281105995,
0.07585971057415009,
0.08557908982038498,
0.026017971336841583,
0.010564344003796577,
0.029257789254188538,
-0.000051269893447170034,
-0.005507569760084152,
-0.025965644046664238,
0.05429978296160698,
-0.013535050675272942,
0.03828980028629303,
-0.030253419652581215,
0.04523270204663277,
-0.00157585006672889,
-0.01817350648343563,
-0.0016984449466690421,
-0.025994746014475822,
0.022040434181690216,
0.03053622879087925,
-0.045754481106996536,
0.003521508304402232,
-0.024313105270266533,
0.11776329576969147,
-0.02837035432457924,
0.11233528703451157,
0.11951824277639389,
0.10129697620868683,
0.0030133307445794344,
-0.0026913487818092108,
0.0202332790941,
0.06309641152620316,
-0.009013642556965351,
0.042796969413757324,
2.9902895695339303e-33,
-0.01838780753314495,
-0.11624018102884293,
0.024492722004652023,
0.09641004353761673,
0.0357489176094532,
0.04036225751042366,
0.030453814193606377,
-0.0222356878221035,
-0.09459284693002701,
-0.03244757279753685,
0.0056614382192492485,
0.10277936607599258,
0.019880706444382668,
0.03964802250266075,
0.0004900460480712354,
0.013311653397977352,
0.020588967949151993,
0.060793112963438034,
0.038079194724559784,
-0.018770994618535042,
-0.006521380040794611,
0.000144860619911924,
-0.048278626054525375,
0.11652057617902756,
0.0575028695166111,
-0.07237841188907623,
0.009263052605092525,
-0.018873952329158783,
0.014362144283950329,
-0.04689602181315422,
0.0769888237118721,
0.029339013621211052,
0.029709467664361,
0.06931157410144806,
0.0038424646481871605,
-0.0017009304137900472,
0.022790877148509026,
0.05856822431087494,
-0.1003490686416626,
-0.011227171868085861,
0.05425751954317093,
0.055961716920137405,
-0.03432682529091835,
0.0023313453420996666,
-0.07675471156835556,
-0.09524020552635193,
-0.007301135919988155,
-0.011168420314788818,
-0.01835421286523342,
-0.040904413908720016,
-0.06922256201505661,
0.06457884609699249,
0.06554357707500458,
-0.05197365581989288,
0.021984726190567017,
0.01971503347158432,
0.027801530435681343,
-0.12576790153980255,
-0.10562991350889206,
-0.03186231479048729,
0.0388655811548233,
0.04849886894226074,
0.015837421640753746,
-0.021037787199020386,
0.0438908115029335,
-0.03736278414726257,
0.02765115723013878,
-0.020462365821003914,
0.020695289596915245,
0.03617534786462784,
-0.09110996872186661,
0.04566129669547081,
0.002465409692376852,
0.0017554895021021366,
0.041905369609594345,
-0.0034289280883967876,
-0.06136491894721985,
-0.029324164614081383,
-0.02533572167158127,
-0.05187274515628815,
-0.02270779199898243,
-0.018927808851003647,
-0.045704685151576996,
0.07205412536859512,
0.05143164098262787,
0.007278084754943848,
-0.08754263818264008,
-0.007599587086588144,
0.05751824378967285,
-0.04465445503592491,
0.09272883087396622,
-0.03773076832294464,
-0.020520001649856567,
-0.05742136389017105,
-0.10002145916223526,
-5.7709499254078604e-33,
-0.013865193352103233,
0.005717273335903883,
-0.06944540143013,
0.04992334917187691,
-0.045800238847732544,
0.00883626937866211,
-0.03571988269686699,
-0.046155497431755066,
0.00947451964020729,
-0.030147848650813103,
-0.09550555050373077,
0.06261921674013138,
0.04573220759630203,
0.0626232773065567,
-0.025798842310905457,
0.05346228927373886,
-0.0703369677066803,
-0.007888872176408768,
0.04952911660075188,
-0.032130494713783264,
-0.03666536509990692,
0.019548483192920685,
0.10472995042800903,
-0.007079302798956633,
-0.015098320320248604,
-0.04825722798705101,
-0.03278633579611778,
-0.0185968279838562,
-0.025666847825050354,
-0.011676820926368237,
-0.07126593589782715,
-0.0004902465152554214,
-0.05178898572921753,
0.0746324434876442,
-0.044407911598682404,
-0.08021069318056107,
-0.032753825187683105,
-0.029993874952197075,
0.05594903975725174,
-0.046136487275362015,
0.027783237397670746,
-0.00330176018178463,
-0.0022379097063094378,
-0.04722825065255165,
-0.0011270538670942187,
0.07525520026683807,
-0.023741064593195915,
0.04003017768263817,
-0.019721750169992447,
-0.08937136083841324,
-0.011286252178251743,
-0.02110762894153595,
-0.005296884570270777,
0.03914153575897217,
-0.019786253571510315,
-0.08977869153022766,
-0.03207801282405853,
0.014049298129975796,
0.013820748776197433,
0.00009273862087866291,
0.08855630457401276,
-0.05529395863413811,
-0.03641418740153313,
0.006126211024820805,
-0.1379566192626953,
-0.0029589037876576185,
-0.11703549325466156,
-0.012785167433321476,
0.015758950263261795,
-0.10377102345228195,
0.028389712795615196,
-0.04095233231782913,
-0.02647116407752037,
-0.019636059179902077,
-0.020314712077379227,
-0.01835787296295166,
0.03951258584856987,
-0.1472485214471817,
-0.008970221504569054,
0.03525596857070923,
-0.02725977450609207,
0.1003422960639,
-0.06517669558525085,
-0.0016432682750746608,
-0.00607727188616991,
0.008566061034798622,
-0.03509700670838356,
0.07310212403535843,
-0.008021010085940361,
0.018051279708743095,
0.019034506753087044,
0.05967560037970543,
-0.1007932797074318,
0.019272953271865845,
-0.09255616366863251,
-4.675019482647258e-8,
-0.01815726049244404,
0.0001850245607784018,
-0.09758441150188446,
0.008171684108674526,
-0.09682018309831619,
0.024714477360248566,
0.08445577323436737,
0.04640374705195427,
0.09265981614589691,
0.086927130818367,
0.0006141485646367073,
-0.018580447882413864,
0.04173392057418823,
0.00026153441285714507,
-0.008253650739789009,
0.08813843876123428,
0.029439466074109077,
0.07334023714065552,
-0.0003568374668247998,
-0.026460250839591026,
0.05806273594498634,
0.028238989412784576,
-0.04785094037652016,
0.08770232647657394,
0.03304683789610863,
-0.04754674807190895,
0.004732036497443914,
0.02567245066165924,
0.013274619355797768,
-0.06127592548727989,
-0.024651631712913513,
0.031281545758247375,
0.04403752461075783,
-0.0210870411247015,
-0.0023068608716130257,
0.04086969420313835,
-0.03103926219046116,
-0.008740321733057499,
0.048414260149002075,
0.07151103019714355,
-0.006764082703739405,
0.032864440232515335,
-0.04996180161833763,
-0.005271293222904205,
-0.05945787951350212,
-0.02019866742193699,
0.018162766471505165,
-0.005086879711598158,
-0.028548464179039,
-0.010384170338511467,
0.044702041894197464,
-0.011897698044776917,
-0.018400272354483604,
0.041191551834344864,
0.017032098025083542,
0.057740718126297,
0.02964072860777378,
-0.08380704373121262,
0.010472902096807957,
0.011443342082202435,
-0.07097427546977997,
0.052443042397499084,
0.0150049002841115,
-0.028644630685448647
] | 0.122455
|
my variable b ' ``` #### Comments Hash-tag (`#`) characters denote the beginning of a comment, meaning that the rest of the line will be completely ignored. Hash-tags found within quotes are however treated as any other standard character. For example: ```text # This is a comment MY\_VAR = my variable # This is also a comment MY\_VAR\_A = "# this is NOT a comment" ``` #### `export` prefixes The `export` keyword can optionally be added in front of variable declarations, such keyword will be completely ignored by all processing done on the file. This is useful so that the file can be sourced, without modifications, in shell terminals. Example: ```text export MY\_VAR = my variable ``` ### CLI Options `.env` files can be used to populate the `process.env` object via one the following CLI options: \* [`--env-file=file`][] \* [`--env-file-if-exists=file`][] ### Programmatic APIs There following two functions allow you to directly interact with `.env` files: \* [`process.loadEnvFile`][] loads an `.env` file and populates `process.env` with its variables \* [`util.parseEnv`][] parses the row content of an `.env` file and returns its value in an object [CLI Environment Variables documentation]: cli.md#environment-variables\_1 [`--env-file-if-exists=file`]: cli.md#--env-file-if-existsfile [`--env-file=file`]: cli.md#--env-filefile [`process.env` documentation]: process.md#processenv [`process.loadEnvFile`]: process.md#processloadenvfilepath [`util.parseEnv`]: util.md#utilparseenvcontent [dotenv]: https://github.com/motdotla/dotenv
|
https://github.com/nodejs/node/blob/main//doc/api/environment_variables.md
|
main
|
nodejs
|
[
-0.06446859240531921,
0.002104638610035181,
-0.006805269978940487,
0.027829362079501152,
0.008773407898843288,
-0.03385654091835022,
0.0831775888800621,
0.011295502074062824,
0.020526478067040443,
0.03400496393442154,
-0.026910144835710526,
0.031221896409988403,
0.08481091260910034,
-0.016609374433755875,
0.0531957782804966,
0.0930224359035492,
-0.009432901628315449,
-0.04229776933789253,
-0.08509684354066849,
-0.08433175086975098,
0.05435048043727875,
0.06911280006170273,
0.010256798006594181,
0.06008094176650047,
0.028255227953195572,
0.014171469025313854,
0.0004564773116726428,
0.06879164278507233,
-0.010399208404123783,
0.02764703705906868,
-0.021712863817811012,
0.08484254777431488,
-0.06825680285692215,
-0.006899240892380476,
0.047472499310970306,
0.14246664941310883,
0.005005924962460995,
0.01416134275496006,
0.014702021144330502,
-0.06113569438457489,
-0.030695272609591484,
0.0740770772099495,
-0.1093684509396553,
-0.011435090564191341,
-0.006308596581220627,
0.01459991093724966,
0.006843162700533867,
-0.01241457648575306,
-0.11465242505073547,
-0.05991259217262268,
-0.0067875562235713005,
-0.06748353689908981,
-0.005720754154026508,
-0.031185945495963097,
0.02418890781700611,
-0.046487510204315186,
-0.029678259044885635,
-0.023097392171621323,
0.03351200744509697,
0.004725584760308266,
-0.06357158720493317,
0.04976583272218704,
-0.0072382669895887375,
-0.0008070573676377535,
0.006941932253539562,
-0.017120346426963806,
-0.056888334453105927,
0.07024450600147247,
-0.04269425570964813,
0.056895531713962555,
-0.10389725118875504,
0.013223914429545403,
-0.09618522971868515,
-0.017433976754546165,
0.009921178221702576,
0.05342746153473854,
0.021641835570335388,
-0.0030602840706706047,
-0.008352142758667469,
-0.06086608022451401,
-0.09975308924913406,
-0.07332097738981247,
-0.012113065458834171,
0.00956642720848322,
-0.008740405552089214,
-0.04118911549448967,
0.05244780704379082,
0.004849928896874189,
0.04261965677142143,
0.006663760636001825,
-0.09512504935264587,
-0.13299399614334106,
0.07838352769613266,
-0.0045938640832901,
0.08120855689048767,
0.07400108128786087,
0.02081887610256672,
0.02868345007300377,
0.05511854588985443,
0.03786849230527878,
0.008392923511564732,
0.04302527755498886,
0.05928880348801613,
-0.04645255580544472,
0.02748539298772812,
0.038138583302497864,
0.05036138743162155,
-0.026507748290896416,
-0.001317710499279201,
-0.0213328767567873,
0.005708268843591213,
0.042330142110586166,
0.008744769729673862,
-0.04644504562020302,
0.023338187485933304,
0.0047376686707139015,
0.06740833818912506,
-0.02595374919474125,
0.049807142466306686,
0.04703625291585922,
0.04917136952280998,
-0.04388212040066719,
-0.0051034060306847095,
0.08278518915176392,
0.009376076981425285,
0.017093876376748085,
-0.0050567262805998325,
4.924519422392933e-33,
-0.029174992814660072,
-0.08160458505153656,
-0.025451771914958954,
0.031371038407087326,
-0.02141355350613594,
0.09078136086463928,
0.05577465519309044,
-0.03265909478068352,
0.0006830300553701818,
0.02886679396033287,
-0.024633435532450676,
-0.027365829795598984,
0.001882961019873619,
0.018123043701052666,
-0.015323786996304989,
0.06512173265218735,
0.042695287615060806,
-0.010199231095612049,
0.03634228929877281,
-0.001767804380506277,
0.038626838475465775,
0.0016290507046505809,
-0.09472823888063431,
0.011464327573776245,
0.014627289026975632,
-0.0849226638674736,
0.0004433998838067055,
-0.13986562192440033,
0.030819294974207878,
-0.03228460252285004,
0.03801786154508591,
-0.02207213267683983,
0.11603645235300064,
0.06504877656698227,
-0.01507081650197506,
-0.07232540100812912,
-0.03055497631430626,
0.015291881747543812,
-0.03810544312000275,
-0.016597231850028038,
0.08129392564296722,
0.03391382470726967,
-0.038597363978624344,
0.037423450499773026,
-0.04453621059656143,
-0.018033301457762718,
-0.05788056552410126,
-0.01310331467539072,
-0.03786981478333473,
-0.031524159014225006,
0.003460825188085437,
0.12384958565235138,
0.059934064745903015,
-0.07576156407594681,
-0.008425068110227585,
-0.09568512439727783,
0.029851511120796204,
-0.14720885455608368,
-0.08572743088006973,
-0.0698200911283493,
-0.0455213338136673,
0.044116538017988205,
0.039789725095033646,
0.009408867917954922,
0.08765773475170135,
-0.07547123730182648,
0.09503565728664398,
0.08977226167917252,
-0.03050042688846588,
-0.01947498507797718,
-0.08379538357257843,
0.028978928923606873,
-0.020504135638475418,
-0.027060408145189285,
0.032108061015605927,
-0.017274433746933937,
-0.04273518547415733,
-0.015323936007916927,
0.0553392618894577,
-0.06717932224273682,
-0.0144844064489007,
0.011949902400374413,
-0.08526097238063812,
0.043744586408138275,
-0.010836350731551647,
-0.016005046665668488,
-0.07063198834657669,
-0.0936637669801712,
0.0119495689868927,
-0.07119384407997131,
0.013772021047770977,
-0.029823308810591698,
-0.051624130457639694,
-0.0769425556063652,
-0.09919312596321106,
-7.441740290317057e-33,
0.08368203043937683,
0.01905776560306549,
0.007858858443796635,
0.038711730390787125,
-0.06925360858440399,
0.024460632354021072,
0.09540841728448868,
-0.031477026641368866,
0.029672930017113686,
-0.05589842423796654,
-0.09463697671890259,
0.02989809401333332,
-0.01450318656861782,
0.005290275905281305,
0.06445001065731049,
0.006380308885127306,
-0.09613578766584396,
0.02274661511182785,
0.055373385548591614,
-0.015205631963908672,
-0.03294326737523079,
-0.030968323349952698,
0.09353070706129074,
0.0677863359451294,
0.04091137647628784,
-0.03536103665828705,
0.023653576150536537,
0.028957409784197807,
0.0020586038008332253,
0.003755013458430767,
-0.0524272583425045,
0.09911884367465973,
-0.06105315312743187,
-0.03683595359325409,
-0.11950480192899704,
-0.08857739716768265,
-0.05864029377698898,
0.031098661944270134,
0.05801115185022354,
0.0476839542388916,
0.042111173272132874,
0.07958200573921204,
-0.012893511913716793,
0.021917637437582016,
-0.04880884289741516,
0.04367624595761299,
-0.0013281202409416437,
0.018379049375653267,
-0.021232370287179947,
-0.056161604821681976,
0.060441892594099045,
-0.04804069176316261,
-0.04776125028729439,
0.00016997470811475068,
0.03056788444519043,
-0.05780293792486191,
-0.05426609516143799,
-0.05584784224629402,
-0.09687928855419159,
-0.01912781037390232,
0.03093542903661728,
-0.005019774194806814,
0.025869809091091156,
-0.04076690226793289,
-0.11530912667512894,
-0.03636825457215309,
-0.04907215014100075,
-0.001366840791888535,
0.044415730983018875,
-0.039879076182842255,
0.07738024741411209,
-0.06746381521224976,
-0.055512212216854095,
0.02793877385556698,
0.0289058405905962,
0.06179168075323105,
0.08207778632640839,
-0.05863749980926514,
0.021161077544093132,
0.06532132625579834,
0.009192954748868942,
0.04313350468873978,
-0.05846976116299629,
0.0033671297132968903,
0.06874550879001617,
-0.08159381151199341,
-0.07071582227945328,
0.10512876510620117,
0.014039669185876846,
0.016834288835525513,
0.038206182420253754,
0.013188019394874573,
0.0025867566000670195,
-0.0016440593171864748,
-0.026909662410616875,
-4.983426649118883e-8,
-0.0228160060942173,
-0.025498272851109505,
-0.04984014853835106,
-0.004568065050989389,
-0.0635237842798233,
0.050186675041913986,
0.008833898231387138,
-0.04976608231663704,
0.0022691863123327494,
0.022834256291389465,
0.04393820837140083,
-0.044777657836675644,
-0.026713527739048004,
0.0025155539624392986,
-0.10832908004522324,
0.07708219438791275,
0.03431086242198944,
0.044877346605062485,
-0.001224754611030221,
-0.02102869749069214,
-0.04388514533638954,
0.052827466279268265,
-0.08607947826385498,
0.01741534098982811,
0.08734338730573654,
0.017973093315958977,
-0.030010899528861046,
0.042481835931539536,
-0.01606753282248974,
-0.026391971856355667,
0.0929139032959938,
0.045122887939214706,
0.02009093016386032,
-0.09238743782043457,
-0.03413952514529228,
0.0018747574649751186,
0.06156395003199577,
0.013607347384095192,
0.040641602128744125,
0.008915593847632408,
-0.04429549723863602,
0.02750464528799057,
-0.08747967332601547,
-0.003648645244538784,
-0.04666493460536003,
-0.04313572496175766,
-0.011018989607691765,
0.04929526522755623,
-0.026731276884675026,
0.003523486666381359,
0.06422216445207596,
0.01286415196955204,
0.022324543446302414,
0.043704308569431305,
0.009418371133506298,
0.036660704761743546,
0.08063824474811554,
-0.010239414870738983,
0.04553128406405449,
-0.008454667404294014,
0.02989763207733631,
-0.03870367631316185,
-0.007903320714831352,
-0.006674105767160654
] | -0.040302
|
# Modules: TypeScript > Stability: 2 - Stable ## Enabling There are two ways to enable runtime TypeScript support in Node.js: 1. For [full support][] of all of TypeScript's syntax and features, including using any version of TypeScript, use a third-party package. 2. For lightweight support, you can use the built-in support for [type stripping][]. ## Full TypeScript support To use TypeScript with full support for all TypeScript features, including `tsconfig.json`, you can use a third-party package. These instructions use [`tsx`][] as an example but there are many other similar libraries available. 1. Install the package as a development dependency using whatever package manager you're using for your project. For example, with `npm`: ```bash npm install --save-dev tsx ``` 2. Then you can run your TypeScript code via: ```bash npx tsx your-file.ts ``` Or alternatively, you can run with `node` via: ```bash node --import=tsx your-file.ts ``` ## Type stripping By default Node.js will execute TypeScript files that contains only erasable TypeScript syntax. Node.js will replace TypeScript syntax with whitespace, and no type checking is performed. To enable the transformation of non erasable TypeScript syntax, which requires JavaScript code generation, such as `enum` declarations, parameter properties use the flag [`--experimental-transform-types`][]. To disable this feature, use the flag [`--no-strip-types`][]. Node.js ignores `tsconfig.json` files and therefore features that depend on settings within `tsconfig.json`, such as paths or converting newer JavaScript syntax to older standards, are intentionally unsupported. To get full TypeScript support, see [Full TypeScript support][]. The type stripping feature is designed to be lightweight. By intentionally not supporting syntaxes that require JavaScript code generation, and by replacing inline types with whitespace, Node.js can run TypeScript code without the need for source maps. Type stripping is compatible with most versions of TypeScript but we recommend version 5.8 or newer with the following `tsconfig.json` settings: ```json { "compilerOptions": { "noEmit": true, // Optional - see note below "target": "esnext", "module": "nodenext", "rewriteRelativeImportExtensions": true, "erasableSyntaxOnly": true, "verbatimModuleSyntax": true } } ``` Use the `noEmit` option if you intend to only execute `\*.ts` files, for example a build script. You won't need this flag if you intend to distribute `\*.js` files. ### Determining module system Node.js supports both [CommonJS][] and [ES Modules][] syntax in TypeScript files. Node.js will not convert from one module system to another; if you want your code to run as an ES module, you must use `import` and `export` syntax, and if you want your code to run as CommonJS you must use `require` and `module.exports`. \* `.ts` files will have their module system determined [the same way as `.js` files.][] To use `import` and `export` syntax, add `"type": "module"` to the nearest parent `package.json`. \* `.mts` files will always be run as ES modules, similar to `.mjs` files. \* `.cts` files will always be run as CommonJS modules, similar to `.cjs` files. \* `.tsx` files are unsupported. As in JavaScript files, [file extensions are mandatory][] in `import` statements and `import()` expressions: `import './file.ts'`, not `import './file'`. Because of backward compatibility, file extensions are also mandatory in `require()` calls: `require('./file.ts')`, not `require('./file')`, similar to how the `.cjs` extension is mandatory in `require` calls in CommonJS files. The `tsconfig.json` option `allowImportingTsExtensions` will allow the TypeScript compiler `tsc` to type-check files with `import` specifiers that include the `.ts` extension. ### TypeScript features Since Node.js is only removing inline types, any TypeScript features that involve \_replacing\_ TypeScript syntax with new JavaScript syntax will error, unless the flag [`--experimental-transform-types`][] is passed. The most prominent features that require transformation are: \* `Enum` declarations \* `namespace` with runtime code \* legacy `module` with runtime code \* parameter properties
|
https://github.com/nodejs/node/blob/main//doc/api/typescript.md
|
main
|
nodejs
|
[
-0.0503762848675251,
-0.022519217804074287,
0.04245443269610405,
0.057039178907871246,
0.0018786946311593056,
0.03522789105772972,
0.022780917584896088,
0.08906993269920349,
-0.07892551273107529,
0.043421849608421326,
-0.11969243735074997,
0.08099853992462158,
-0.05950210615992546,
0.06414961069822311,
0.10676989704370499,
0.02440686896443367,
-0.0176924429833889,
0.026364946737885475,
0.04917630925774574,
-0.06725071370601654,
-0.003904142417013645,
-0.031558651477098465,
0.06485376507043839,
-0.015358085744082928,
-0.024283738806843758,
-0.02854003757238388,
0.00950577761977911,
-0.025724809616804123,
0.0645383670926094,
0.05256769806146622,
-0.09131421893835068,
0.01717977225780487,
-0.04403715208172798,
-0.004124940373003483,
-0.07269517332315445,
0.09271770715713501,
-0.016024461016058922,
0.02252141945064068,
-0.013566103763878345,
-0.07187662273645401,
0.06131378933787346,
0.1027960479259491,
-0.05047588795423508,
-0.08939868956804276,
-0.00011897993681486696,
-0.0848562940955162,
-0.0420406199991703,
-0.0296438280493021,
-0.05793348699808121,
0.00546645000576973,
-0.0030699691269546747,
0.004437256138771772,
-0.03066318854689598,
-0.045202743262052536,
0.04855150356888771,
-0.024298958480358124,
-0.06309191882610321,
0.017333798110485077,
0.01710348390042782,
-0.007281370926648378,
-0.00955128949135542,
0.0032373080030083656,
0.013021712191402912,
-0.06827592104673386,
0.04365928843617439,
0.09158767759799957,
-0.0443887896835804,
0.10751423239707947,
0.05494006350636482,
0.015849612653255463,
-0.04007457569241524,
-0.024135427549481392,
-0.015868356451392174,
0.011524416506290436,
-0.06913402676582336,
-0.0944945439696312,
0.028683597221970558,
-0.03322593867778778,
-0.021481331437826157,
0.08682338148355484,
-0.05088576674461365,
-0.03331631422042847,
0.02772752195596695,
0.1023559421300888,
-0.057499710470438004,
0.11119082570075989,
0.06904837489128113,
0.022471800446510315,
0.06565175950527191,
0.015128818340599537,
-0.03009863942861557,
-0.0048736329190433025,
0.06824091821908951,
-0.0226836409419775,
0.05687371641397476,
0.00986747071146965,
-0.040638767182826996,
0.05692429840564728,
-0.008723262697458267,
0.0024330869782716036,
-0.024405257776379585,
-0.011809870600700378,
0.0391504280269146,
0.020581698045134544,
-0.040174804627895355,
0.013644680380821228,
0.018305029720067978,
-0.09894204884767532,
0.02634369768202305,
0.03388369083404541,
-0.0008323648362420499,
0.06685657054185867,
-0.0237699244171381,
-0.06137606501579285,
-0.1402655839920044,
0.0025224315468221903,
-0.029308268800377846,
-0.048498962074518204,
0.09154035151004791,
0.12052267044782639,
0.05147638916969299,
0.018472114577889442,
-0.007531505078077316,
0.054695386439561844,
0.10032708942890167,
0.00077837985008955,
0.08926869928836823,
3.3503304485503425e-33,
-0.06610691547393799,
0.04799824580550194,
0.016046853736042976,
0.07122460752725601,
0.025962816551327705,
-0.006059687584638596,
0.027494097128510475,
-0.05952499806880951,
-0.1416519731283188,
0.03650841489434242,
-0.00540167884901166,
0.03761615976691246,
-0.09689374268054962,
0.012075116857886314,
0.023863641545176506,
-0.08137626200914383,
0.07191888242959976,
-0.03160689026117325,
0.06615318357944489,
0.04880720376968384,
0.029760323464870453,
0.06525107473134995,
0.00904789287596941,
0.11343115568161011,
0.01965879090130329,
-0.033234767615795135,
0.025790495797991753,
0.040556881576776505,
-0.023089246824383736,
-0.024177683517336845,
0.04162995144724846,
0.017537040635943413,
-0.023594781756401062,
0.031224463135004044,
0.013368803076446056,
-0.03937959671020508,
-0.09067139029502869,
0.03371332213282585,
-0.00790486391633749,
-0.009972860105335712,
-0.009741675108671188,
0.0607277937233448,
-0.06459523737430573,
0.03555614501237869,
0.004739102441817522,
-0.0605587363243103,
0.03374819457530975,
-0.035439152270555496,
0.0732608363032341,
-0.027303999289870262,
-0.05040976405143738,
0.08166764676570892,
-0.0029283694457262754,
-0.012742933817207813,
0.10326802730560303,
0.004679129458963871,
0.07088478654623032,
-0.030133523046970367,
0.07490455359220505,
0.007141838315874338,
0.04983854666352272,
-0.0744263157248497,
0.026620246469974518,
-0.032212600111961365,
0.05697504058480263,
-0.010864658281207085,
-0.06777819246053696,
-0.050292253494262695,
-0.0029290823731571436,
0.02055968903005123,
0.006639001425355673,
0.040531352162361145,
-0.05460793152451515,
0.07270042598247528,
0.029374226927757263,
0.047799210995435715,
-0.004116110038012266,
0.030253300443291664,
0.03318692743778229,
-0.050231367349624634,
-0.02248126082122326,
-0.0737062320113182,
0.0066991341300308704,
0.066824771463871,
0.09706121683120728,
-0.10130771994590759,
-0.07882137596607208,
0.03674592077732086,
0.0798315554857254,
-0.052757494151592255,
0.009615069255232811,
-0.02131391316652298,
-0.06506120413541794,
-0.053319890052080154,
-0.09733908623456955,
-4.195007260930637e-33,
-0.018584100529551506,
0.051386766135692596,
-0.11880455166101456,
0.05771118402481079,
-0.15176594257354736,
-0.09445063024759293,
-0.04482122138142586,
-0.03892166540026665,
0.061427172273397446,
0.05782638117671013,
-0.006895669735968113,
-0.03466600179672241,
0.077471062541008,
-0.020777592435479164,
-0.019287578761577606,
0.0338461734354496,
-0.06813942641019821,
-0.02981494925916195,
-0.01630931906402111,
-0.053866494446992874,
-0.050689637660980225,
-0.019986458122730255,
0.07474375516176224,
0.0231008380651474,
0.0006119742174632847,
0.02569662034511566,
0.03709699586033821,
0.06370586901903152,
-0.07041031122207642,
-0.041569504886865616,
-0.05270960181951523,
0.025920625776052475,
0.0017981213750317693,
0.012712710537016392,
-0.023709362372756004,
-0.05537467077374458,
0.046372391283512115,
0.06179105490446091,
0.055176977068185806,
-0.054908037185668945,
0.02901623770594597,
0.02195805311203003,
-0.027047989889979362,
-0.03842709958553314,
-0.007249949034303427,
-0.008976312354207039,
-0.028317227959632874,
0.059916041791439056,
0.009879432618618011,
-0.05567130073904991,
-0.027594462037086487,
-0.033541999757289886,
0.00006602652138099074,
-0.07301858812570572,
-0.004907357506453991,
-0.0634499117732048,
0.043571390211582184,
-0.04503675177693367,
-0.030684422701597214,
0.02831784263253212,
0.025585386902093887,
-0.09826231747865677,
0.060566917061805725,
0.002383379964157939,
-0.046434011310338974,
-0.09007426351308823,
-0.12082960456609726,
-0.058348994702100754,
0.015570126473903656,
0.05348151549696922,
-0.05080744996666908,
0.032213591039180756,
0.033975448459386826,
0.01490319799631834,
0.004446682054549456,
-0.004471353255212307,
0.07431842386722565,
0.028351856395602226,
0.07902792096138,
-0.0012129050446674228,
0.021782148629426956,
0.06364728510379791,
0.03230443224310875,
-0.016804877668619156,
-0.003442722372710705,
0.08136063069105148,
-0.014370682649314404,
0.013436415232717991,
0.053454142063856125,
0.029691556468605995,
-0.015114364214241505,
-0.013807518407702446,
-0.04171988368034363,
0.028955569490790367,
-0.01892811246216297,
-4.89160072447703e-8,
-0.035964418202638626,
-0.06041914224624634,
-0.14419232308864594,
-0.037541069090366364,
-0.02481841668486595,
-0.02520386129617691,
-0.01282741129398346,
-0.04549359530210495,
0.08388642221689224,
0.003534123068675399,
-0.020429551601409912,
-0.00040769847691990435,
-0.03355017676949501,
-0.02089293673634529,
0.046795804053545,
0.028018850833177567,
-0.02819916047155857,
0.05243730917572975,
-0.05001438781619072,
-0.021204516291618347,
-0.01904095523059368,
0.00706549733877182,
0.008948811329901218,
0.07460679858922958,
0.05012921616435051,
-0.0015191705897450447,
0.016562366858124733,
-0.00043459402513690293,
-0.019657030701637268,
0.006292634643614292,
-0.05307696387171745,
0.0014835626352578402,
-0.008015076629817486,
-0.02527451328933239,
0.016289208084344864,
-0.007445975672453642,
0.003992369864135981,
0.05743565410375595,
0.05007483437657356,
0.041156623512506485,
0.032438814640045166,
0.047868356108665466,
-0.06720311939716339,
0.006121697835624218,
-0.011629998683929443,
-0.009752573445439339,
0.0342429019510746,
0.0412643626332283,
0.04089844226837158,
-0.01662631891667843,
0.026272639632225037,
0.05058304965496063,
-0.09620757400989532,
0.034275565296411514,
-0.06433901190757751,
0.05373692885041237,
-0.0536087267100811,
0.010506358928978443,
-0.023783691227436066,
-0.08696175366640091,
-0.04242796450853348,
-0.05354895815253258,
0.047899942845106125,
-0.07860232144594193
] | 0.152274
|
is only removing inline types, any TypeScript features that involve \_replacing\_ TypeScript syntax with new JavaScript syntax will error, unless the flag [`--experimental-transform-types`][] is passed. The most prominent features that require transformation are: \* `Enum` declarations \* `namespace` with runtime code \* legacy `module` with runtime code \* parameter properties \* import aliases `namespaces` and `module` that do not contain runtime code are supported. This example will work correctly: ```ts // This namespace is exporting a type namespace TypeOnly { export type A = string; } ``` This will result in [`ERR\_UNSUPPORTED\_TYPESCRIPT\_SYNTAX`][] error: ```ts // This namespace is exporting a value namespace A { export let x = 1 } ``` Since Decorators are currently a [TC39 Stage 3 proposal](https://github.com/tc39/proposal-decorators), they are not transformed and will result in a parser error. Node.js does not provide polyfills and thus will not support decorators until they are supported natively in JavaScript. In addition, Node.js does not read `tsconfig.json` files and does not support features that depend on settings within `tsconfig.json`, such as paths or converting newer JavaScript syntax into older standards. ### Importing types without `type` keyword Due to the nature of type stripping, the `type` keyword is necessary to correctly strip type imports. Without the `type` keyword, Node.js will treat the import as a value import, which will result in a runtime error. The tsconfig option [`verbatimModuleSyntax`][] can be used to match this behavior. This example will work correctly: ```ts import type { Type1, Type2 } from './module.ts'; import { fn, type FnParams } from './fn.ts'; ``` This will result in a runtime error: ```ts import { Type1, Type2 } from './module.ts'; import { fn, FnParams } from './fn.ts'; ``` ### Non-file forms of input Type stripping can be enabled for `--eval` and STDIN. The module system will be determined by `--input-type`, as it is for JavaScript. TypeScript syntax is unsupported in the REPL, `--check`, and `inspect`. ### Source maps Since inline types are replaced by whitespace, source maps are unnecessary for correct line numbers in stack traces; and Node.js does not generate them. When [`--experimental-transform-types`][] is enabled, source-maps are enabled by default. ### Type stripping in dependencies To discourage package authors from publishing packages written in TypeScript, Node.js refuses to handle TypeScript files inside folders under a `node\_modules` path. ### Paths aliases [`tsconfig` "paths"][] won't be transformed and therefore produce an error. The closest feature available is [subpath imports][] with the limitation that they need to start with `#`. [CommonJS]: modules.md [ES Modules]: esm.md [Full TypeScript support]: #full-typescript-support [`--experimental-transform-types`]: cli.md#--experimental-transform-types [`--no-strip-types`]: cli.md#--no-strip-types [`ERR\_UNSUPPORTED\_TYPESCRIPT\_SYNTAX`]: errors.md#err\_unsupported\_typescript\_syntax [`tsconfig` "paths"]: https://www.typescriptlang.org/tsconfig/#paths [`tsx`]: https://tsx.is/ [`verbatimModuleSyntax`]: https://www.typescriptlang.org/tsconfig/#verbatimModuleSyntax [file extensions are mandatory]: esm.md#mandatory-file-extensions [full support]: #full-typescript-support [subpath imports]: packages.md#subpath-imports [the same way as `.js` files.]: packages.md#determining-module-system [type stripping]: #type-stripping
|
https://github.com/nodejs/node/blob/main//doc/api/typescript.md
|
main
|
nodejs
|
[
-0.08217310160398483,
-0.006726165767759085,
0.0681404322385788,
0.06074674427509308,
0.004071975592523813,
-0.0087755611166358,
-0.013309278525412083,
-0.020072992891073227,
-0.060610149055719376,
0.027640176936984062,
-0.06621474027633667,
0.015332761220633984,
-0.0506441630423069,
0.0449957475066185,
0.1407942920923233,
0.041258953511714935,
-0.027302375063300133,
0.027121948078274727,
-0.01258869469165802,
0.013138988986611366,
0.0281886737793684,
-0.030761457979679108,
-0.01135669182986021,
0.011778753250837326,
0.022289477288722992,
-0.044117365032434464,
-0.037670284509658813,
-0.036017682403326035,
0.030680587515234947,
-0.018202492967247963,
-0.07027395069599152,
0.047830309718847275,
-0.10342881083488464,
0.02779378555715084,
-0.023863449692726135,
0.07191773504018784,
-0.015175649896264076,
0.010064310394227505,
0.02615663781762123,
-0.08205467462539673,
0.06192658096551895,
0.10277757048606873,
-0.04937512055039406,
-0.08850308507680893,
0.019147159531712532,
-0.032671310007572174,
0.0002746439422480762,
-0.06858653575181961,
-0.13195012509822845,
-0.03578561171889305,
-0.0029487640131264925,
0.013240513391792774,
-0.0291566364467144,
-0.01771259866654873,
0.003635173197835684,
-0.03650006279349327,
-0.05661798641085625,
0.0041794790886342525,
0.07369580864906311,
0.03332540765404701,
-0.009155363775789738,
0.0266425721347332,
0.060295119881629944,
-0.03188764303922653,
-0.021625719964504242,
-0.010273194871842861,
-0.04826560989022255,
0.05731266736984253,
0.048924770206213,
0.014013274572789669,
-0.09911972284317017,
0.002197871683165431,
-0.04661251977086067,
0.016253391280770302,
0.015602338127791882,
-0.09806659072637558,
0.0011068807216361165,
0.06036694347858429,
0.012928865849971771,
0.007509784772992134,
-0.007698118221014738,
-0.037040453404188156,
-0.06058936193585396,
0.11332586407661438,
-0.003633705899119377,
0.09315836429595947,
-0.036737147718667984,
0.023889269679784775,
0.00261776614934206,
0.06366176158189774,
-0.058477602899074554,
-0.09056461602449417,
0.056400515139102936,
0.048328425735235214,
0.03899753838777542,
-0.02667194791138172,
-0.07729802280664444,
0.029268041253089905,
0.002090123714879155,
0.004107658751308918,
-0.05918118357658386,
0.03419363126158714,
0.05051097646355629,
-0.049348510801792145,
-0.0775454044342041,
-0.0193623173981905,
0.019501233473420143,
-0.06892256438732147,
0.00733961584046483,
0.04318830743432045,
0.004149123560637236,
0.05793576315045357,
-0.03028487041592598,
-0.0974164754152298,
-0.048940934240818024,
-0.004932836163789034,
-0.0015624972293153405,
-0.06322920322418213,
0.0708141177892685,
0.11087361723184586,
0.0997808575630188,
0.0020035752095282078,
0.06930287927389145,
0.0394255667924881,
0.0711384192109108,
0.057804059237241745,
0.02851487137377262,
1.9619964987933637e-33,
-0.0797509029507637,
0.015760188922286034,
-0.02693219669163227,
0.0893624797463417,
0.05834413319826126,
0.03535538166761398,
0.048425041139125824,
0.019549835473299026,
-0.07762879878282547,
-0.00572533393278718,
-0.013167032040655613,
0.035983406007289886,
-0.05601028352975845,
0.011575230397284031,
0.04049021005630493,
-0.030604010447859764,
0.10803014785051346,
-0.004796575754880905,
0.040713634341955185,
0.025439303368330002,
0.03164902701973915,
0.08491676300764084,
-0.03727345913648605,
0.04687504842877388,
-0.03387938439846039,
-0.0293950904160738,
0.00493658147752285,
-0.05546474829316139,
0.03625054657459259,
-0.023939190432429314,
-0.03097386658191681,
-0.011981111951172352,
0.00910138338804245,
0.02590249478816986,
0.056392569094896317,
-0.004147934261709452,
0.00388203258626163,
-0.009217964485287666,
-0.044142600148916245,
0.05940931662917137,
-0.06579098850488663,
0.07566247135400772,
-0.09956852346658707,
0.086316779255867,
0.0561283603310585,
-0.06197855621576309,
0.09175553172826767,
0.0364740751683712,
0.057330887764692307,
-0.031354501843452454,
-0.038056761026382446,
0.07311883568763733,
0.0449911504983902,
-0.024479283019900322,
0.08865439891815186,
0.02536219358444214,
0.09300391376018524,
-0.012061409652233124,
-0.013373205438256264,
-0.05031716823577881,
0.012345203198492527,
0.00021574922720901668,
0.008937850594520569,
-0.021312391385436058,
0.0796370878815651,
-0.01395212858915329,
-0.02083045244216919,
-0.0006638455670326948,
-0.06014757603406906,
0.0008658031583763659,
0.00529285566881299,
0.04119625315070152,
-0.15217405557632446,
0.08816099911928177,
0.06494543701410294,
0.00814799778163433,
-0.026124238967895508,
0.042356669902801514,
0.049110181629657745,
-0.06891060620546341,
-0.029012838378548622,
-0.003498493228107691,
0.023357415571808815,
0.06010996922850609,
0.05028193071484566,
-0.06600866466760635,
-0.02819802239537239,
0.013910706155002117,
0.12309306859970093,
-0.015183964744210243,
0.0839676707983017,
-0.04634401574730873,
-0.054724160581827164,
-0.04672979190945625,
-0.08806172013282776,
-4.296433688965384e-33,
-0.038983054459095,
0.05943246930837631,
-0.061406027525663376,
0.06997726857662201,
-0.1030166745185852,
-0.08793514221906662,
-0.025504915043711662,
0.016631167382001877,
0.07942167669534683,
0.010215315967798233,
-0.0028853225521743298,
-0.006482848897576332,
0.06777972728013992,
-0.039448875933885574,
0.003013723297044635,
0.009176615625619888,
-0.14011837542057037,
-0.06543256342411041,
-0.03960937261581421,
-0.04294024035334587,
0.03175527974963188,
0.045276157557964325,
0.0149497976526618,
0.05844828858971596,
-0.07107380032539368,
0.06017736345529556,
-0.06886356323957443,
0.08458191901445389,
0.004341034684330225,
-0.019014744088053703,
-0.01860673911869526,
0.0031350047793239355,
-0.019294457510113716,
0.044171031564474106,
-0.03175773844122887,
-0.06396516412496567,
-0.0007073465967550874,
0.07692614197731018,
0.008670979179441929,
-0.034939687699079514,
-0.0577378012239933,
0.006071583367884159,
-0.011740417219698429,
0.003321063704788685,
-0.011949541978538036,
-0.008648897521197796,
-0.05421853065490723,
0.054082948714494705,
0.06344453245401382,
0.007493100594729185,
0.004807661287486553,
-0.010038374923169613,
-0.07384336739778519,
-0.06859874725341797,
-0.022574909031391144,
-0.06842786818742752,
-0.017622385174036026,
-0.050514597445726395,
-0.029216492548584938,
0.03740428015589714,
0.046351730823516846,
-0.045498788356781006,
0.06215420365333557,
-0.0475321039557457,
-0.023482084274291992,
-0.05490243807435036,
-0.062379252165555954,
-0.012189328670501709,
0.026352250948548317,
-0.01381691824644804,
0.007350398693233728,
-0.020875219255685806,
-0.05267157033085823,
-0.025954242795705795,
-0.013970828615128994,
0.011906545609235764,
0.12226751446723938,
-0.01858646050095558,
0.06110402196645737,
0.014201108366250992,
-0.06424729526042938,
0.03859000653028488,
0.037634432315826416,
-0.0406746044754982,
-0.010363534092903137,
0.012770147994160652,
0.003775112796574831,
0.035750895738601685,
0.011813418939709663,
0.0007234428776428103,
0.020815769210457802,
-0.05922460928559303,
-0.0508948378264904,
0.013198649510741234,
-0.046385981142520905,
-5.4975508589905075e-8,
-0.06512633711099625,
-0.020623330026865005,
-0.14127177000045776,
-0.07219282537698746,
-0.12216374278068542,
-0.0577404610812664,
-0.012173186056315899,
-0.004905043635517359,
0.04745730385184288,
-0.009946728125214577,
-0.02363092079758644,
0.06912293285131454,
0.042168304324150085,
0.011150489561259747,
0.04266306385397911,
0.021927934139966965,
0.016931291669607162,
0.050398699939250946,
-0.07025737315416336,
-0.020308418199419975,
-0.0531940832734108,
0.015591430477797985,
-0.07888250797986984,
0.020069517195224762,
0.01379989180713892,
-0.04652659595012665,
0.003967000171542168,
0.041195083409547806,
0.03237605467438698,
0.0220458023250103,
-0.0659715011715889,
0.05496479198336601,
0.044304247945547104,
0.029322510585188866,
-0.012328705750405788,
0.0019610535819083452,
0.054737817496061325,
-0.02327265404164791,
0.031670376658439636,
0.04583864286541939,
0.02434896118938923,
0.018140539526939392,
-0.09407688677310944,
0.029879402369260788,
-0.03389448672533035,
-0.058083076030015945,
0.01819898746907711,
0.07469630241394043,
0.016182152554392815,
0.013715100474655628,
0.09341434389352798,
0.0671163946390152,
-0.09985612332820892,
-0.0020461895037442446,
-0.07259818911552429,
0.0550558865070343,
-0.053502146154642105,
0.016396893188357353,
-0.0027254971209913492,
-0.09028950333595276,
-0.005484077613800764,
-0.0742477998137474,
0.0850660428404808,
-0.06739653646945953
] | 0.080307
|
# Util > Stability: 2 - Stable The `node:util` module supports the needs of Node.js internal APIs. Many of the utilities are useful for application and module developers as well. To access it: ```mjs import util from 'node:util'; ``` ```cjs const util = require('node:util'); ``` ## `util.callbackify(original)` \* `original` {Function} An `async` function \* Returns: {Function} a callback style function Takes an `async` function (or a function that returns a `Promise`) and returns a function following the error-first callback style, i.e. taking an `(err, value) => ...` callback as the last argument. In the callback, the first argument will be the rejection reason (or `null` if the `Promise` resolved), and the second argument will be the resolved value. ```mjs import { callbackify } from 'node:util'; async function fn() { return 'hello world'; } const callbackFunction = callbackify(fn); callbackFunction((err, ret) => { if (err) throw err; console.log(ret); }); ``` ```cjs const { callbackify } = require('node:util'); async function fn() { return 'hello world'; } const callbackFunction = callbackify(fn); callbackFunction((err, ret) => { if (err) throw err; console.log(ret); }); ``` Will print: ```text hello world ``` The callback is executed asynchronously, and will have a limited stack trace. If the callback throws, the process will emit an [`'uncaughtException'`][] event, and if not handled will exit. Since `null` has a special meaning as the first argument to a callback, if a wrapped function rejects a `Promise` with a falsy value as a reason, the value is wrapped in an `Error` with the original value stored in a field named `reason`. ```js function fn() { return Promise.reject(null); } const callbackFunction = util.callbackify(fn); callbackFunction((err, ret) => { // When the Promise was rejected with `null` it is wrapped with an Error and // the original value is stored in `reason`. err && Object.hasOwn(err, 'reason') && err.reason === null; // true }); ``` ## `util.convertProcessSignalToExitCode(signalCode)` \* `signalCode` {string} A signal name (e.g., `'SIGTERM'`, `'SIGKILL'`). \* Returns: {number|null} The exit code, or `null` if the signal is invalid. The `util.convertProcessSignalToExitCode()` method converts a signal name to its corresponding POSIX exit code. Following the POSIX standard, the exit code for a process terminated by a signal is calculated as `128 + signal number`. ```mjs import { convertProcessSignalToExitCode } from 'node:util'; console.log(convertProcessSignalToExitCode('SIGTERM')); // 143 (128 + 15) console.log(convertProcessSignalToExitCode('SIGKILL')); // 137 (128 + 9) console.log(convertProcessSignalToExitCode('INVALID')); // null ``` ```cjs const { convertProcessSignalToExitCode } = require('node:util'); console.log(convertProcessSignalToExitCode('SIGTERM')); // 143 (128 + 15) console.log(convertProcessSignalToExitCode('SIGKILL')); // 137 (128 + 9) console.log(convertProcessSignalToExitCode('INVALID')); // null ``` This is particularly useful when working with processes to determine the exit code based on the signal that terminated the process. ## `util.debuglog(section[, callback])` \* `section` {string} A string identifying the portion of the application for which the `debuglog` function is being created. \* `callback` {Function} A callback invoked the first time the logging function is called with a function argument that is a more optimized logging function. \* Returns: {Function} The logging function The `util.debuglog()` method is used to create a function that conditionally writes debug messages to `stderr` based on the existence of the `NODE\_DEBUG` environment variable. If the `section` name appears within the value of that environment variable, then the returned function operates similar to [`console.error()`][]. If not, then the returned function is a no-op. ```mjs import { debuglog } from 'node:util'; const log = debuglog('foo'); log('hello from foo [%d]', 123); ``` ```cjs const { debuglog } = require('node:util'); const log = debuglog('foo'); log('hello from foo [%d]', 123); ``` If this program is run with `NODE\_DEBUG=foo` in the environment, then it will output something like: ```console FOO 3245: hello from foo [123] ``` where `3245` is
|
https://github.com/nodejs/node/blob/main//doc/api/util.md
|
main
|
nodejs
|
[
-0.1623135656118393,
0.025991573929786682,
0.0009367865277454257,
0.10116611421108246,
0.0015637228498235345,
-0.039341963827610016,
-0.03337523713707924,
0.06296228617429733,
0.05172570049762726,
-0.05702706798911095,
-0.057515423744916916,
0.051146410405635834,
0.007485106587409973,
-0.07491731643676758,
0.049541275948286057,
0.05002615228295326,
0.019041774794459343,
0.06586954742670059,
-0.033749088644981384,
-0.052560675889253616,
-0.002074203221127391,
-0.015048384666442871,
0.013494063168764114,
0.0038109130691736937,
-0.027921048924326897,
-0.06545598804950714,
-0.03509325534105301,
-0.018074406310915947,
0.04914388433098793,
-0.043276507407426834,
0.02725965343415737,
-0.003932987339794636,
-0.0762295350432396,
0.009980225935578346,
-0.098480723798275,
0.16997693479061127,
-0.04957480728626251,
-0.12042024731636047,
-0.04524337127804756,
-0.044979874044656754,
0.003938222769647837,
0.09355638176202774,
-0.039898790419101715,
-0.08108044415712357,
0.06127225235104561,
-0.03159839287400246,
-0.0494643859565258,
0.038770537823438644,
-0.07326170057058334,
0.02192639745771885,
0.031891580671072006,
0.02220475673675537,
-0.10629362612962723,
0.003249309491366148,
0.060925498604774475,
0.03094707615673542,
-0.008688878268003464,
0.03903263062238693,
0.005819386336952448,
0.05220961943268776,
0.03738677129149437,
-0.013906528241932392,
0.022373327985405922,
-0.009405813179910183,
0.09212841093540192,
-0.02320255897939205,
-0.057569872587919235,
-0.013487151823937893,
0.014135113917291164,
0.04324612021446228,
-0.0188758485019207,
-0.03491232544183731,
-0.03579922765493393,
0.015108025632798672,
-0.012711760587990284,
-0.040450818836688995,
0.012339274398982525,
0.009999645873904228,
-0.07173758745193481,
0.08533789962530136,
-0.010571291670203209,
-0.015824858099222183,
-0.05588424205780029,
-0.003020662348717451,
0.004524203948676586,
0.03914652392268181,
-0.01790931634604931,
0.029569024220108986,
0.032493457198143005,
0.04777538776397705,
-0.02910827472805977,
-0.031696051359176636,
-0.08946366608142853,
0.017469175159931183,
0.0070294709876179695,
0.002092244103550911,
0.02879899926483631,
0.01975010521709919,
-0.034208912402391434,
-0.004701040685176849,
-0.015082008205354214,
0.029602600261569023,
0.04603027179837227,
-0.007059588097035885,
0.07559332996606827,
-0.015251602977514267,
-0.02083972655236721,
-0.07053947448730469,
0.034985534846782684,
-0.01407379936426878,
-0.04937588796019554,
0.0041592796333134174,
-0.024519754573702812,
0.024208560585975647,
-0.0020482614636421204,
-0.014431030489504337,
0.07650364190340042,
-0.04982488602399826,
0.12078370153903961,
0.05697361007332802,
0.10928158462047577,
0.040786053985357285,
0.05275798961520195,
-0.038175251334905624,
0.04439519718289375,
-0.022823872044682503,
0.0191799383610487,
2.5272136719320675e-33,
-0.06190256029367447,
-0.04392535239458084,
0.014847841113805771,
0.08806023746728897,
0.04596881568431854,
-0.005284307524561882,
0.06333315372467041,
-0.07704254984855652,
-0.11557585000991821,
-0.05068517103791237,
0.015606007538735867,
0.05580425262451172,
0.016844332218170166,
-0.024283144623041153,
-0.009352602064609528,
-0.03731127828359604,
0.09411771595478058,
-0.06695383787155151,
0.05453938618302345,
0.030315754935145378,
0.002911573275923729,
0.01907890848815441,
0.026797179132699966,
0.020127853378653526,
0.0599571168422699,
-0.040842220187187195,
0.028866374865174294,
0.06892430782318115,
-0.014773019589483738,
-0.03128607198596001,
0.014318234287202358,
0.06925006955862045,
-0.02816036529839039,
0.002995056100189686,
0.005781060084700584,
-0.00864463672041893,
-0.06010313704609871,
-0.021570933982729912,
-0.08577238023281097,
-0.045991554856300354,
-0.07028540223836899,
0.1102057695388794,
-0.09445425122976303,
0.02714703232049942,
0.004937672987580299,
-0.10989957302808762,
-0.037109240889549255,
0.002292466349899769,
0.037155091762542725,
-0.026737291365861893,
-0.012590479105710983,
0.05410949885845184,
0.016442473977804184,
-0.03310852125287056,
0.03676142543554306,
0.021398739889264107,
0.02359972894191742,
-0.008881311863660812,
-0.08050114661455154,
0.016047900542616844,
0.10348553955554962,
-0.09042812883853912,
-0.0416368767619133,
-0.0155164310708642,
0.0007780744344927371,
0.04857797548174858,
-0.038925331085920334,
0.06427363306283951,
-0.013756091706454754,
0.030983449891209602,
0.025962932035326958,
0.026656653732061386,
-0.016513459384441376,
0.035734858363866806,
-0.018385840579867363,
0.01833508163690567,
-0.10331711173057556,
-0.07449506968259811,
-0.009121937677264214,
-0.06334549188613892,
0.028041109442710876,
-0.006365210749208927,
-0.07845168560743332,
0.12007296830415726,
0.04184616729617119,
0.014253050088882446,
-0.019671374931931496,
-0.004262994043529034,
0.0813116729259491,
0.03993405029177666,
-0.018332593142986298,
-0.026654697954654694,
0.03286951407790184,
-0.05215758457779884,
-0.11673465371131897,
-5.682056103862802e-33,
0.008342275395989418,
0.010828626342117786,
-0.09531627595424652,
0.12149053812026978,
-0.05571524053812027,
-0.0545821338891983,
-0.047202300280332565,
0.0030092319939285517,
-0.023656383156776428,
0.005872187204658985,
-0.06035121530294418,
0.0176902636885643,
0.06372582912445068,
0.03776799142360687,
0.0003487635694909841,
0.05999811366200447,
-0.0585954450070858,
-0.05165029317140579,
-0.02678346075117588,
-0.019519945606589317,
-0.026844345033168793,
0.02103838138282299,
0.012501384131610394,
0.01988246664404869,
-0.11176168918609619,
0.0143972709774971,
-0.07044203579425812,
-0.048420246690511703,
0.003969336394220591,
-0.07055199146270752,
-0.05022526904940605,
-0.027711303904652596,
-0.024856144562363625,
0.056528542190790176,
0.06321893632411957,
-0.0477638766169548,
0.02514667622745037,
0.036080893129110336,
0.011551382951438427,
-0.07638496160507202,
0.09644794464111328,
0.05048356577754021,
0.005011377856135368,
-0.0028480372857302427,
0.03772170841693878,
0.005545578431338072,
-0.03075735829770565,
0.08626793324947357,
-0.005365774966776371,
-0.03289330378174782,
-0.026459330692887306,
-0.06497526168823242,
-0.021981937810778618,
0.05082222819328308,
-0.081634022295475,
-0.03574070334434509,
0.04677112028002739,
0.01316552422940731,
0.09599443525075912,
0.0490829162299633,
-0.035727135837078094,
-0.11858319491147995,
0.00233664782717824,
-0.0447089709341526,
-0.05898666009306908,
0.04209776967763901,
-0.09086042642593384,
-0.043880216777324677,
0.11112568527460098,
0.029650811105966568,
0.036680884659290314,
0.019117793068289757,
0.018808072432875633,
0.005185963120311499,
-0.0268201045691967,
-0.012241908349096775,
-0.02391177974641323,
-0.15298882126808167,
0.05545850843191147,
0.05599811300635338,
-0.044681116938591,
0.0581970140337944,
0.01390992570668459,
0.03680286183953285,
-0.014430612325668335,
0.00328311906196177,
0.01947838068008423,
0.05182262882590294,
-0.007432837039232254,
-0.036282796412706375,
0.05940478295087814,
0.013575924560427666,
-0.1337711066007614,
0.003914170898497105,
-0.01255506370216608,
-5.688614024279559e-8,
-0.05138944461941719,
-0.01236372347921133,
-0.07982690632343292,
-0.012996410951018333,
-0.03076566569507122,
0.010218900628387928,
0.013685503974556923,
-0.06714651733636856,
0.07366477698087692,
0.01880909688770771,
-0.020238004624843597,
-0.057748906314373016,
0.026923540979623795,
-0.05956704542040825,
-0.034783415496349335,
0.09420549124479294,
0.014625275507569313,
0.03755414858460426,
0.007490265648812056,
-0.00636742589995265,
-0.05507349967956543,
0.022250665351748466,
-0.009326900355517864,
0.08396552503108978,
-0.006139904726296663,
-0.006451911758631468,
0.055637769401073456,
0.10630276799201965,
-0.06410441547632217,
-0.019487973302602768,
-0.040718819946050644,
0.032111529260873795,
0.05252131447196007,
0.021629825234413147,
-0.025720544159412384,
0.0040373592637479305,
0.03652841970324516,
-0.01260664127767086,
0.12215050309896469,
0.0619819238781929,
0.048304278403520584,
0.054981980472803116,
-0.048978399485349655,
0.0359780378639698,
-0.03689373657107353,
-0.016412047669291496,
0.022370006889104843,
-0.06468138098716736,
-0.04325955733656883,
0.020163634791970253,
0.07207993417978287,
-0.0858367308974266,
-0.032442498952150345,
0.015158242546021938,
0.005824023857712746,
-0.0020423319656401873,
-0.038559988141059875,
-0.05448051914572716,
0.004170313943177462,
-0.012296359986066818,
0.031782470643520355,
0.02421901747584343,
0.10065419226884842,
-0.03478885442018509
] | 0.155261
|
log('hello from foo [%d]', 123); ``` ```cjs const { debuglog } = require('node:util'); const log = debuglog('foo'); log('hello from foo [%d]', 123); ``` If this program is run with `NODE\_DEBUG=foo` in the environment, then it will output something like: ```console FOO 3245: hello from foo [123] ``` where `3245` is the process id. If it is not run with that environment variable set, then it will not print anything. The `section` supports wildcard also: ```mjs import { debuglog } from 'node:util'; const log = debuglog('foo-bar'); log('hi there, it\'s foo-bar [%d]', 2333); ``` ```cjs const { debuglog } = require('node:util'); const log = debuglog('foo-bar'); log('hi there, it\'s foo-bar [%d]', 2333); ``` if it is run with `NODE\_DEBUG=foo\*` in the environment, then it will output something like: ```console FOO-BAR 3257: hi there, it's foo-bar [2333] ``` Multiple comma-separated `section` names may be specified in the `NODE\_DEBUG` environment variable: `NODE\_DEBUG=fs,net,tls`. The optional `callback` argument can be used to replace the logging function with a different function that doesn't have any initialization or unnecessary wrapping. ```mjs import { debuglog } from 'node:util'; let log = debuglog('internals', (debug) => { // Replace with a logging function that optimizes out // testing if the section is enabled log = debug; }); ``` ```cjs const { debuglog } = require('node:util'); let log = debuglog('internals', (debug) => { // Replace with a logging function that optimizes out // testing if the section is enabled log = debug; }); ``` ### `debuglog().enabled` \* Type: {boolean} The `util.debuglog().enabled` getter is used to create a test that can be used in conditionals based on the existence of the `NODE\_DEBUG` environment variable. If the `section` name appears within the value of that environment variable, then the returned value will be `true`. If not, then the returned value will be `false`. ```mjs import { debuglog } from 'node:util'; const enabled = debuglog('foo').enabled; if (enabled) { console.log('hello from foo [%d]', 123); } ``` ```cjs const { debuglog } = require('node:util'); const enabled = debuglog('foo').enabled; if (enabled) { console.log('hello from foo [%d]', 123); } ``` If this program is run with `NODE\_DEBUG=foo` in the environment, then it will output something like: ```console hello from foo [123] ``` ## `util.debug(section)` Alias for `util.debuglog`. Usage allows for readability of that doesn't imply logging when only using `util.debuglog().enabled`. ## `util.deprecate(fn, msg[, code[, options]])` \* `fn` {Function} The function that is being deprecated. \* `msg` {string} A warning message to display when the deprecated function is invoked. \* `code` {string} A deprecation code. See the [list of deprecated APIs][] for a list of codes. \* `options` {Object} \* `modifyPrototype` {boolean} When false do not change the prototype of object while emitting the deprecation warning. \*\*Default:\*\* `true`. \* Returns: {Function} The deprecated function wrapped to emit a warning. The `util.deprecate()` method wraps `fn` (which may be a function or class) in such a way that it is marked as deprecated. ```mjs import { deprecate } from 'node:util'; export const obsoleteFunction = deprecate(() => { // Do something here. }, 'obsoleteFunction() is deprecated. Use newShinyFunction() instead.'); ``` ```cjs const { deprecate } = require('node:util'); exports.obsoleteFunction = deprecate(() => { // Do something here. }, 'obsoleteFunction() is deprecated. Use newShinyFunction() instead.'); ``` When called, `util.deprecate()` will return a function that will emit a `DeprecationWarning` using the [`'warning'`][] event. The warning will be emitted and printed to `stderr` the first time the returned function is called. After the warning is emitted, the wrapped function is called without emitting a warning. If the same optional `code` is supplied in multiple calls to `util.deprecate()`, the warning will be emitted only once for that `code`. ```mjs
|
https://github.com/nodejs/node/blob/main//doc/api/util.md
|
main
|
nodejs
|
[
0.013217546977102757,
0.04461444169282913,
0.07272181659936905,
0.015677187591791153,
0.051842834800481796,
-0.09169105440378189,
0.03183022141456604,
0.042473919689655304,
0.006566154304891825,
-0.026059474796056747,
-0.05688872188329697,
-0.037604622542858124,
0.012987079098820686,
0.003052324056625366,
0.04174886271357536,
0.026320461183786392,
-0.018487341701984406,
0.05690757557749748,
-0.029430028051137924,
-0.04907689616084099,
0.07100170105695724,
0.08246159553527832,
-0.019815580919384956,
0.023926345631480217,
-0.022460486739873886,
-0.0350128635764122,
0.002943583996966481,
0.014180856756865978,
0.03207334503531456,
0.014545350335538387,
0.09541798382997513,
0.01782604306936264,
-0.07327771931886673,
0.08919388055801392,
0.037782229483127594,
0.13238254189491272,
-0.010546407662332058,
-0.10886279493570328,
0.016590524464845657,
0.00581122562289238,
0.03876928240060806,
0.14426176249980927,
-0.09211605787277222,
-0.0034831215161830187,
0.06577978283166885,
-0.032348062843084335,
-0.14825613796710968,
0.0733618512749672,
-0.050357554107904434,
-0.0159024465829134,
-0.0088772838935256,
-0.020487302914261818,
-0.0052376845851540565,
-0.010691405273973942,
0.016058646142482758,
0.02061697095632553,
0.0035587733145803213,
0.005404291674494743,
0.06624789535999298,
0.009671882726252079,
-0.05059809610247612,
-0.0011269814567640424,
0.040641311556100845,
-0.04794352129101753,
0.0609716922044754,
-0.09256934374570847,
-0.05154968798160553,
0.10014065355062485,
0.026149485260248184,
0.04512571915984154,
-0.06943534314632416,
0.02144177258014679,
-0.04298774152994156,
-0.060504503548145294,
-0.02500145323574543,
-0.013505065813660622,
-0.0015803570859134197,
0.008345769718289375,
-0.03571481257677078,
-0.02528723143041134,
-0.03282646834850311,
-0.03305517137050629,
-0.010671302676200867,
0.014547865837812424,
-0.008067265152931213,
0.04099585488438606,
-0.030373239889740944,
0.01217764150351286,
0.03171485289931297,
0.0261925607919693,
-0.12426766008138657,
-0.16513437032699585,
-0.08895616233348846,
0.03113066777586937,
0.06117726489901543,
0.032968878746032715,
0.05425979569554329,
0.05057436227798462,
0.03477238491177559,
0.01958625391125679,
-0.01966925896704197,
0.05928948521614075,
0.07338212430477142,
-0.023124217987060547,
0.030295969918370247,
0.028573259711265564,
-0.03878536820411682,
-0.01831938698887825,
-0.013324200175702572,
-0.03462919220328331,
-0.024302057921886444,
0.0621100515127182,
0.033578429371118546,
0.04312654212117195,
0.05442863702774048,
-0.015338369645178318,
0.11758681386709213,
-0.0767374113202095,
0.03003319539129734,
0.06944984942674637,
0.07696981728076935,
-0.01422386895865202,
0.016305843368172646,
0.04920217767357826,
0.005795437842607498,
0.03168134763836861,
0.023247703909873962,
1.214335622909333e-33,
0.060989294201135635,
-0.08631831407546997,
-0.011209127493202686,
0.04076289385557175,
0.011512278579175472,
0.07636183500289917,
-0.039703454822301865,
0.008647737093269825,
-0.07358795404434204,
0.10278099030256271,
-0.09727798402309418,
0.035940442234277725,
0.020363960415124893,
-0.03267939016222954,
0.04057776555418968,
0.07976584881544113,
0.055866073817014694,
-0.029459737241268158,
-0.032171580940485,
0.062184106558561325,
-0.035178158432245255,
0.04210895672440529,
-0.0536469966173172,
-0.058785226196050644,
0.019029205664992332,
0.016131965443491936,
0.012212805449962616,
-0.05268625542521477,
-0.01472070999443531,
-0.013391658663749695,
-0.009478039108216763,
-0.015654850751161575,
0.04788241907954216,
0.035717468708753586,
0.06727411597967148,
0.024055814370512962,
-0.03526001423597336,
0.04134602099657059,
-0.1311602145433426,
-0.008989930152893066,
-0.04354649409651756,
0.032196998596191406,
-0.03617056459188461,
-0.0011146229226142168,
-0.027673542499542236,
-0.06005902960896492,
-0.08025126159191132,
-0.028840510174632072,
-0.024030204862356186,
-0.04412510246038437,
0.03950423747301102,
0.10138984769582748,
0.0005346788093447685,
-0.12104436755180359,
0.0473150908946991,
-0.07185697555541992,
0.061743371188640594,
-0.08610320091247559,
-0.02607942931354046,
0.0176805779337883,
0.05481982231140137,
0.04137123003602028,
-0.03985360264778137,
0.09556656330823898,
0.00579566927626729,
-0.027626313269138336,
0.021757595241069794,
0.10111860930919647,
0.05193208530545235,
0.031056784093379974,
-0.05567638576030731,
-0.035742878913879395,
-0.03445557504892349,
0.0025379247963428497,
0.009979959577322006,
0.036781877279281616,
-0.03420889377593994,
-0.01808774098753929,
-0.015481816604733467,
-0.025151783600449562,
0.06138640269637108,
-0.05412213131785393,
-0.0955907478928566,
0.01901213452219963,
0.013333369977772236,
0.0325864814221859,
-0.08647403120994568,
-0.037001773715019226,
-0.020428519695997238,
-0.008570091798901558,
-0.03239285573363304,
-0.04387052357196808,
-0.06409597396850586,
-0.08932629972696304,
-0.05260901898145676,
-4.8984212437527705e-33,
-0.0216961819678545,
0.07817015796899796,
-0.061258960515260696,
-0.02872081659734249,
-0.10207988321781158,
-0.07981971651315689,
0.040142133831977844,
-0.023515112698078156,
-0.01059578638523817,
0.011159809306263924,
-0.0644335150718689,
0.04954511672258377,
0.05542709305882454,
0.10008502751588821,
0.06245743855834007,
0.04386311024427414,
-0.135232612490654,
0.004515644162893295,
-0.0038488435093313456,
-0.03262491151690483,
0.027406083419919014,
0.019228756427764893,
0.04234980791807175,
0.02959391288459301,
-0.05073683336377144,
0.007759252097457647,
0.009658138267695904,
-0.018594590947031975,
-0.03529016673564911,
-0.06649600714445114,
0.0032166088931262493,
-0.003756557824090123,
-0.043713752180337906,
0.08995205909013748,
-0.025115542113780975,
-0.06554167717695236,
-0.06151500344276428,
0.04887425899505615,
0.04092830792069435,
-0.0590817891061306,
0.027918925508856773,
0.06076306104660034,
-0.0017400685464963317,
0.043257854878902435,
-0.03010556660592556,
0.0004917449550703168,
-0.00964299775660038,
0.0028704938013106585,
0.06572281569242477,
0.00344563159160316,
-0.025701725855469704,
-0.049422141164541245,
0.058490365743637085,
0.05519400164484978,
-0.05475273355841637,
-0.08530759811401367,
-0.058587223291397095,
0.013688203878700733,
-0.025955013930797577,
0.01917046681046486,
0.023670028895139694,
-0.016486264765262604,
0.001330205355770886,
-0.00829889066517353,
-0.07291010767221451,
-0.08303005993366241,
-0.07530514150857925,
-0.0057093133218586445,
0.05168134346604347,
-0.0993458479642868,
0.004943009931594133,
0.007851225323975086,
-0.09410359710454941,
0.05312013626098633,
-0.024117019027471542,
0.07173381000757217,
-0.055681198835372925,
-0.08322915434837341,
0.02406810224056244,
0.07385613769292831,
-0.03884100914001465,
0.027448022738099098,
-0.08275756239891052,
0.03227439895272255,
0.02849007584154606,
-0.07471221685409546,
-0.030282968655228615,
0.06251507252454758,
-0.009987701661884785,
-0.039433907717466354,
0.05788683146238327,
0.07582269608974457,
-0.1110401451587677,
-0.042156022042036057,
-0.028766710311174393,
-4.8479765979436706e-8,
-0.08074502646923065,
-0.017718378454446793,
-0.08223965018987656,
-0.014239897020161152,
0.012169676832854748,
0.018423384055495262,
0.016288315877318382,
-0.03909088671207428,
0.010778245516121387,
0.06188107654452324,
-0.05688698962330818,
-0.005366613622754812,
-0.04614092409610748,
-0.05847141519188881,
0.0012109262170270085,
-0.0022282840218394995,
-0.015213060192763805,
-0.04747043922543526,
-0.012033803388476372,
0.04460950195789337,
-0.010849894024431705,
0.02593746781349182,
-0.042774684727191925,
0.03517233952879906,
-0.055222272872924805,
-0.106643907725811,
0.058127034455537796,
0.03667294979095459,
-0.027182959020137787,
-0.015814270824193954,
0.014294306747615337,
0.1098618358373642,
-0.019725220277905464,
0.002284733345732093,
-0.04568355903029442,
0.0003425835457164794,
0.01514049805700779,
-0.02586650848388672,
0.0502006858587265,
0.023540467023849487,
0.011962201446294785,
0.0049840291030704975,
0.018317464739084244,
0.012282668612897396,
-0.1000489816069603,
-0.05914480984210968,
0.06534192711114883,
-0.03851654753088951,
0.06518977880477905,
0.07076548784971237,
0.022195179015398026,
-0.008518753573298454,
-0.032270293682813644,
0.04876987636089325,
0.010527189821004868,
-0.016702378168702126,
-0.00427069328725338,
-0.06053633615374565,
0.03526707738637924,
0.005810520611703396,
0.03893047571182251,
-0.0004152078181505203,
0.07786497473716736,
0.001999944681301713
] | 0.047192
|
emitted and printed to `stderr` the first time the returned function is called. After the warning is emitted, the wrapped function is called without emitting a warning. If the same optional `code` is supplied in multiple calls to `util.deprecate()`, the warning will be emitted only once for that `code`. ```mjs import { deprecate } from 'node:util'; const fn1 = deprecate( () => 'a value', 'deprecation message', 'DEP0001', ); const fn2 = deprecate( () => 'a different value', 'other dep message', 'DEP0001', ); fn1(); // Emits a deprecation warning with code DEP0001 fn2(); // Does not emit a deprecation warning because it has the same code ``` ```cjs const { deprecate } = require('node:util'); const fn1 = deprecate( function() { return 'a value'; }, 'deprecation message', 'DEP0001', ); const fn2 = deprecate( function() { return 'a different value'; }, 'other dep message', 'DEP0001', ); fn1(); // Emits a deprecation warning with code DEP0001 fn2(); // Does not emit a deprecation warning because it has the same code ``` If either the `--no-deprecation` or `--no-warnings` command-line flags are used, or if the `process.noDeprecation` property is set to `true` \_prior\_ to the first deprecation warning, the `util.deprecate()` method does nothing. If the `--trace-deprecation` or `--trace-warnings` command-line flags are set, or the `process.traceDeprecation` property is set to `true`, a warning and a stack trace are printed to `stderr` the first time the deprecated function is called. If the `--throw-deprecation` command-line flag is set, or the `process.throwDeprecation` property is set to `true`, then an exception will be thrown when the deprecated function is called. The `--throw-deprecation` command-line flag and `process.throwDeprecation` property take precedence over `--trace-deprecation` and `process.traceDeprecation`. ## `util.diff(actual, expected)` > Stability: 1 - Experimental \* `actual` {Array|string} The first value to compare \* `expected` {Array|string} The second value to compare \* Returns: {Array} An array of difference entries. Each entry is an array with two elements: \* `0` {number} Operation code: `-1` for delete, `0` for no-op/unchanged, `1` for insert \* `1` {string} The value associated with the operation \* Algorithm complexity: O(N\\*D), where: \* N is the total length of the two sequences combined (N = actual.length + expected.length) \* D is the edit distance (the minimum number of operations required to transform one sequence into the other). [`util.diff()`][] compares two string or array values and returns an array of difference entries. It uses the Myers diff algorithm to compute minimal differences, which is the same algorithm used internally by assertion error messages. If the values are equal, an empty array is returned. ```js const { diff } = require('node:util'); // Comparing strings const actualString = '12345678'; const expectedString = '12!!5!7!'; console.log(diff(actualString, expectedString)); // [ // [0, '1'], // [0, '2'], // [1, '3'], // [1, '4'], // [-1, '!'], // [-1, '!'], // [0, '5'], // [1, '6'], // [-1, '!'], // [0, '7'], // [1, '8'], // [-1, '!'], // ] // Comparing arrays const actualArray = ['1', '2', '3']; const expectedArray = ['1', '3', '4']; console.log(diff(actualArray, expectedArray)); // [ // [0, '1'], // [1, '2'], // [0, '3'], // [-1, '4'], // ] // Equal values return empty array console.log(diff('same', 'same')); // [] ``` ## `util.format(format[, ...args])` \* `format` {string} A `printf`-like format string. The `util.format()` method returns a formatted string using the first argument as a `printf`-like format string which can contain zero or more format specifiers. Each specifier is replaced with the converted value from the corresponding argument. Supported specifiers are: \* `%s`: `String` will be used to convert all values except `BigInt`, `Object` and `-0`. `BigInt` values will be represented with an `n` and Objects that have
|
https://github.com/nodejs/node/blob/main//doc/api/util.md
|
main
|
nodejs
|
[
-0.05823925882577896,
0.06742006540298462,
0.04863673448562622,
0.05136561393737793,
0.03312184289097786,
-0.03720744326710701,
0.01220780611038208,
0.0504755862057209,
0.06235704943537712,
-0.026806501671671867,
0.05575893446803093,
-0.004848867189139128,
0.011877881363034248,
-0.03910455107688904,
-0.012012348510324955,
-0.007508527487516403,
-0.08938364684581757,
0.02664763107895851,
-0.04191967472434044,
-0.09095180779695511,
0.056244879961013794,
0.021814418956637383,
-0.09042000770568848,
0.0486922562122345,
0.033926356583833694,
-0.050047703087329865,
-0.015346205793321133,
0.07451282441616058,
0.02893092855811119,
-0.0016345287440344691,
0.11030155420303345,
0.008018218912184238,
-0.06848986446857452,
0.10028552263975143,
-0.05285074561834335,
0.12935486435890198,
-0.08208493143320084,
-0.08843262493610382,
-0.0037668871227651834,
0.001092699239961803,
-0.025780878961086273,
0.09381745755672455,
-0.09148021787405014,
-0.017831342294812202,
0.024510806426405907,
-0.03693801909685135,
-0.07351034134626389,
0.024096380919218063,
-0.08274919539690018,
-0.03510952368378639,
0.08399393409490585,
0.057404108345508575,
-0.04463409259915352,
-0.032646358013153076,
0.06844598799943924,
-0.04406409338116646,
-0.05177485942840576,
0.00722422543913126,
-0.07010961323976517,
0.07539167255163193,
-0.042834002524614334,
-0.014739790931344032,
0.017477672547101974,
-0.040200550109148026,
0.0949285551905632,
-0.04651545733213425,
-0.0027805001009255648,
0.026451271027326584,
-0.01265355758368969,
0.20326118171215057,
-0.0469328910112381,
-0.03775273635983467,
-0.005199194885790348,
0.018128786236047745,
-0.010638036765158176,
0.036501750349998474,
-0.004372484516352415,
0.0033162320032715797,
-0.09328293055295944,
-0.03205355629324913,
-0.02683105133473873,
-0.023367205634713173,
-0.0028426693752408028,
-0.026604317128658295,
0.036836739629507065,
0.05948217213153839,
-0.005166954360902309,
-0.04407785087823868,
0.06333806365728378,
-0.020022207871079445,
-0.023834360763430595,
-0.06610765308141708,
-0.07253018021583557,
0.10879235714673996,
-0.042429208755493164,
-0.010779314674437046,
-0.023117071017622948,
0.030883103609085083,
-0.023770300671458244,
0.013292050920426846,
-0.06077629700303078,
-0.007201156113296747,
0.023876942694187164,
-0.05286003649234772,
0.03997648507356644,
-0.09645203500986099,
0.0010149116860702634,
-0.01960110478103161,
0.013569301925599575,
-0.04670469090342522,
0.003763366723433137,
0.06099289655685425,
0.028074998408555984,
-0.05365041643381119,
0.016988353803753853,
0.08942120522260666,
0.07588191330432892,
-0.0020254922565072775,
0.14615453779697418,
0.04009129852056503,
0.048309553414583206,
0.003669591387733817,
0.05280967801809311,
0.030637526884675026,
-0.02552426978945732,
-0.09019467234611511,
-0.0011799304047599435,
3.4323575463766756e-33,
-0.08064134418964386,
-0.07848111540079117,
-0.007455224636942148,
0.02792873978614807,
-0.03053608164191246,
0.007046715822070837,
-0.006215266417711973,
-0.01719982549548149,
-0.10280727595090866,
-0.03819449990987778,
0.0072136675007641315,
0.041331697255373,
-0.005538214463740587,
-0.01298731192946434,
0.05005890876054764,
-0.022920934483408928,
0.13183724880218506,
-0.032934483140707016,
0.08920832723379135,
0.015695156529545784,
0.0563555546104908,
-0.03801029175519943,
0.013473774306476116,
-0.0367509163916111,
0.04053710773587227,
-0.003909911960363388,
0.015698174014687538,
0.003749419003725052,
-0.036848776042461395,
-0.00956578180193901,
0.0013398979790508747,
0.04356810450553894,
0.0010174441849812865,
0.05022455379366875,
0.03985564410686493,
-0.04803604260087013,
-0.027151932939887047,
0.02262882888317108,
-0.045911118388175964,
-0.029527731239795685,
-0.008708531036973,
0.07549849152565002,
-0.022152436897158623,
0.0014926779549568892,
0.0680658146739006,
-0.06536929309368134,
0.005917063914239407,
0.04994937777519226,
0.06055695563554764,
-0.01977575570344925,
0.025896307080984116,
0.09269768744707108,
0.014212329871952534,
-0.006443261634558439,
0.004885105416178703,
-0.04648727923631668,
0.04851226881146431,
-0.09688317775726318,
-0.06772463023662567,
0.006582198198884726,
0.029915684834122658,
0.007387978490442038,
-0.08267631381750107,
-0.013228902593255043,
0.0385160967707634,
0.021484320983290672,
-0.012109721079468727,
0.0600581169128418,
0.020894229412078857,
-0.028630951419472694,
-0.06392581760883331,
-0.0019300176063552499,
0.009698108769953251,
-0.03711298108100891,
0.0006449614884331822,
0.002508559264242649,
-0.03124042972922325,
0.005208906717598438,
0.11453932523727417,
-0.10615327954292297,
-0.017939724028110504,
-0.025772670283913612,
-0.06047503277659416,
-0.00019907452224288136,
0.01785096898674965,
-0.023964902386069298,
-0.03887161612510681,
-0.06265184283256531,
0.005524416454136372,
0.1279718428850174,
-0.036846816539764404,
0.002229904755949974,
0.014362011104822159,
-0.04637354612350464,
-0.05011693388223648,
-5.932431257800164e-33,
-0.06363515555858612,
0.08464287966489792,
-0.0303974412381649,
0.09974344074726105,
-0.05680262669920921,
-0.008261972106993198,
-0.025010081008076668,
-0.022684460505843163,
-0.04014855995774269,
0.021091317757964134,
-0.00361651461571455,
-0.012941242195665836,
0.05497366562485695,
0.03691680729389191,
-0.039694689214229584,
0.07272718101739883,
-0.06498666107654572,
-0.026536185294389725,
-0.007313393987715244,
-0.044421855360269547,
0.03362822160124779,
0.1258152723312378,
0.05738016590476036,
-0.00027285245596431196,
-0.07285092771053314,
0.026084093376994133,
0.03832339867949486,
0.013187251053750515,
-0.012090262956917286,
-0.07963435351848602,
-0.03322722017765045,
0.04277133569121361,
0.03776352107524872,
0.04546734318137169,
0.024440698325634003,
-0.10928109288215637,
0.05224321410059929,
0.00437344703823328,
0.0038676063995808363,
0.014935358427464962,
0.06474065035581589,
0.0790264755487442,
-0.019387511536478996,
0.008574696257710457,
-0.011024138890206814,
-0.008393319323658943,
-0.008416933007538319,
0.03847956657409668,
0.07725466787815094,
-0.011609523557126522,
-0.006646447349339724,
-0.06851308792829514,
-0.0516672320663929,
0.004045179113745689,
-0.11839476972818375,
-0.08627986907958984,
-0.0026606351602822542,
0.013893329538404942,
0.024712417274713516,
0.07761545479297638,
0.030238917097449303,
-0.12691891193389893,
0.03678535670042038,
-0.044111523777246475,
0.0060304380021989346,
-0.052358031272888184,
-0.042554862797260284,
0.06825371086597443,
0.09101201593875885,
0.008333328180015087,
0.051186710596084595,
0.04189243167638779,
-0.08831939846277237,
-0.0773935541510582,
-0.08293317258358002,
0.011384403333067894,
-0.03496896103024483,
-0.10734491795301437,
0.006576720625162125,
0.022094685584306717,
-0.058926403522491455,
0.02601481042802334,
-0.020652450621128082,
0.056053418666124344,
-0.004887308459728956,
-0.018146585673093796,
-0.006322967819869518,
0.02446429617702961,
-0.011797034181654453,
0.028943665325641632,
0.019082680344581604,
0.04785817489027977,
-0.08241493254899979,
0.009014328941702843,
-0.04394296929240227,
-4.605005443636401e-8,
-0.07652561366558075,
-0.04438655823469162,
-0.07092410326004028,
-0.052157264202833176,
0.06098606809973717,
-0.06451774388551712,
0.0479983314871788,
-0.044620249420404434,
-0.00031977842445485294,
-0.022676365450024605,
-0.0009040774893946946,
0.032862257212400436,
-0.03416664898395538,
-0.05918538197875023,
-0.02416481263935566,
0.0013633116614073515,
-0.016381610184907913,
-0.040120549499988556,
-0.017243320122361183,
-0.005409312900155783,
-0.011188897304236889,
0.002783088479191065,
-0.024824362248182297,
0.041186053305864334,
-0.05781366303563118,
-0.06756366789340973,
0.07344672083854675,
0.08046415448188782,
0.026157498359680176,
-0.027286240831017494,
-0.03173751384019852,
0.05221270024776459,
0.10218838602304459,
0.019767852500081062,
-0.03717362508177757,
0.01761050522327423,
0.03274364769458771,
-0.0019169029546901584,
0.04472765326499939,
0.15495729446411133,
0.039730384945869446,
-0.017760591581463814,
-0.044612493366003036,
0.07413790374994278,
-0.04993170127272606,
-0.015306071378290653,
0.026220474392175674,
-0.04242819920182228,
-0.006843266077339649,
0.004841917660087347,
0.06161734089255333,
-0.00994193833321333,
-0.055245447903871536,
0.018108965829014778,
-0.05764065682888031,
-0.03926043212413788,
-0.051081396639347076,
0.017305606976151466,
-0.031096896156668663,
0.024161918088793755,
0.04740605130791664,
-0.02800583839416504,
0.07208506017923355,
-0.002046099863946438
] | 0.096212
|
which can contain zero or more format specifiers. Each specifier is replaced with the converted value from the corresponding argument. Supported specifiers are: \* `%s`: `String` will be used to convert all values except `BigInt`, `Object` and `-0`. `BigInt` values will be represented with an `n` and Objects that have neither a user defined `toString` function nor `Symbol.toPrimitive` function are inspected using `util.inspect()` with options `{ depth: 0, colors: false, compact: 3 }`. \* `%d`: `Number` will be used to convert all values except `BigInt` and `Symbol`. \* `%i`: `parseInt(value, 10)` is used for all values except `BigInt` and `Symbol`. \* `%f`: `parseFloat(value)` is used for all values expect `Symbol`. \* `%j`: JSON. Replaced with the string `'[Circular]'` if the argument contains circular references. \* `%o`: `Object`. A string representation of an object with generic JavaScript object formatting. Similar to `util.inspect()` with options `{ showHidden: true, showProxy: true }`. This will show the full object including non-enumerable properties and proxies. \* `%O`: `Object`. A string representation of an object with generic JavaScript object formatting. Similar to `util.inspect()` without options. This will show the full object not including non-enumerable properties and proxies. \* `%c`: `CSS`. This specifier is ignored and will skip any CSS passed in. \* `%%`: single percent sign (`'%'`). This does not consume an argument. \* Returns: {string} The formatted string If a specifier does not have a corresponding argument, it is not replaced: ```js util.format('%s:%s', 'foo'); // Returns: 'foo:%s' ``` Values that are not part of the format string are formatted using `util.inspect()` if their type is not `string`. If there are more arguments passed to the `util.format()` method than the number of specifiers, the extra arguments are concatenated to the returned string, separated by spaces: ```js util.format('%s:%s', 'foo', 'bar', 'baz'); // Returns: 'foo:bar baz' ``` If the first argument does not contain a valid format specifier, `util.format()` returns a string that is the concatenation of all arguments separated by spaces: ```js util.format(1, 2, 3); // Returns: '1 2 3' ``` If only one argument is passed to `util.format()`, it is returned as it is without any formatting: ```js util.format('%% %s'); // Returns: '%% %s' ``` `util.format()` is a synchronous method that is intended as a debugging tool. Some input values can have a significant performance overhead that can block the event loop. Use this function with care and never in a hot code path. ## `util.formatWithOptions(inspectOptions, format[, ...args])` \* `inspectOptions` {Object} \* `format` {string} This function is identical to [`util.format()`][], except in that it takes an `inspectOptions` argument which specifies options that are passed along to [`util.inspect()`][]. ```js util.formatWithOptions({ colors: true }, 'See object %O', { foo: 42 }); // Returns 'See object { foo: 42 }', where `42` is colored as a number // when printed to a terminal. ``` ## `util.getCallSites([frameCount][, options])` > Stability: 1.1 - Active development \* `frameCount` {integer} Optional number of frames to capture as call site objects. \*\*Default:\*\* `10`. Allowable range is between 1 and 200. \* `options` {Object} Optional \* `sourceMap` {boolean} Reconstruct the original location in the stacktrace from the source-map. Enabled by default with the flag `--enable-source-maps`. \* Returns: {Object\[]} An array of call site objects \* `functionName` {string} Returns the name of the function associated with this call site. \* `scriptName` {string} Returns the name of the resource that contains the script for the function for this call site. \* `scriptId` {string} Returns the unique id of the script, as in Chrome DevTools protocol [`Runtime.ScriptId`][]. \* `lineNumber` {number} Returns the JavaScript script line number (1-based). \* `columnNumber` {number} Returns the JavaScript script column number (1-based). Returns
|
https://github.com/nodejs/node/blob/main//doc/api/util.md
|
main
|
nodejs
|
[
-0.010572385974228382,
0.1148516982793808,
-0.07280074805021286,
-0.009972015395760536,
-0.012084081768989563,
-0.07825852185487747,
-0.015663769096136093,
0.13734155893325806,
-0.004933095071464777,
-0.04884732514619827,
-0.02513316087424755,
-0.04073113948106766,
0.04884802922606468,
0.045198891311883926,
0.10383579134941101,
-0.003293416928499937,
-0.03586875647306442,
0.01048316154628992,
-0.032986801117658615,
-0.07527089864015579,
0.06564515829086304,
0.04449351504445076,
-0.012550109066069126,
-0.01145920529961586,
-0.017129914835095406,
-0.029072942212224007,
0.02887727878987789,
0.016912953928112984,
0.06199856474995613,
-0.035875871777534485,
-0.0475332997739315,
0.03539983928203583,
0.03753139451146126,
-0.018170693889260292,
0.060697488486766815,
0.0544651634991169,
0.03374277055263519,
-0.04234359785914421,
0.04036916792392731,
-0.024591360241174698,
0.074286088347435,
0.05954950675368309,
-0.03012058697640896,
-0.08488545566797256,
0.04952644556760788,
-0.01952393911778927,
-0.04036271572113037,
0.03264588490128517,
-0.09153790771961212,
0.0707334578037262,
0.011047870852053165,
0.05888697877526283,
-0.06945431232452393,
-0.009160923771560192,
0.06524424999952316,
-0.011636226437985897,
-0.055192045867443085,
-0.04385986924171448,
0.0059258295223116875,
-0.02037225477397442,
-0.08340276032686234,
-0.002858047606423497,
-0.007511173374950886,
-0.007490246556699276,
-0.014918811619281769,
-0.0600515641272068,
-0.026743346825242043,
-0.05380154028534889,
0.00826945248991251,
-0.039042238146066666,
-0.03064541518688202,
-0.02831825241446495,
-0.04125282168388367,
0.028738249093294144,
0.0085728969424963,
0.018917692825198174,
0.0020636972039937973,
0.029475584626197815,
-0.040477558970451355,
0.0032209502533078194,
-0.02093425579369068,
-0.1103719174861908,
0.020837759599089622,
0.03614945709705353,
0.028572864830493927,
0.03908497467637062,
-0.017390962690114975,
0.07607287913560867,
-0.022955792024731636,
0.0734148919582367,
-0.009203718043863773,
-0.09446494281291962,
-0.025554023683071136,
0.0004039901541545987,
-0.004826736636459827,
0.09281189739704132,
0.01561002153903246,
0.0021729222498834133,
-0.07582906633615494,
0.04297420755028725,
-0.0077559747733175755,
-0.07806047052145004,
0.09128151088953018,
-0.04396890103816986,
0.016739705577492714,
0.05048999935388565,
0.056511495262384415,
0.011166336946189404,
0.0634981244802475,
-0.02094566822052002,
0.010554803535342216,
0.0008926399168558419,
-0.02800152450799942,
-0.06761956959962845,
-0.005710108671337366,
0.034943416714668274,
0.029191777110099792,
0.019885161891579628,
0.049304887652397156,
0.048580098897218704,
0.12486019730567932,
0.006295754574239254,
-0.011258281767368317,
0.05789826810359955,
-0.011380751617252827,
0.03160356730222702,
-0.0019373369868844748,
5.843045565337684e-33,
-0.0232220608741045,
-0.0024293800815939903,
0.019087549299001694,
-0.05976543202996254,
-0.10589171200990677,
-0.029020827263593674,
-0.02128702402114868,
-0.0005520698032341897,
0.02069096267223358,
0.05452829971909523,
-0.05245012789964676,
0.09582500904798508,
0.016818488016724586,
0.009854055009782314,
-0.007264828775078058,
0.013217032887041569,
0.11394529789686203,
-0.02750692330300808,
-0.0006310453172773123,
-0.03470125049352646,
0.054831571877002716,
0.03628300130367279,
-0.0634327381849289,
0.11626021564006805,
0.006082864478230476,
0.06401915103197098,
0.043916210532188416,
-0.02861616760492325,
-0.055556878447532654,
0.013380280695855618,
-0.043030668050050735,
-0.08043508976697922,
0.02188412845134735,
0.053221169859170914,
0.0708194151520729,
0.02748490869998932,
0.004924267530441284,
0.017473751679062843,
-0.024395080283284187,
-0.040680430829524994,
-0.11105172336101532,
-0.007104768883436918,
-0.08502163738012314,
0.047719214111566544,
-0.013426784425973892,
-0.024609943851828575,
0.036284882575273514,
0.021126728504896164,
0.0037779274862259626,
0.018689634278416634,
-0.05168827623128891,
0.08517874777317047,
0.03250901401042938,
0.013006323017179966,
-0.0014647131320089102,
-0.045444514602422714,
0.11822862923145294,
0.013286561705172062,
-0.009098353795707226,
-0.02520998939871788,
-0.02405971847474575,
0.0717720091342926,
0.004222175106406212,
0.02099292352795601,
-0.048645809292793274,
-0.0029868786223232746,
0.005735236685723066,
-0.0390910729765892,
-0.019035877659916878,
0.06063974276185036,
-0.08142688870429993,
0.10333522409200668,
-0.005932986736297607,
0.030170822516083717,
-0.02295706793665886,
-0.12868911027908325,
0.025457801297307014,
0.008982399478554726,
0.01356322132050991,
-0.015001017600297928,
0.08136861771345139,
0.09161258488893509,
0.021894114091992378,
-0.02040480263531208,
-0.012617761269211769,
-0.06840605288743973,
0.02185661345720291,
-0.024102328345179558,
-0.008607438765466213,
-0.13151131570339203,
0.05571414530277252,
-0.01074064988642931,
-0.017663294449448586,
-0.039428506046533585,
-0.1142793744802475,
-6.933338248902449e-33,
-0.027074458077549934,
0.03307335078716278,
-0.012602549977600574,
0.05387170612812042,
-0.08892429620027542,
-0.06827857345342636,
0.05922773480415344,
0.054425835609436035,
0.0755312368273735,
-0.01827220246195793,
-0.038276154547929764,
-0.009239882230758667,
0.00033908322802744806,
-0.08750076591968536,
0.060954827815294266,
0.02448723092675209,
-0.1374828815460205,
0.014513548463582993,
-0.006939722690731287,
-0.022981926798820496,
-0.06509928405284882,
0.04464367404580116,
0.014541530050337315,
0.008678726851940155,
-0.07665511220693588,
0.014056524261832237,
0.031099479645490646,
-0.0350365974009037,
-0.005237690173089504,
0.020268388092517853,
-0.04149128124117851,
-0.0446748211979866,
0.01543424278497696,
0.019202327355742455,
-0.04547109454870224,
-0.09916380047798157,
0.07909299433231354,
0.03666256368160248,
-0.01847809925675392,
0.009985221549868584,
0.03058248944580555,
0.05058322101831436,
0.0069375233724713326,
0.0993979349732399,
-0.0008070561452768743,
0.00014240625023376197,
-0.0032303857151418924,
0.08198901265859604,
0.0024665461387485266,
-0.11296745389699936,
0.03555503860116005,
-0.0037848036736249924,
-0.0050173476338386536,
0.014386619441211224,
-0.01030229963362217,
-0.06584858149290085,
-0.029987705871462822,
0.00021179109171498567,
-0.045104075223207474,
0.012307270430028439,
-0.07810715585947037,
-0.09735728800296783,
0.01744110696017742,
0.009152465499937534,
0.012661950662732124,
-0.006563072092831135,
-0.05168406292796135,
-0.09303313493728638,
-0.04789058491587639,
-0.05418391898274422,
0.03792824596166611,
-0.07284817099571228,
0.023723993450403214,
-0.00012296802015043795,
-0.02695499174296856,
-0.032483115792274475,
-0.016757482662796974,
0.010124258697032928,
0.03480404615402222,
0.07590720057487488,
-0.0015806667506694794,
0.03221593052148819,
0.011127498932182789,
0.0981985554099083,
0.028570756316184998,
-0.05039851740002632,
0.008329750038683414,
0.12384539097547531,
-0.0704445168375969,
-0.03569906949996948,
-0.009945332072675228,
0.1295962631702423,
-0.00018496277334634215,
0.07416799664497375,
0.05574682727456093,
-6.030549570823496e-8,
-0.02298232540488243,
-0.039981234818696976,
-0.07731854915618896,
-0.003256803145632148,
-0.03770720958709717,
0.03844006359577179,
-0.04479016363620758,
-0.07299713045358658,
0.06068146228790283,
0.03615133464336395,
0.016611095517873764,
0.04745183512568474,
-0.1131930872797966,
-0.153525710105896,
0.0009207713883370161,
0.06712227314710617,
0.043231040239334106,
0.02537522464990616,
-0.0553319938480854,
0.07361964136362076,
0.03729207441210747,
-0.0035041370429098606,
-0.07185093313455582,
-0.07048863172531128,
0.0004919671919196844,
-0.008486781269311905,
-0.04820539802312851,
0.06660209596157074,
-0.01971670612692833,
-0.046811267733573914,
-0.026263579726219177,
-0.0004007235402241349,
0.00889117643237114,
-0.023061273619532585,
-0.06467077136039734,
-0.025219421833753586,
0.025770554319024086,
0.07705298066139221,
0.06140634045004845,
0.12423783540725708,
-0.02008638344705105,
-0.017402121797204018,
-0.15287360548973083,
0.022115645930171013,
-0.02882908470928669,
-0.04770442470908165,
-0.029978489503264427,
0.024051252752542496,
-0.03424105420708656,
-0.015911024063825607,
-0.06605014204978943,
-0.017227953299880028,
-0.04289998859167099,
-0.020727869123220444,
-0.07640400528907776,
0.019269200041890144,
0.013647026382386684,
0.011007432825863361,
-0.012413732707500458,
0.029342103749513626,
0.0936896875500679,
0.04902271181344986,
0.03854415938258171,
0.004345716442912817
] | 0.104439
|
the resource that contains the script for the function for this call site. \* `scriptId` {string} Returns the unique id of the script, as in Chrome DevTools protocol [`Runtime.ScriptId`][]. \* `lineNumber` {number} Returns the JavaScript script line number (1-based). \* `columnNumber` {number} Returns the JavaScript script column number (1-based). Returns an array of call site objects containing the stack of the caller function. Unlike accessing an `error.stack`, the result returned from this API is not interfered with `Error.prepareStackTrace`. ```mjs import { getCallSites } from 'node:util'; function exampleFunction() { const callSites = getCallSites(); console.log('Call Sites:'); callSites.forEach((callSite, index) => { console.log(`CallSite ${index + 1}:`); console.log(`Function Name: ${callSite.functionName}`); console.log(`Script Name: ${callSite.scriptName}`); console.log(`Line Number: ${callSite.lineNumber}`); console.log(`Column Number: ${callSite.columnNumber}`); }); // CallSite 1: // Function Name: exampleFunction // Script Name: /home/example.js // Line Number: 5 // Column Number: 26 // CallSite 2: // Function Name: anotherFunction // Script Name: /home/example.js // Line Number: 22 // Column Number: 3 // ... } // A function to simulate another stack layer function anotherFunction() { exampleFunction(); } anotherFunction(); ``` ```cjs const { getCallSites } = require('node:util'); function exampleFunction() { const callSites = getCallSites(); console.log('Call Sites:'); callSites.forEach((callSite, index) => { console.log(`CallSite ${index + 1}:`); console.log(`Function Name: ${callSite.functionName}`); console.log(`Script Name: ${callSite.scriptName}`); console.log(`Line Number: ${callSite.lineNumber}`); console.log(`Column Number: ${callSite.columnNumber}`); }); // CallSite 1: // Function Name: exampleFunction // Script Name: /home/example.js // Line Number: 5 // Column Number: 26 // CallSite 2: // Function Name: anotherFunction // Script Name: /home/example.js // Line Number: 22 // Column Number: 3 // ... } // A function to simulate another stack layer function anotherFunction() { exampleFunction(); } anotherFunction(); ``` It is possible to reconstruct the original locations by setting the option `sourceMap` to `true`. If the source map is not available, the original location will be the same as the current location. When the `--enable-source-maps` flag is enabled, for example when using `--experimental-transform-types`, `sourceMap` will be true by default. ```ts import { getCallSites } from 'node:util'; interface Foo { foo: string; } const callSites = getCallSites({ sourceMap: true }); // With sourceMap: // Function Name: '' // Script Name: example.js // Line Number: 7 // Column Number: 26 // Without sourceMap: // Function Name: '' // Script Name: example.js // Line Number: 2 // Column Number: 26 ``` ```cjs const { getCallSites } = require('node:util'); const callSites = getCallSites({ sourceMap: true }); // With sourceMap: // Function Name: '' // Script Name: example.js // Line Number: 7 // Column Number: 26 // Without sourceMap: // Function Name: '' // Script Name: example.js // Line Number: 2 // Column Number: 26 ``` ## `util.getSystemErrorName(err)` \* `err` {number} \* Returns: {string} Returns the string name for a numeric error code that comes from a Node.js API. The mapping between error codes and error names is platform-dependent. See [Common System Errors][] for the names of common errors. ```js fs.access('file/that/does/not/exist', (err) => { const name = util.getSystemErrorName(err.errno); console.error(name); // ENOENT }); ``` ## `util.getSystemErrorMap()` \* Returns: {Map} Returns a Map of all system error codes available from the Node.js API. The mapping between error codes and error names is platform-dependent. See [Common System Errors][] for the names of common errors. ```js fs.access('file/that/does/not/exist', (err) => { const errorMap = util.getSystemErrorMap(); const name = errorMap.get(err.errno); console.error(name); // ENOENT }); ``` ## `util.getSystemErrorMessage(err)` \* `err` {number} \* Returns: {string} Returns the string message for a numeric error code that comes from a Node.js API. The mapping between error codes and string messages is platform-dependent. ```js fs.access('file/that/does/not/exist', (err) => { const message = util.getSystemErrorMessage(err.errno); console.error(message); // No such file or directory }); ``` ## `util.setTraceSigInt(enable)` \* `enable` {boolean} Enable or disable printing a
|
https://github.com/nodejs/node/blob/main//doc/api/util.md
|
main
|
nodejs
|
[
-0.10047809034585953,
-0.003160280641168356,
-0.04753541946411133,
0.05203697085380554,
-0.01504648569971323,
-0.07913074642419815,
-0.013766812160611153,
0.09104957431554794,
0.075686976313591,
-0.02666529454290867,
-0.0517006441950798,
-0.04729665070772171,
-0.03198552504181862,
-0.06326620280742645,
-0.026497285813093185,
-0.010661980137228966,
-0.04666413739323616,
-0.04423989728093147,
0.013532712124288082,
-0.03761817514896393,
0.054483383893966675,
0.060043174773454666,
-0.02360808663070202,
-0.010594607330858707,
0.007065764628350735,
-0.03003891184926033,
-0.11238336563110352,
-0.01904631219804287,
0.06983892619609833,
0.019197477027773857,
0.056427985429763794,
0.022057097405195236,
-0.08393442630767822,
-0.017993949353694916,
-0.041300512850284576,
0.10162026435136795,
-0.08363880217075348,
-0.045999687165021896,
-0.014920069836080074,
0.0625271126627922,
0.055597126483917236,
0.0329761877655983,
-0.02193361707031727,
-0.033999331295490265,
0.03285234421491623,
-0.08488688617944717,
-0.06928133964538574,
-0.009468930773437023,
-0.05266585946083069,
0.027213454246520996,
0.026142049580812454,
0.07515798509120941,
-0.04053514078259468,
-0.0710516944527626,
0.01978699490427971,
0.02924855798482895,
0.016246557235717773,
-0.017337007448077202,
0.05411422625184059,
0.1056734174489975,
-0.03202227130532265,
-0.06593441963195801,
0.035193126648664474,
-0.047995105385780334,
0.05605290085077286,
-0.004095157608389854,
-0.00840410590171814,
-0.003747017355635762,
-0.0032085594721138477,
0.006526622921228409,
-0.007065718527883291,
0.028618957847356796,
0.038975946605205536,
0.02167227491736412,
-0.003363819792866707,
0.03448870778083801,
-0.026469187811017036,
0.017930615693330765,
0.00035038613714277744,
-0.03417305275797844,
0.030824527144432068,
-0.10929097980260849,
0.006119387689977884,
0.053477298468351364,
0.020822009071707726,
0.11123346537351608,
0.027883803471922874,
0.07415802031755447,
0.06369227916002274,
0.024739945307374,
-0.04716449975967407,
-0.056063953787088394,
-0.07677475363016129,
0.05338846892118454,
-0.052684202790260315,
0.03169049695134163,
0.000007584726517961826,
-0.037433698773384094,
0.0018030422506853938,
0.014946608804166317,
0.008359342813491821,
0.03690434247255325,
0.026582062244415283,
0.007157132029533386,
-0.029329337179660797,
0.012049885466694832,
-0.02392030693590641,
0.001979890512302518,
-0.009912985377013683,
0.008386669680476189,
0.015687530860304832,
0.06092206761240959,
0.006349929608404636,
0.017364520579576492,
0.020128460600972176,
-0.022051861509680748,
0.10858321189880371,
-0.0731511116027832,
0.09043212980031967,
0.07848218083381653,
0.13749532401561737,
0.06507541984319687,
0.028349436819553375,
-0.025334039703011513,
0.02441222406923771,
0.018767453730106354,
0.0920259952545166,
2.8838959431829897e-33,
0.049788590520620346,
-0.0731332004070282,
0.049703292548656464,
-0.013591306284070015,
0.06205097958445549,
-0.011376632377505302,
0.017937779426574707,
-0.014368051663041115,
-0.06020427867770195,
0.0557192899286747,
-0.023848071694374084,
0.05513881891965866,
0.0017446307465434074,
-0.06493382900953293,
0.0009396474924869835,
0.09222893416881561,
0.05828453600406647,
-0.04871879145503044,
-0.017525577917695045,
0.03458496928215027,
-0.04050068184733391,
-0.027800455689430237,
0.03634737432003021,
0.030264345929026604,
0.07378319650888443,
0.04141266644001007,
-0.07502305507659912,
0.09347895532846451,
-0.026309223845601082,
-0.018479658290743828,
0.0028862529434263706,
-0.009792915545403957,
-0.05751657485961914,
0.029450630769133568,
0.08640936762094498,
0.024866202846169472,
-0.021294433623552322,
0.006427580025047064,
-0.10460621118545532,
0.011165611445903778,
-0.002623253734782338,
0.013691899366676807,
-0.05452620983123779,
0.06526107341051102,
-0.040598805993795395,
-0.12138522416353226,
-0.07280359417200089,
0.0201328806579113,
0.038557086139917374,
-0.049166399985551834,
-0.08028995990753174,
0.10114871710538864,
0.09081533551216125,
-0.05474620684981346,
0.08262497186660767,
-0.04315279424190521,
0.04068060219287872,
-0.017092909663915634,
0.0128204096108675,
-0.00021276302868500352,
0.01553758792579174,
-0.06076209992170334,
-0.11258973181247711,
0.02381814457476139,
-0.011943526566028595,
0.006431438494473696,
-0.03460599109530449,
0.0497414655983448,
-0.011883842758834362,
0.010736603289842606,
0.02221396565437317,
0.05490025132894516,
0.04784182086586952,
0.044779643416404724,
0.014770328998565674,
-0.0265344250947237,
-0.033635109663009644,
-0.0676933228969574,
-0.015892500057816505,
-0.027214961126446724,
0.16580526530742645,
-0.014466640539467335,
-0.0023430653382092714,
0.014852335676550865,
-0.018829243257641792,
0.12011833488941193,
-0.0017915167845785618,
-0.06563934683799744,
-0.023353707045316696,
0.10886196792125702,
-0.07915975153446198,
-0.06280561536550522,
-0.08673769235610962,
-0.05861994996666908,
-0.10913652181625366,
-5.123093846367419e-33,
-0.07045815885066986,
0.022455576807260513,
-0.06683864444494247,
0.04486057907342911,
-0.05665043741464615,
-0.06569434702396393,
0.043679092079401016,
0.043251022696495056,
0.013645150698721409,
0.00507360277697444,
-0.0259233545511961,
0.040911685675382614,
-0.0025934837758541107,
0.013738262467086315,
0.09901496022939682,
0.07627739012241364,
-0.11717113107442856,
-0.05165814235806465,
0.04686561971902847,
-0.08744437992572784,
0.039495665580034256,
0.023007309064269066,
0.04871749505400658,
0.04117446765303612,
-0.07074545323848724,
-0.03954264149069786,
-0.021725954487919807,
-0.03777441754937172,
-0.03874608874320984,
-0.10041477531194687,
-0.039088599383831024,
-0.04433102905750275,
-0.03661612421274185,
0.08204654604196548,
0.03556123375892639,
0.002302201697602868,
0.0776992067694664,
0.05802801996469498,
0.038299866020679474,
-0.01548920851200819,
-0.023962989449501038,
-0.020924190059304237,
0.02766813151538372,
-0.03537176921963692,
-0.028516074642539024,
0.0018297380302101374,
-0.02153850346803665,
0.11097728461027145,
-0.01495677325874567,
-0.08059963583946228,
-0.06515758484601974,
-0.008268032222986221,
-0.023353001102805138,
0.07672987133264542,
-0.01783827133476734,
0.010804069228470325,
0.009877023287117481,
-0.07418671250343323,
0.01926024816930294,
0.016203956678509712,
0.000432233908213675,
-0.0700446218252182,
-0.09305903315544128,
0.02510547824203968,
0.03297535702586174,
0.04565178230404854,
-0.05039384216070175,
-0.054325077682733536,
0.0586082860827446,
0.0690547376871109,
-0.01800094172358513,
-0.08413936197757721,
0.03261007368564606,
-0.03307062014937401,
0.012535878457129002,
0.0020242047030478716,
-0.08917403966188431,
-0.022763146087527275,
-0.0019423464545980096,
0.07038577646017075,
0.08394010365009308,
0.02928818017244339,
0.07049249857664108,
-0.05767228081822395,
0.026332193985581398,
-0.02963930554687977,
0.07245488464832306,
0.08037819713354111,
-0.032992176711559296,
-0.023995980620384216,
0.03700414299964905,
-0.023370318114757538,
-0.12211989611387253,
-0.014547832310199738,
-0.011491292156279087,
-5.097929900443887e-8,
-0.0054495627991855145,
0.0297529399394989,
-0.08651020377874374,
-0.04823468253016472,
0.019620098173618317,
-0.04413663595914841,
0.015491071157157421,
-0.039049744606018066,
-0.02164180763065815,
0.026945140212774277,
-0.05217136815190315,
0.008690902031958103,
0.03827366232872009,
0.03942414000630379,
0.0057449620217084885,
0.027058951556682587,
-0.007208190392702818,
0.04513125866651535,
-0.027890853583812714,
-0.010928629897534847,
-0.026411322876811028,
-0.009468061849474907,
0.058426424860954285,
-0.01746968924999237,
0.011170423589646816,
-0.0043126060627400875,
-0.027274560183286667,
0.1149175837635994,
-0.04060458391904831,
0.020135018974542618,
-0.07500413060188293,
-0.01141772884875536,
0.001250815810635686,
-0.006464574486017227,
-0.019103659316897392,
0.0605708509683609,
0.026088571175932884,
-0.03906518965959549,
0.06611979007720947,
-0.006634841673076153,
0.07965324074029922,
-0.011582044884562492,
-0.03393884003162384,
0.07334399968385696,
0.029016196727752686,
-0.009823130443692207,
-0.07160750776529312,
0.03907220810651779,
0.09461464732885361,
-0.05592603236436844,
-0.05532556772232056,
-0.031790975481271744,
-0.04532143846154213,
-0.008052874356508255,
-0.04671887308359146,
-0.04016449302434921,
-0.043801069259643555,
-0.07288730144500732,
0.02051914483308792,
0.03355344384908676,
-0.022972097620368004,
0.0315602645277977,
0.06440214067697525,
-0.04195224121212959
] | 0.060326
|
message for a numeric error code that comes from a Node.js API. The mapping between error codes and string messages is platform-dependent. ```js fs.access('file/that/does/not/exist', (err) => { const message = util.getSystemErrorMessage(err.errno); console.error(message); // No such file or directory }); ``` ## `util.setTraceSigInt(enable)` \* `enable` {boolean} Enable or disable printing a stack trace on `SIGINT`. The API is only available on the main thread. ## `util.inherits(constructor, superConstructor)` > Stability: 3 - Legacy: Use ES2015 class syntax and `extends` keyword instead. \* `constructor` {Function} \* `superConstructor` {Function} Usage of `util.inherits()` is discouraged. Please use the ES6 `class` and `extends` keywords to get language level inheritance support. Also note that the two styles are [semantically incompatible][]. Inherit the prototype methods from one [constructor][] into another. The prototype of `constructor` will be set to a new object created from `superConstructor`. This mainly adds some input validation on top of `Object.setPrototypeOf(constructor.prototype, superConstructor.prototype)`. As an additional convenience, `superConstructor` will be accessible through the `constructor.super\_` property. ```js const util = require('node:util'); const EventEmitter = require('node:events'); function MyStream() { EventEmitter.call(this); } util.inherits(MyStream, EventEmitter); MyStream.prototype.write = function(data) { this.emit('data', data); }; const stream = new MyStream(); console.log(stream instanceof EventEmitter); // true console.log(MyStream.super\_ === EventEmitter); // true stream.on('data', (data) => { console.log(`Received data: "${data}"`); }); stream.write('It works!'); // Received data: "It works!" ``` ES6 example using `class` and `extends`: ```mjs import EventEmitter from 'node:events'; class MyStream extends EventEmitter { write(data) { this.emit('data', data); } } const stream = new MyStream(); stream.on('data', (data) => { console.log(`Received data: "${data}"`); }); stream.write('With ES6'); ``` ```cjs const EventEmitter = require('node:events'); class MyStream extends EventEmitter { write(data) { this.emit('data', data); } } const stream = new MyStream(); stream.on('data', (data) => { console.log(`Received data: "${data}"`); }); stream.write('With ES6'); ``` ## `util.inspect(object[, options])` ## `util.inspect(object[, showHidden[, depth[, colors]]])` \* `object` {any} Any JavaScript primitive or `Object`. \* `options` {Object} \* `showHidden` {boolean} If `true`, `object`'s non-enumerable symbols and properties are included in the formatted result. {WeakMap} and {WeakSet} entries are also included as well as user defined prototype properties (excluding method properties). \*\*Default:\*\* `false`. \* `depth` {number} Specifies the number of times to recurse while formatting `object`. This is useful for inspecting large objects. To recurse up to the maximum call stack size pass `Infinity` or `null`. \*\*Default:\*\* `2`. \* `colors` {boolean} If `true`, the output is styled with ANSI color codes. Colors are customizable. See [Customizing `util.inspect` colors][]. \*\*Default:\*\* `false`. \* `customInspect` {boolean} If `false`, `[util.inspect.custom](depth, opts, inspect)` functions are not invoked. \*\*Default:\*\* `true`. \* `showProxy` {boolean} If `true`, `Proxy` inspection includes the [`target` and `handler`][] objects. \*\*Default:\*\* `false`. \* `maxArrayLength` {integer} Specifies the maximum number of `Array`, {TypedArray}, {Map}, {WeakMap}, and {WeakSet} elements to include when formatting. Set to `null` or `Infinity` to show all elements. Set to `0` or negative to show no elements. \*\*Default:\*\* `100`. \* `maxStringLength` {integer} Specifies the maximum number of characters to include when formatting. Set to `null` or `Infinity` to show all elements. Set to `0` or negative to show no characters. \*\*Default:\*\* `10000`. \* `breakLength` {integer} The length at which input values are split across multiple lines. Set to `Infinity` to format the input as a single line (in combination with `compact` set to `true` or any number >= `1`). \*\*Default:\*\* `80`. \* `compact` {boolean|integer} Setting this to `false` causes each object key to be displayed on a new line. It will break on new lines in text that is longer than `breakLength`. If set to a number, the most `n` inner elements are united on a single line as long as all properties fit into `breakLength`. Short array elements are also grouped together. For more information, see
|
https://github.com/nodejs/node/blob/main//doc/api/util.md
|
main
|
nodejs
|
[
-0.04657907038927078,
0.010725765489041805,
0.024151833727955818,
0.0368712954223156,
0.07509417086839676,
-0.04182521253824234,
-0.00956051517277956,
0.121053546667099,
0.00994776003062725,
-0.05028335377573967,
0.0022477570455521345,
0.015811704099178314,
-0.006947048474103212,
0.012810715474188328,
0.037930455058813095,
0.01842055283486843,
-0.0386236310005188,
-0.028996193781495094,
-0.015333387069404125,
-0.026250356808304787,
0.08237620443105698,
0.0713699609041214,
0.007315575610846281,
0.03934178501367569,
0.03052792139351368,
-0.027676569297909737,
-0.08237997442483902,
-0.034310244023799896,
0.00031743576982989907,
0.02788463421165943,
0.01709454134106636,
0.005035781767219305,
-0.043380510061979294,
0.027427498251199722,
0.0008656431455165148,
0.09302980452775955,
0.0003732963523361832,
-0.1312917321920395,
-0.036168910562992096,
-0.004407072905451059,
-0.06344258040189743,
0.08371428400278091,
-0.00987008586525917,
-0.06102414429187775,
0.03380691260099411,
-0.08554635941982269,
-0.09324231743812561,
0.003393597202375531,
-0.055536333471536636,
0.05020354315638542,
-0.00985917542129755,
-0.00276110484264791,
0.028181247413158417,
-0.06531096994876862,
0.06518454849720001,
0.013340934179723263,
-0.03451094776391983,
-0.005349309649318457,
-0.006049627438187599,
0.0822518840432167,
0.014797540381550789,
-0.06224891170859337,
0.05215028300881386,
-0.08445008099079132,
-0.00705276895314455,
0.02501976303756237,
0.01718895696103573,
-0.01282090786844492,
-0.031034642830491066,
0.04624492675065994,
0.0004578895168378949,
0.004229039419442415,
-0.010480934754014015,
0.13375669717788696,
-0.009092518128454685,
-0.005639458075165749,
0.018889665603637695,
0.06005574390292168,
-0.01051280740648508,
-0.03505810350179672,
-0.04902291297912598,
-0.0346541628241539,
0.03199664130806923,
0.053032126277685165,
0.03333848714828491,
0.08813183754682541,
-0.03689982742071152,
0.033464543521404266,
0.03576621413230896,
0.04646618291735649,
-0.033771660178899765,
-0.10825909674167633,
-0.04679553583264351,
0.10849258303642273,
0.03378835320472717,
-0.006647355854511261,
-0.07658097892999649,
0.01915590837597847,
-0.04832512512803078,
0.007021448574960232,
-0.044533632695674896,
-0.003788488218560815,
0.041389018297195435,
-0.02509818971157074,
0.039480194449424744,
0.0310808252543211,
0.01213474478572607,
0.003705706214532256,
-0.06067052111029625,
-0.0736897885799408,
0.004682231694459915,
-0.022183889523148537,
0.026964128017425537,
-0.018849393352866173,
0.003936345688998699,
-0.007051009684801102,
0.09414871037006378,
-0.05275138467550278,
0.06320343911647797,
0.07730749994516373,
0.13021355867385864,
-0.026720410212874413,
-0.017569515854120255,
-0.006208401173353195,
0.017211444675922394,
-0.03703510761260986,
0.011280634440481663,
3.787580184251663e-33,
0.012222499586641788,
0.020367490127682686,
0.005877513904124498,
0.12696148455142975,
0.07505683600902557,
-0.02257210947573185,
-0.0022948943078517914,
-0.0748198926448822,
-0.12140605598688126,
-0.04416632279753685,
-0.01535816304385662,
0.010881458409130573,
0.0015777639346197248,
-0.09327247738838196,
0.08826892822980881,
-0.02117726393043995,
0.10754664242267609,
-0.0668816864490509,
0.07560068368911743,
-0.033895451575517654,
0.011693130247294903,
-0.007525954395532608,
0.009087434969842434,
0.004739248193800449,
0.04486526548862457,
0.05817153677344322,
0.012345002964138985,
-0.005719958338886499,
-0.003358833258971572,
-0.010252172127366066,
-0.031299397349357605,
-0.027890916913747787,
0.03688184916973114,
0.03794628009200096,
0.017198380082845688,
-0.04820454865694046,
0.025362171232700348,
0.010067564435303211,
-0.10102275758981705,
-0.001506341970525682,
-0.02202538214623928,
0.04780625179409981,
-0.09485460072755814,
0.007580719422549009,
0.018735267221927643,
-0.04332800582051277,
-0.023817667737603188,
0.04240935668349266,
0.07422447949647903,
-0.03857661038637161,
-0.06586472690105438,
0.08468768000602722,
0.03182817995548248,
-0.010842773132026196,
0.12285209447145462,
0.0008877436048351228,
0.021181663498282433,
-0.02709553763270378,
-0.05470122769474983,
-0.02978327125310898,
0.11024385690689087,
-0.04491936415433884,
0.04589056968688965,
-0.009727825410664082,
0.014282609336078167,
-0.023388663306832314,
-0.0814240500330925,
-0.03279079496860504,
-0.004305111709982157,
0.008888461627066135,
0.0000832184887258336,
-0.004690449219197035,
-0.0059024738147854805,
0.09624458104372025,
-0.023550068959593773,
-0.028197376057505608,
-0.022337453439831734,
0.0172333512455225,
0.003872509580105543,
-0.029585737735033035,
-0.011584708467125893,
-0.055894866585731506,
-0.011179846711456776,
0.08324585109949112,
0.03919157385826111,
0.024383001029491425,
-0.01565340720117092,
0.04696164280176163,
0.08021694421768188,
0.08825410157442093,
-0.02834722213447094,
-0.07271504402160645,
0.03300860524177551,
-0.0730917677283287,
-0.12349250167608261,
-5.913998037011332e-33,
-0.043591130524873734,
0.040357306599617004,
-0.0813220739364624,
0.010378310456871986,
-0.0728701502084732,
-0.014933561906218529,
0.02288220077753067,
0.008442561142146587,
-0.012690690346062183,
0.030810847878456116,
-0.025891510769724846,
0.04022218659520149,
0.06652531027793884,
-0.03105081245303154,
-0.000837808009237051,
0.03650409355759621,
-0.09894388914108276,
-0.06885390728712082,
0.015123180113732815,
-0.02467290498316288,
0.02608509548008442,
0.0715075209736824,
0.02263982594013214,
0.026056598871946335,
-0.07339389622211456,
0.010242507793009281,
-0.05539536103606224,
-0.006815636530518532,
-0.07704757153987885,
-0.06630249321460724,
-0.04475770518183708,
0.004019724205136299,
-0.01053747907280922,
0.015663690865039825,
0.07693629711866379,
-0.11270250380039215,
0.04237546771764755,
0.023527203127741814,
-0.028767339885234833,
-0.02366511896252632,
0.05103720352053642,
0.049814678728580475,
-0.01895172707736492,
-0.023353703320026398,
-0.00688837980851531,
0.0195140577852726,
0.02562967874109745,
-0.026169830933213234,
-0.011478692293167114,
-0.0750402957201004,
0.01344490610063076,
-0.12083260715007782,
0.08532091975212097,
0.0337214432656765,
-0.05663382634520531,
0.017250441014766693,
0.008970080874860287,
0.003925811033695936,
-0.01015210710465908,
0.06279738247394562,
-0.004530536476522684,
-0.15313853323459625,
-0.08460858464241028,
-0.05676316097378731,
0.025476934388279915,
-0.05126933753490448,
-0.10306309908628464,
0.003768546972423792,
0.08487069606781006,
-0.021071217954158783,
-0.002971475711092353,
-0.047951146960258484,
-0.0165780708193779,
0.01675640419125557,
-0.002155181486159563,
0.01595880091190338,
-0.03133738040924072,
-0.06942062824964523,
0.03474165126681328,
0.0612693727016449,
-0.000171697698533535,
0.0463719367980957,
-0.007760579232126474,
0.07589621841907501,
0.049085117876529694,
-0.026085244491696358,
0.011808818206191063,
0.10773754864931107,
0.007970087230205536,
-0.04673582315444946,
-0.007737548556178808,
0.028097031638026237,
-0.08714395761489868,
-0.038897112011909485,
0.012886982411146164,
-6.192277623995324e-8,
-0.06840202212333679,
-0.004728920292109251,
-0.10488894581794739,
-0.09825992584228516,
0.061455968767404556,
-0.004148906096816063,
-0.015856537967920303,
-0.028133483603596687,
0.03353537991642952,
0.09122496098279953,
-0.07813718169927597,
0.040746334940195084,
0.0003126371302641928,
-0.10869909077882767,
-0.01398660708218813,
-0.04109236225485802,
-0.015345895662903786,
0.10632586479187012,
-0.0035268981009721756,
-0.02530827932059765,
0.05688296630978584,
0.055444519966840744,
0.018408173695206642,
0.0321030467748642,
-0.062323927879333496,
-0.06069335341453552,
0.07413751631975174,
0.06186733767390251,
-0.060489997267723083,
-0.04550149291753769,
-0.09713064134120941,
-0.000714446825440973,
0.03606690466403961,
-0.020343560725450516,
-0.030637158080935478,
0.05310411378741264,
0.03744954988360405,
-0.006122231483459473,
0.06268326938152313,
0.05739525333046913,
0.058269962668418884,
0.03526366874575615,
-0.07190537452697754,
0.037962980568408966,
-0.04177401587367058,
-0.027538513764739037,
-0.03736904263496399,
0.015168294310569763,
-0.004539997782558203,
0.0021176079753786325,
-0.0397074893116951,
0.04011242464184761,
-0.08481579273939133,
0.10932889580726624,
-0.05135786160826683,
-0.037676144391298294,
-0.029314644634723663,
-0.038579680025577545,
-0.033294353634119034,
0.00575194600969553,
0.11693190783262253,
0.05848901346325874,
0.06706632673740387,
-0.03436819836497307
] | 0.173389
|
new line. It will break on new lines in text that is longer than `breakLength`. If set to a number, the most `n` inner elements are united on a single line as long as all properties fit into `breakLength`. Short array elements are also grouped together. For more information, see the example below. \*\*Default:\*\* `3`. \* `sorted` {boolean|Function} If set to `true` or a function, all properties of an object, and `Set` and `Map` entries are sorted in the resulting string. If set to `true` the [default sort][] is used. If set to a function, it is used as a [compare function][]. \* `getters` {boolean|string} If set to `true`, getters are inspected. If set to `'get'`, only getters without a corresponding setter are inspected. If set to `'set'`, only getters with a corresponding setter are inspected. This might cause side effects depending on the getter function. \*\*Default:\*\* `false`. \* `numericSeparator` {boolean} If set to `true`, an underscore is used to separate every three digits in all bigints and numbers. \*\*Default:\*\* `false`. \* Returns: {string} The representation of `object`. The `util.inspect()` method returns a string representation of `object` that is intended for debugging. The output of `util.inspect` may change at any time and should not be depended upon programmatically. Additional `options` may be passed that alter the result. `util.inspect()` will use the constructor's name and/or `Symbol.toStringTag` property to make an identifiable tag for an inspected value. ```js class Foo { get [Symbol.toStringTag]() { return 'bar'; } } class Bar {} const baz = Object.create(null, { [Symbol.toStringTag]: { value: 'foo' } }); util.inspect(new Foo()); // 'Foo [bar] {}' util.inspect(new Bar()); // 'Bar {}' util.inspect(baz); // '[foo] {}' ``` Circular references point to their anchor by using a reference index: ```mjs import { inspect } from 'node:util'; const obj = {}; obj.a = [obj]; obj.b = {}; obj.b.inner = obj.b; obj.b.obj = obj; console.log(inspect(obj)); // { // a: [ [Circular \*1] ], // b: { inner: [Circular \*2], obj: [Circular \*1] } // } ``` ```cjs const { inspect } = require('node:util'); const obj = {}; obj.a = [obj]; obj.b = {}; obj.b.inner = obj.b; obj.b.obj = obj; console.log(inspect(obj)); // { // a: [ [Circular \*1] ], // b: { inner: [Circular \*2], obj: [Circular \*1] } // } ``` The following example inspects all properties of the `util` object: ```mjs import util from 'node:util'; console.log(util.inspect(util, { showHidden: true, depth: null })); ``` ```cjs const util = require('node:util'); console.log(util.inspect(util, { showHidden: true, depth: null })); ``` The following example highlights the effect of the `compact` option: ```mjs import { inspect } from 'node:util'; const o = { a: [1, 2, [[ 'Lorem ipsum dolor sit amet,\nconsectetur adipiscing elit, sed do ' + 'eiusmod \ntempor incididunt ut labore et dolore magna aliqua.', 'test', 'foo']], 4], b: new Map([['za', 1], ['zb', 'test']]), }; console.log(inspect(o, { compact: true, depth: 5, breakLength: 80 })); // { a: // [ 1, // 2, // [ [ 'Lorem ipsum dolor sit amet,\nconsectetur [...]', // A long line // 'test', // 'foo' ] ], // 4 ], // b: Map(2) { 'za' => 1, 'zb' => 'test' } } // Setting `compact` to false or an integer creates more reader friendly output. console.log(inspect(o, { compact: false, depth: 5, breakLength: 80 })); // { // a: [ // 1, // 2, // [ // [ // 'Lorem ipsum dolor sit amet,\n' + // 'consectetur adipiscing elit, sed do eiusmod \n' + // 'tempor incididunt ut labore et dolore magna aliqua.', // 'test', // 'foo' // ] // ], // 4 // ], // b: Map(2) { // 'za' => 1, //
|
https://github.com/nodejs/node/blob/main//doc/api/util.md
|
main
|
nodejs
|
[
-0.017824651673436165,
0.05133464187383652,
0.01786665804684162,
0.003350555431097746,
-0.07972844690084457,
-0.006418721750378609,
0.0011759056942537427,
-0.033183082938194275,
-0.045188140124082565,
0.018291262909770012,
0.000024745882910792716,
0.06490782648324966,
-0.02219841070473194,
-0.1039356142282486,
-0.011428446508944035,
0.06628285348415375,
-0.0863332450389862,
-0.07260569930076599,
-0.10988585650920868,
-0.008848619647324085,
0.04399585351347923,
-0.01787571795284748,
-0.10085095465183258,
0.031801894307136536,
-0.05398028343915939,
0.07981900870800018,
-0.03293459489941597,
0.027815159410238266,
0.008288183249533176,
-0.03563748672604561,
-0.06396806240081787,
0.05176106467843056,
0.09069176763296127,
0.07813559472560883,
-0.006508206482976675,
-0.014081628993153572,
0.0037273389752954245,
0.033887699246406555,
-0.02297886461019516,
-0.009423214942216873,
-0.05645616725087166,
-0.02242877520620823,
-0.047864776104688644,
0.03734341636300087,
-0.023604705929756165,
0.056508343666791916,
-0.04900696873664856,
-0.04103546217083931,
-0.00722136627882719,
-0.008412127383053303,
-0.10857745260000229,
0.10624106973409653,
0.016007833182811737,
0.05770108476281166,
0.07170731574296951,
-0.03308745101094246,
-0.0086168572306633,
-0.036462441086769104,
-0.01495145820081234,
-0.03173984959721565,
0.015225782059133053,
-0.0214555487036705,
-0.017004430294036865,
0.0151330241933465,
0.12466743588447571,
-0.040281932801008224,
-0.026228206232190132,
0.03737308084964752,
0.04013365879654884,
-0.0012653459561988711,
-0.10544570535421371,
0.03209678828716278,
-0.06203373521566391,
0.07283534854650497,
0.011021919548511505,
0.022775523364543915,
-0.016569511964917183,
-0.03522443398833275,
-0.0037939574103802443,
-0.03515349701046944,
-0.05517616122961044,
-0.009737511165440083,
0.02860327623784542,
0.06332998722791672,
-0.0010995056945830584,
0.04715707525610924,
-0.05192491412162781,
-0.07694350183010101,
0.027942292392253876,
0.02280980348587036,
-0.014498259872198105,
-0.06848200410604477,
0.04354636371135712,
0.07946082949638367,
0.028821390122175217,
0.038224127143621445,
-0.00501598184928298,
-0.06975748389959335,
-0.08116333931684494,
0.06846974790096283,
0.03569517284631729,
0.03555084392428398,
0.0997823178768158,
-0.01068066991865635,
-0.017064860090613365,
-0.03346068412065506,
0.03697310760617256,
-0.04092882573604584,
-0.0238539669662714,
-0.03607179969549179,
0.06460574269294739,
0.044338878244161606,
-0.0286836139857769,
-0.06466690450906754,
-0.059557508677244186,
-0.039211198687553406,
-0.026264449581503868,
0.051633164286613464,
0.013497910462319851,
0.05242087319493294,
0.0811643972992897,
-0.03633754700422287,
-0.03386547416448593,
0.014814280904829502,
0.02579272724688053,
0.11965953558683395,
0.0340723916888237,
6.120092318753219e-33,
0.005525391548871994,
-0.008109541609883308,
0.027986295521259308,
0.04493490234017372,
-0.01397693157196045,
0.05005476251244545,
-0.07634946703910828,
0.06068413332104683,
-0.03497433289885521,
0.0507408045232296,
0.04630821943283081,
0.021164949983358383,
0.0193646103143692,
0.05048177018761635,
0.004814296029508114,
-0.07067148387432098,
0.05124317482113838,
-0.03659272566437721,
-0.06084141135215759,
-0.06268210709095001,
-0.09880229830741882,
0.006904206704348326,
0.020610386505723,
-0.02978047914803028,
0.01971684955060482,
-0.041729073971509933,
-0.05063315108418465,
-0.048629261553287506,
-0.1100439503788948,
-0.04240180924534798,
-0.04008563607931137,
-0.023342374712228775,
0.055697742849588394,
0.05779409036040306,
0.09041055291891098,
0.0535481832921505,
-0.04083321616053581,
-0.050313159823417664,
-0.022327115759253502,
-0.055129580199718475,
-0.108851358294487,
-0.06810472905635834,
0.04944020137190819,
0.0025760135613381863,
0.057690251618623734,
-0.08382781594991684,
-0.1342320740222931,
0.0712009146809578,
0.016902677714824677,
0.04878471419215202,
-0.01629190891981125,
0.07866425812244415,
0.044207099825143814,
0.02698725275695324,
0.004683003760874271,
-0.036217570304870605,
0.05835431441664696,
0.011156061664223671,
0.005470650270581245,
0.05960966274142265,
-0.04213552922010422,
0.01601034589111805,
0.02948649227619171,
0.06281132996082306,
0.01898176781833172,
0.007767145521938801,
0.0228152833878994,
0.014330904930830002,
0.10522215068340302,
0.037840381264686584,
-0.08125654608011246,
0.07377893477678299,
-0.015486134216189384,
0.0964777022600174,
-0.023839788511395454,
-0.029601724818348885,
-0.027770044282078743,
-0.03543872758746147,
0.030006524175405502,
-0.11076781153678894,
0.05006564408540726,
-0.006479706149548292,
0.049033645540475845,
-0.017377644777297974,
-0.0593244805932045,
-0.01111843902617693,
-0.03569411858916283,
-0.11097404360771179,
0.02320915088057518,
-0.04241033270955086,
0.024988358840346336,
-0.019462600350379944,
-0.004920742474496365,
-0.02225702628493309,
0.05327916517853737,
-8.66740474003244e-33,
0.052670661360025406,
-0.014499520882964134,
-0.03158674016594887,
0.01702641136944294,
0.030538083985447884,
-0.07512561976909637,
0.016785144805908203,
0.10984086245298386,
0.05913690850138664,
-0.016746442764997482,
0.02917894534766674,
0.06729695945978165,
-0.01972520723938942,
-0.07148701697587967,
0.11052221059799194,
0.022024478763341904,
-0.0342584028840065,
-0.07315179705619812,
0.12481415271759033,
-0.039007898420095444,
0.07173870503902435,
-0.00966927781701088,
-0.05183584615588188,
0.05035758391022682,
-0.03063579648733139,
-0.06187964230775833,
0.06492719799280167,
-0.023336444050073624,
-0.04203490912914276,
0.002170958323404193,
0.01641904003918171,
-0.030490433797240257,
-0.08042494207620621,
0.09943274408578873,
-0.030169924721121788,
-0.09908200055360794,
0.008337165229022503,
0.0766645297408104,
0.032049234956502914,
0.0383027121424675,
-0.007093878462910652,
0.0691113993525505,
0.01943107508122921,
-0.03446927294135094,
0.02123260870575905,
-0.008803684264421463,
-0.05278286710381508,
0.05080142989754677,
-0.0336468406021595,
-0.08955925703048706,
0.01312532089650631,
-0.04474073275923729,
-0.0236812811344862,
0.0102087976410985,
0.005249883513897657,
-0.016686415299773216,
-0.06434286385774612,
0.002022945089265704,
-0.016188114881515503,
0.0030992210377007723,
-0.0864570215344429,
-0.015098112635314465,
0.03002958744764328,
0.05449894070625305,
-0.016697874292731285,
-0.06659173965454102,
-0.06716258823871613,
-0.01599709317088127,
0.001963234506547451,
-0.0185429397970438,
0.025664066895842552,
-0.07576572895050049,
-0.09472951292991638,
-0.052366647869348526,
-0.13260632753372192,
0.002385273575782776,
0.03205281123518944,
-0.028065554797649384,
-0.013524293899536133,
0.08785748481750488,
0.022763051092624664,
-0.011870067566633224,
-0.008250405080616474,
0.09587310254573822,
-0.04955476522445679,
0.05039450526237488,
0.031371310353279114,
0.047149527817964554,
-0.003199186408892274,
0.021402867510914803,
-0.03308643773198128,
0.04048239812254906,
0.010062973015010357,
0.03100210800766945,
-0.09500502794981003,
-6.176151856607248e-8,
-0.01272535789757967,
-0.08123373985290527,
-0.07672157138586044,
0.027196865528821945,
0.059931788593530655,
0.0023821925278753042,
0.028169777244329453,
0.018613586202263832,
-0.07483424246311188,
-0.03397399187088013,
0.06662549823522568,
0.13796508312225342,
-0.06265408545732498,
-0.011011090129613876,
0.00528911454603076,
-0.039312928915023804,
-0.036586180329322815,
-0.0781162828207016,
-0.07116295397281647,
0.005465778987854719,
-0.0026681264862418175,
0.025092553347349167,
0.018822096288204193,
0.051363538950681686,
-0.006500820629298687,
0.040090858936309814,
-0.01304292306303978,
0.0695713460445404,
-0.02558964677155018,
0.012519300915300846,
0.09862980246543884,
0.06085856258869171,
0.0821700170636177,
-0.0032399441115558147,
-0.0008588595082983375,
0.04845797270536423,
-0.07406744360923767,
0.011728668585419655,
0.066457100212574,
0.009841876104474068,
-0.006275268737226725,
0.024420728906989098,
0.04030245915055275,
-0.026102419942617416,
-0.03461781144142151,
-0.06681977957487106,
0.010709930211305618,
-0.015887316316366196,
0.026023773476481438,
-0.11500828713178635,
-0.018639598041772842,
0.029768921434879303,
0.00820450484752655,
-0.05098011717200279,
-0.04189259931445122,
0.012670261785387993,
0.004379697609692812,
0.09997998178005219,
0.06631851196289062,
0.024936268106102943,
-0.030068177729845047,
0.005146543961018324,
0.026095010340213776,
-0.011175871826708317
] | 0.116351
|
// [ // [ // 'Lorem ipsum dolor sit amet,\n' + // 'consectetur adipiscing elit, sed do eiusmod \n' + // 'tempor incididunt ut labore et dolore magna aliqua.', // 'test', // 'foo' // ] // ], // 4 // ], // b: Map(2) { // 'za' => 1, // 'zb' => 'test' // } // } // Setting `breakLength` to e.g. 150 will print the "Lorem ipsum" text in a // single line. ``` ```cjs const { inspect } = require('node:util'); const o = { a: [1, 2, [[ 'Lorem ipsum dolor sit amet,\nconsectetur adipiscing elit, sed do ' + 'eiusmod \ntempor incididunt ut labore et dolore magna aliqua.', 'test', 'foo']], 4], b: new Map([['za', 1], ['zb', 'test']]), }; console.log(inspect(o, { compact: true, depth: 5, breakLength: 80 })); // { a: // [ 1, // 2, // [ [ 'Lorem ipsum dolor sit amet,\nconsectetur [...]', // A long line // 'test', // 'foo' ] ], // 4 ], // b: Map(2) { 'za' => 1, 'zb' => 'test' } } // Setting `compact` to false or an integer creates more reader friendly output. console.log(inspect(o, { compact: false, depth: 5, breakLength: 80 })); // { // a: [ // 1, // 2, // [ // [ // 'Lorem ipsum dolor sit amet,\n' + // 'consectetur adipiscing elit, sed do eiusmod \n' + // 'tempor incididunt ut labore et dolore magna aliqua.', // 'test', // 'foo' // ] // ], // 4 // ], // b: Map(2) { // 'za' => 1, // 'zb' => 'test' // } // } // Setting `breakLength` to e.g. 150 will print the "Lorem ipsum" text in a // single line. ``` The `showHidden` option allows {WeakMap} and {WeakSet} entries to be inspected. If there are more entries than `maxArrayLength`, there is no guarantee which entries are displayed. That means retrieving the same {WeakSet} entries twice may result in different output. Furthermore, entries with no remaining strong references may be garbage collected at any time. ```mjs import { inspect } from 'node:util'; const obj = { a: 1 }; const obj2 = { b: 2 }; const weakSet = new WeakSet([obj, obj2]); console.log(inspect(weakSet, { showHidden: true })); // WeakSet { { a: 1 }, { b: 2 } } ``` ```cjs const { inspect } = require('node:util'); const obj = { a: 1 }; const obj2 = { b: 2 }; const weakSet = new WeakSet([obj, obj2]); console.log(inspect(weakSet, { showHidden: true })); // WeakSet { { a: 1 }, { b: 2 } } ``` The `sorted` option ensures that an object's property insertion order does not impact the result of `util.inspect()`. ```mjs import { inspect } from 'node:util'; import assert from 'node:assert'; const o1 = { b: [2, 3, 1], a: '`a` comes before `b`', c: new Set([2, 3, 1]), }; console.log(inspect(o1, { sorted: true })); // { a: '`a` comes before `b`', b: [ 2, 3, 1 ], c: Set(3) { 1, 2, 3 } } console.log(inspect(o1, { sorted: (a, b) => b.localeCompare(a) })); // { c: Set(3) { 3, 2, 1 }, b: [ 2, 3, 1 ], a: '`a` comes before `b`' } const o2 = { c: new Set([2, 1, 3]), a: '`a` comes before `b`', b: [2, 3, 1], }; assert.strict.equal( inspect(o1, { sorted: true }), inspect(o2, { sorted: true }), ); ``` ```cjs const { inspect } = require('node:util'); const assert = require('node:assert'); const o1 = { b: [2, 3, 1], a: '`a` comes before `b`', c: new Set([2, 3, 1]), }; console.log(inspect(o1, { sorted: true })); // { a: '`a` comes before `b`', b: [ 2, 3,
|
https://github.com/nodejs/node/blob/main//doc/api/util.md
|
main
|
nodejs
|
[
-0.047414153814315796,
0.12110207974910736,
0.07420123368501663,
-0.02619483880698681,
-0.00371043523773551,
0.0009656334877945483,
0.016300681978464127,
0.06620392948389053,
-0.016101902350783348,
0.005500624421983957,
0.009285137988626957,
-0.016791148111224174,
-0.030973752960562706,
-0.08234784007072449,
0.010494514368474483,
0.03266007825732231,
-0.10738792270421982,
0.07164515554904938,
-0.011749833822250366,
-0.11187662184238434,
0.05858815461397171,
0.044859662652015686,
0.05775841698050499,
0.00929227564483881,
-0.02343169040977955,
0.07999344170093536,
-0.013454793021082878,
0.07402351498603821,
0.02086084708571434,
-0.005970328580588102,
0.06228334829211235,
-0.008172553963959217,
0.06613978743553162,
0.07206185907125473,
0.006721292622387409,
0.07222634553909302,
-0.01688000187277794,
-0.07884673029184341,
0.008023759350180626,
-0.001969658536836505,
0.03163718804717064,
0.06882698833942413,
-0.08987787365913391,
-0.0012230132706463337,
0.10010765492916107,
-0.0039613679982721806,
-0.10016705095767975,
0.04188534617424011,
-0.039994362741708755,
0.07129067927598953,
-0.03289084509015083,
0.024126239120960236,
-0.045621175318956375,
0.037293318659067154,
0.04492659866809845,
-0.020849090069532394,
0.01193486712872982,
-0.07062225788831711,
0.10949116945266724,
-0.05373702943325043,
0.011204629205167294,
0.004101262427866459,
0.07406001538038254,
-0.0324866846203804,
0.059790268540382385,
-0.026341091841459274,
-0.033750299364328384,
0.09366156160831451,
-0.05000421777367592,
0.06930574774742126,
-0.09401950240135193,
0.02890264056622982,
-0.045728329569101334,
0.03801475837826729,
-0.11033187806606293,
-0.0019733188673853874,
-0.10107974708080292,
-0.07389765232801437,
-0.015041372738778591,
0.03167249634861946,
-0.06482047587633133,
0.010881723836064339,
0.0780787318944931,
0.052829451858997345,
-0.030839048326015472,
0.07392176985740662,
-0.015076009556651115,
-0.03381732106208801,
0.04561261460185051,
-0.07665307074785233,
-0.04093766584992409,
-0.09262895584106445,
-0.09641323983669281,
0.04784468188881874,
-0.007087418809533119,
0.05995221436023712,
0.024029284715652466,
0.006918386090546846,
-0.006049677729606628,
0.028289679437875748,
0.025114700198173523,
0.05158615857362747,
0.026265723630785942,
-0.04220237582921982,
-0.13271833956241608,
-0.02201615646481514,
0.045471083372831345,
-0.02664562314748764,
0.0013700335985049605,
0.017194433137774467,
0.04304691031575203,
0.001174206263385713,
-0.03938819468021393,
-0.012469898909330368,
-0.04518304765224457,
-0.05630764737725258,
0.05035758018493652,
-0.04182426258921623,
0.12865647673606873,
0.1410837173461914,
0.07311093062162399,
-0.018199026584625244,
-0.057969506829977036,
0.01777549460530281,
0.022012056782841682,
-0.038383230566978455,
0.09910379350185394,
6.547722469902982e-33,
-0.04478416219353676,
-0.020882871001958847,
0.012397609651088715,
0.023605363443493843,
0.02939031273126602,
0.04511507228016853,
-0.05419212579727173,
0.0183201115578413,
-0.1036626473069191,
0.024536490440368652,
-0.062346313148736954,
-0.060693006962537766,
0.0249570794403553,
-0.06074807420372963,
0.05301208794116974,
-0.07487933337688446,
0.0824551060795784,
-0.041662342846393585,
-0.019698187708854675,
0.01918148063123226,
-0.023174671456217766,
-0.00852970127016306,
0.06413314491510391,
0.012228300794959068,
0.004793868400156498,
-0.06444678455591202,
-0.04717841371893883,
-0.0004996808129362762,
-0.040736034512519836,
-0.029841871932148933,
0.09313374012708664,
0.014591637067496777,
-0.019979294389486313,
0.021347327157855034,
0.08417226374149323,
0.025823570787906647,
0.028499530628323555,
0.014872441999614239,
-0.11766478419303894,
-0.009452283382415771,
-0.08440491557121277,
-0.003817725693807006,
0.02771211788058281,
0.01101407129317522,
-0.0017784362426027656,
0.005075771827250719,
-0.017753245308995247,
-0.030358444899320602,
0.0196438729763031,
0.021780837327241898,
-0.056114792823791504,
0.06213042512536049,
0.0024775885976850986,
-0.03227321058511734,
0.028545144945383072,
-0.019828399643301964,
0.012427562847733498,
-0.042115237563848495,
-0.03490186855196953,
0.07033347338438034,
-0.0416841022670269,
0.07596611976623535,
0.036721326410770416,
0.07541820406913757,
0.011872999370098114,
-0.027204835787415504,
-0.0029719227459281683,
0.058526717126369476,
-0.017915068194270134,
0.012838051654398441,
-0.05679219588637352,
-0.018734876066446304,
-0.006189202424138784,
0.04606660082936287,
-0.06891905516386032,
-0.014539764262735844,
-0.061839163303375244,
-0.04919783025979996,
-0.006576016079634428,
-0.10343435406684875,
0.05727323517203331,
-0.07324632257223129,
0.07111562788486481,
-0.0371004156768322,
0.07886864989995956,
-0.07141813635826111,
-0.07288161665201187,
-0.027747726067900658,
0.06658650189638138,
-0.02397473342716694,
0.009955083951354027,
0.013151303865015507,
-0.04000132903456688,
-0.10572793334722519,
-0.06067134439945221,
-6.877589694630732e-33,
0.024294478818774223,
0.017725365236401558,
-0.00701429508626461,
0.07031503319740295,
0.016546722501516342,
-0.046157725155353546,
0.04498074948787689,
0.07576170563697815,
0.02153226174414158,
0.058252718299627304,
0.004185948520898819,
0.0510951466858387,
-0.017262134701013565,
0.0038235716056078672,
0.04695416986942291,
0.05065241828560829,
-0.05410474166274071,
0.013108068145811558,
0.11843649297952652,
-0.028071880340576172,
0.021830519661307335,
-0.07507775723934174,
0.02364065870642662,
0.04330287501215935,
-0.015283814631402493,
0.07848846912384033,
0.0702386125922203,
-0.025760643184185028,
-0.08121056854724884,
-0.03257399797439575,
-0.05166676640510559,
0.00003241641752538271,
0.012246597558259964,
0.09730589389801025,
-0.029252737760543823,
-0.016926176846027374,
0.005810439586639404,
0.10560348629951477,
-0.009645908139646053,
0.04623895511031151,
0.03297039866447449,
0.03326011821627617,
0.0044330875389277935,
-0.05683206766843796,
0.015902694314718246,
-0.013852293603122234,
-0.055562566965818405,
0.07712426781654358,
-0.03243086487054825,
-0.04707501456141472,
-0.04022420570254326,
0.03604162484407425,
-0.000509353878442198,
0.05507281795144081,
-0.03888306766748428,
-0.06779806315898895,
-0.09650401771068573,
-0.02694731391966343,
-0.07567508518695831,
-0.05404302850365639,
-0.04247089847922325,
-0.05425485968589783,
0.04742622375488281,
0.045612551271915436,
0.13896897435188293,
-0.09473641961812973,
-0.04548954218626022,
-0.025625919923186302,
-0.0031379899010062218,
-0.009672214277088642,
0.003082041395828128,
0.06341677159070969,
-0.03634807839989662,
-0.011376166716217995,
-0.04571717232465744,
-0.016865231096744537,
0.003244823543354869,
-0.05745193734765053,
0.004045051522552967,
0.05900876596570015,
-0.004213940352201462,
-0.0020989913027733564,
-0.00041688879719004035,
0.07698418200016022,
-0.03648954629898071,
0.04073450714349747,
-0.00141562195494771,
0.04401678591966629,
0.0014927401207387447,
-0.05682006850838661,
-0.014905803836882114,
0.0801808163523674,
-0.02520672231912613,
0.0014357023173943162,
0.015395066700875759,
-5.648606204999851e-8,
-0.10581023246049881,
-0.10861238837242126,
-0.09322930872440338,
0.0032190082129091024,
0.03539502993226051,
-0.04052720591425896,
0.04740835353732109,
-0.05748434364795685,
0.02739429660141468,
-0.012791145592927933,
0.027369672432541847,
0.09113653749227524,
-0.0421043261885643,
-0.046035848557949066,
0.01558142714202404,
-0.01465142797678709,
0.002575381426140666,
0.01102236844599247,
-0.04339637979865074,
0.020891057327389717,
0.033464085310697556,
0.0491076298058033,
-0.007254120893776417,
0.05693766102194786,
0.009887320920825005,
-0.10453803837299347,
-0.0498349666595459,
-0.013034673407673836,
0.005803097039461136,
-0.050376325845718384,
0.003759085200726986,
-0.01592414639890194,
0.05635655298829079,
-0.022506138309836388,
-0.027511361986398697,
-0.05233972147107124,
0.0197367575019598,
-0.04813916236162186,
0.029822032898664474,
0.07868202775716782,
-0.003775919321924448,
0.012905950658023357,
0.006014054175466299,
-0.022334089502692223,
0.017353253439068794,
-0.07672568410634995,
-0.02177414670586586,
-0.012635832652449608,
0.04900042712688446,
-0.04888865351676941,
0.09223654121160507,
-0.015505635179579258,
0.003221038030460477,
-0.04385650157928467,
-0.048762280493974686,
-0.052126139402389526,
0.0019131156150251627,
0.035936977714300156,
-0.06704556941986084,
0.04555722326040268,
-0.012386200949549675,
-0.010602188296616077,
0.07507085800170898,
-0.04188968613743782
] | 0.095571
|
true }), ); ``` ```cjs const { inspect } = require('node:util'); const assert = require('node:assert'); const o1 = { b: [2, 3, 1], a: '`a` comes before `b`', c: new Set([2, 3, 1]), }; console.log(inspect(o1, { sorted: true })); // { a: '`a` comes before `b`', b: [ 2, 3, 1 ], c: Set(3) { 1, 2, 3 } } console.log(inspect(o1, { sorted: (a, b) => b.localeCompare(a) })); // { c: Set(3) { 3, 2, 1 }, b: [ 2, 3, 1 ], a: '`a` comes before `b`' } const o2 = { c: new Set([2, 1, 3]), a: '`a` comes before `b`', b: [2, 3, 1], }; assert.strict.equal( inspect(o1, { sorted: true }), inspect(o2, { sorted: true }), ); ``` The `numericSeparator` option adds an underscore every three digits to all numbers. ```mjs import { inspect } from 'node:util'; const thousand = 1000; const million = 1000000; const bigNumber = 123456789n; const bigDecimal = 1234.12345; console.log(inspect(thousand, { numericSeparator: true })); // 1\_000 console.log(inspect(million, { numericSeparator: true })); // 1\_000\_000 console.log(inspect(bigNumber, { numericSeparator: true })); // 123\_456\_789n console.log(inspect(bigDecimal, { numericSeparator: true })); // 1\_234.123\_45 ``` ```cjs const { inspect } = require('node:util'); const thousand = 1000; const million = 1000000; const bigNumber = 123456789n; const bigDecimal = 1234.12345; console.log(inspect(thousand, { numericSeparator: true })); // 1\_000 console.log(inspect(million, { numericSeparator: true })); // 1\_000\_000 console.log(inspect(bigNumber, { numericSeparator: true })); // 123\_456\_789n console.log(inspect(bigDecimal, { numericSeparator: true })); // 1\_234.123\_45 ``` `util.inspect()` is a synchronous method intended for debugging. Its maximum output length is approximately 128 MiB. Inputs that result in longer output will be truncated. ### Customizing `util.inspect` colors Color output (if enabled) of `util.inspect` is customizable globally via the `util.inspect.styles` and `util.inspect.colors` properties. `util.inspect.styles` is a map associating a style name to a color from `util.inspect.colors`. The default styles and associated colors are: \* `bigint`: `yellow` \* `boolean`: `yellow` \* `date`: `magenta` \* `module`: `underline` \* `name`: (no styling) \* `null`: `bold` \* `number`: `yellow` \* `regexp`: A method that colors character classes, groups, assertions, and other parts for improved readability. To customize the coloring, change the `colors` property. It is set to `['red', 'green', 'yellow', 'cyan', 'magenta']` by default and may be adjusted as needed. The array is repetitively iterated through depending on the "depth". \* `special`: `cyan` (e.g., `Proxies`) \* `string`: `green` \* `symbol`: `green` \* `undefined`: `grey` Color styling uses ANSI control codes that may not be supported on all terminals. To verify color support use [`tty.hasColors()`][]. Predefined control codes are listed below (grouped as "Modifiers", "Foreground colors", and "Background colors"). #### Complex custom coloring It is possible to define a method as style. It receives the stringified value of the input. It is invoked in case coloring is active and the type is inspected. Example: `util.inspect.styles.regexp(value)` \* `value` {string} The string representation of the input type. \* Returns: {string} The adjusted representation of `object`. #### Modifiers Modifier support varies throughout different terminals. They will mostly be ignored, if not supported. \* `reset` - Resets all (color) modifiers to their defaults \* \*\*bold\*\* - Make text bold \* \_italic\_ - Make text italic \* underline - Make text underlined \* ~~strikethrough~~ - Puts a horizontal line through the center of the text (Alias: `strikeThrough`, `crossedout`, `crossedOut`) \* `hidden` - Prints the text, but makes it invisible (Alias: conceal) \* dim - Decreased color intensity (Alias: `faint`) \* overlined - Make text overlined \* blink - Hides and shows the text in an interval \* inverse - Swap foreground and background colors (Alias: `swapcolors`, `swapColors`) \* doubleunderline - Make text double underlined (Alias: `doubleUnderline`) \* framed - Draw a frame
|
https://github.com/nodejs/node/blob/main//doc/api/util.md
|
main
|
nodejs
|
[
-0.05107889324426651,
0.0430891215801239,
0.03498721867799759,
-0.0019616312347352505,
0.018735190853476524,
-0.05194316804409027,
0.005482136271893978,
-0.05021842196583748,
0.0052533759735524654,
-0.014507601968944073,
-0.04768098518252373,
0.05238347128033638,
0.008757482282817364,
-0.013834908604621887,
0.010439886711537838,
0.07888167351484299,
-0.04945872724056244,
0.03043326921761036,
-0.015110671520233154,
-0.1209992915391922,
0.004771288484334946,
-0.017881520092487335,
-0.046807911247015,
-0.04523051530122757,
0.015431350097060204,
-0.007684105541557074,
-0.03877490013837814,
0.041945360600948334,
0.0918746143579483,
-0.03834213316440582,
-0.012597578577697277,
-0.01884608156979084,
-0.0049779112450778484,
0.07339639216661453,
-0.016983186826109886,
0.07050660252571106,
-0.023994579911231995,
-0.07508767396211624,
0.0067924680188298225,
0.04892325773835182,
-0.008695017546415329,
0.10544735193252563,
-0.010107000358402729,
-0.024683963507413864,
0.03002803400158882,
0.09000055491924286,
-0.06183146685361862,
0.061225906014442444,
-0.10082794725894928,
-0.036692455410957336,
-0.05085292086005211,
-0.036305852234363556,
-0.06009581312537193,
-0.06403908133506775,
0.014064201153814793,
0.020061032846570015,
0.017610883340239525,
-0.09110619872808456,
0.05273032188415527,
0.034903381019830704,
-0.02172263152897358,
-0.018285876139998436,
0.03792494907975197,
-0.013812141492962837,
0.09216488897800446,
0.024167994037270546,
0.040471870452165604,
0.06857933849096298,
0.056327082216739655,
0.11852337419986725,
-0.055494870990514755,
0.042719099670648575,
0.02117447555065155,
0.014476459473371506,
-0.047828368842601776,
-0.010906661860644817,
0.0321541465818882,
0.010123209096491337,
-0.1054053008556366,
-0.010316738858819008,
-0.11184494942426682,
0.0051802159287035465,
-0.022066548466682434,
0.05914020538330078,
-0.015734393149614334,
-0.03552969917654991,
-0.021081604063510895,
-0.08390088379383087,
0.019445234909653664,
0.04268015921115875,
-0.1074984148144722,
-0.08052976429462433,
-0.03419040888547897,
0.07531143724918365,
0.07153049111366272,
0.005261356942355633,
0.15473510324954987,
0.038929618895053864,
0.04678991436958313,
0.05854839086532593,
-0.033914465457201004,
0.03720047324895859,
0.02767104282975197,
-0.028105497360229492,
-0.03240160271525383,
-0.009492447599768639,
-0.0717671737074852,
-0.08583768457174301,
-0.02379610203206539,
-0.050781600177288055,
0.08605892956256866,
-0.0172139722853899,
0.01652044802904129,
0.00004590722164721228,
-0.03002941980957985,
0.01052940171211958,
0.0759735032916069,
-0.03690715134143829,
0.06949552148580551,
0.05045199394226074,
0.07140679657459259,
0.02851388230919838,
0.10240071266889572,
-0.039900075644254684,
-0.01302937138825655,
-0.030736582353711128,
0.012093456462025642,
3.680430200754365e-33,
0.01612568087875843,
-0.059748634696006775,
-0.005741099826991558,
-0.01011774130165577,
-0.016581065952777863,
0.06845352798700333,
0.046371906995773315,
-0.08853019028902054,
-0.13570387661457062,
0.04050523415207863,
-0.0017294028075411916,
0.048615556210279465,
-0.016102878376841545,
-0.0008407472632825375,
0.01931258663535118,
-0.03399519994854927,
0.13895289599895477,
-0.03457101806998253,
-0.04697706177830696,
-0.008611179888248444,
0.006871737074106932,
-0.026618899777531624,
-0.049299269914627075,
-0.03358311951160431,
-0.0004198771493975073,
-0.09344969689846039,
0.020974386483430862,
-0.012274112552404404,
-0.016657672822475433,
-0.034954555332660675,
0.0001294231042265892,
0.055131055414676666,
0.005376487970352173,
0.09678965061903,
0.048348765820264816,
0.011816234327852726,
0.020951993763446808,
-0.024774422869086266,
-0.003368146251887083,
-0.11046639084815979,
0.05322504788637161,
0.023104239255189896,
-0.00015953771071508527,
0.010783080942928791,
0.04500935599207878,
-0.08932603150606155,
-0.1265469491481781,
-0.0020211003720760345,
0.07434181123971939,
-0.02934880554676056,
-0.005475193727761507,
0.018278436735272408,
0.052417706698179245,
-0.007664010860025883,
0.016353700309991837,
-0.034445688128471375,
0.03128243237733841,
-0.00900410208851099,
-0.005182972177863121,
0.0953744575381279,
0.0697537437081337,
0.00968277920037508,
-0.05794657766819,
0.09980963170528412,
-0.09167365729808807,
0.01705671288073063,
-0.03539353236556053,
0.0067525762133300304,
0.11407463252544403,
0.041122134774923325,
-0.05349206179380417,
0.03563535585999489,
-0.029175011441111565,
0.03236331045627594,
-0.014001731760799885,
0.018114401027560234,
-0.09358096867799759,
-0.00891076773405075,
-0.05746173486113548,
-0.13724318146705627,
0.051563482731580734,
0.011955936439335346,
0.015169682912528515,
0.0888327807188034,
-0.009280350990593433,
0.002175922505557537,
-0.054121408611536026,
-0.0017138513503596187,
0.02235400676727295,
-0.028307123109698296,
-0.0713207796216011,
0.007962270639836788,
0.08041759580373764,
-0.08304381370544434,
-0.022557493299245834,
-4.0243038080141474e-33,
0.03884220868349075,
0.046154677867889404,
0.08552920073270798,
0.06871962547302246,
0.014421035535633564,
-0.13794557750225067,
-0.018890520557761192,
-0.08698496967554092,
0.02499156817793846,
0.07142596691846848,
-0.017562272027134895,
0.030204327777028084,
0.05928734317421913,
-0.05291697010397911,
0.06694081425666809,
0.01811944507062435,
-0.050976239144802094,
-0.09870854020118713,
0.039654798805713654,
-0.004076523240655661,
0.03921011835336685,
-0.025589067488908768,
0.0755477249622345,
-0.001538654207251966,
-0.037820082157850266,
0.03185928612947464,
0.06850938498973846,
0.020728962495923042,
-0.051413580775260925,
-0.051238756626844406,
-0.04126442223787308,
0.005333996377885342,
-0.03959094360470772,
0.04716687276959419,
0.012354669161140919,
-0.06780942529439926,
0.04840610921382904,
0.03962858393788338,
-0.00470316456630826,
0.002460513962432742,
0.02060430869460106,
0.037203576415777206,
-0.04502277448773384,
-0.0014208914944902062,
0.013552837073802948,
0.011939252726733685,
-0.021114125847816467,
0.039235226809978485,
-0.015628619119524956,
-0.08017062395811081,
-0.05150511860847473,
0.0253059733659029,
-0.0019911681301891804,
-0.03006681054830551,
-0.03231316804885864,
-0.058219995349645615,
-0.06068907305598259,
-0.011427512392401695,
0.09233398735523224,
-0.004578421823680401,
0.017875781282782555,
-0.092443086206913,
0.04174269735813141,
0.053718894720077515,
0.023895137012004852,
-0.028161965310573578,
-0.11537134647369385,
0.011803314089775085,
0.04771159589290619,
0.00016001051699277014,
-0.011618553660809994,
0.053494296967983246,
-0.056218985468149185,
-0.08823136240243912,
-0.031104959547519684,
-0.03727308288216591,
-0.009552696719765663,
-0.04432133957743645,
0.024898316711187363,
0.02771703153848648,
-0.07353188097476959,
0.011443225666880608,
-0.04114033281803131,
0.09576220065355301,
-0.03994996100664139,
0.04461914300918579,
0.06034195423126221,
0.020218515768647194,
0.01757488027215004,
0.017356105148792267,
-0.0021345987915992737,
0.033730633556842804,
-0.017224470153450966,
-0.020298847928643227,
-0.04559365659952164,
-4.2871782568454364e-8,
-0.06708197295665741,
-0.11827537417411804,
-0.03631255403161049,
0.020236343145370483,
0.0013766040792688727,
-0.07045776396989822,
0.05336114019155502,
0.07103588432073593,
-0.04135874658823013,
-0.02262044884264469,
0.03015914000570774,
0.07527069747447968,
0.03601633012294769,
-0.06082947924733162,
0.007205350324511528,
0.03159022331237793,
-0.028208497911691666,
-0.0757390484213829,
-0.04260433465242386,
-0.010030954144895077,
0.00524464575573802,
0.01902586966753006,
0.08905275911092758,
0.11854592710733414,
0.004100693855434656,
-0.06735802441835403,
0.045001160353422165,
0.014604258351027966,
0.06955071538686752,
0.037103503942489624,
-0.030466070398688316,
0.05133412778377533,
0.08863365650177002,
-0.01192998606711626,
0.02206687070429325,
-0.016789279878139496,
-0.060220927000045776,
0.04661773517727852,
-0.0023107577580958605,
0.014220618642866611,
-0.025773076340556145,
-0.011328685097396374,
-0.012736895121634007,
0.0618048720061779,
0.0016367931384593248,
-0.10689948499202728,
-0.05810125172138214,
-0.008628197945654392,
0.039277832955121994,
-0.06805961579084396,
-0.010167917236685753,
0.008203227072954178,
-0.011521218344569206,
0.037474725395441055,
-0.024323752149939537,
0.0010927139082923532,
-0.057415254414081573,
0.002758386544883251,
0.0493256114423275,
0.024003295227885246,
0.005053466185927391,
0.02215508744120598,
0.07162976264953613,
0.02553626149892807
] | 0.058943
|
dim - Decreased color intensity (Alias: `faint`) \* overlined - Make text overlined \* blink - Hides and shows the text in an interval \* inverse - Swap foreground and background colors (Alias: `swapcolors`, `swapColors`) \* doubleunderline - Make text double underlined (Alias: `doubleUnderline`) \* framed - Draw a frame around the text #### Foreground colors \* `black` \* `red` \* `green` \* `yellow` \* `blue` \* `magenta` \* `cyan` \* `white` \* `gray` (alias: `grey`, `blackBright`) \* `redBright` \* `greenBright` \* `yellowBright` \* `blueBright` \* `magentaBright` \* `cyanBright` \* `whiteBright` #### Background colors \* `bgBlack` \* `bgRed` \* `bgGreen` \* `bgYellow` \* `bgBlue` \* `bgMagenta` \* `bgCyan` \* `bgWhite` \* `bgGray` (alias: `bgGrey`, `bgBlackBright`) \* `bgRedBright` \* `bgGreenBright` \* `bgYellowBright` \* `bgBlueBright` \* `bgMagentaBright` \* `bgCyanBright` \* `bgWhiteBright` ### Custom inspection functions on objects Objects may also define their own [`[util.inspect.custom](depth, opts, inspect)`][util.inspect.custom] function, which `util.inspect()` will invoke and use the result of when inspecting the object. ```mjs import { inspect } from 'node:util'; class Box { constructor(value) { this.value = value; } [inspect.custom](depth, options, inspect) { if (depth < 0) { return options.stylize('[Box]', 'special'); } const newOptions = Object.assign({}, options, { depth: options.depth === null ? null : options.depth - 1, }); // Five space padding because that's the size of "Box< ". const padding = ' '.repeat(5); const inner = inspect(this.value, newOptions) .replace(/\n/g, `\n${padding}`); return `${options.stylize('Box', 'special')}< ${inner} >`; } } const box = new Box(true); console.log(inspect(box)); // "Box< true >" ``` ```cjs const { inspect } = require('node:util'); class Box { constructor(value) { this.value = value; } [inspect.custom](depth, options, inspect) { if (depth < 0) { return options.stylize('[Box]', 'special'); } const newOptions = Object.assign({}, options, { depth: options.depth === null ? null : options.depth - 1, }); // Five space padding because that's the size of "Box< ". const padding = ' '.repeat(5); const inner = inspect(this.value, newOptions) .replace(/\n/g, `\n${padding}`); return `${options.stylize('Box', 'special')}< ${inner} >`; } } const box = new Box(true); console.log(inspect(box)); // "Box< true >" ``` Custom `[util.inspect.custom](depth, opts, inspect)` functions typically return a string but may return a value of any type that will be formatted accordingly by `util.inspect()`. ```mjs import { inspect } from 'node:util'; const obj = { foo: 'this will not show up in the inspect() output' }; obj[inspect.custom] = (depth) => { return { bar: 'baz' }; }; console.log(inspect(obj)); // "{ bar: 'baz' }" ``` ```cjs const { inspect } = require('node:util'); const obj = { foo: 'this will not show up in the inspect() output' }; obj[inspect.custom] = (depth) => { return { bar: 'baz' }; }; console.log(inspect(obj)); // "{ bar: 'baz' }" ``` ### `util.inspect.custom` \* Type: {symbol} that can be used to declare custom inspect functions. In addition to being accessible through `util.inspect.custom`, this symbol is [registered globally][global symbol registry] and can be accessed in any environment as `Symbol.for('nodejs.util.inspect.custom')`. Using this allows code to be written in a portable fashion, so that the custom inspect function is used in an Node.js environment and ignored in the browser. The `util.inspect()` function itself is passed as third argument to the custom inspect function to allow further portability. ```js const customInspectSymbol = Symbol.for('nodejs.util.inspect.custom'); class Password { constructor(value) { this.value = value; } toString() { return 'xxxxxxxx'; } [customInspectSymbol](depth, inspectOptions, inspect) { return `Password <${this.toString()}>`; } } const password = new Password('r0sebud'); console.log(password); // Prints Password ``` See [Custom inspection functions on Objects][] for more details. ### `util.inspect.defaultOptions` The `defaultOptions` value allows customization of the default options used by `util.inspect`. This is useful for functions like `console.log` or `util.format` which implicitly call into `util.inspect`. It shall be set to an
|
https://github.com/nodejs/node/blob/main//doc/api/util.md
|
main
|
nodejs
|
[
-0.02289300411939621,
-0.009721571579575539,
0.07218818366527557,
0.05239739269018173,
-0.0018935886910185218,
-0.020445022732019424,
0.07332094758749008,
0.04158593714237213,
-0.020826326683163643,
-0.079587422311306,
-0.01722155511379242,
-0.007188563700765371,
0.03998751938343048,
-0.061806272715330124,
-0.012859279289841652,
0.12434910237789154,
0.020421810448169708,
-0.022211149334907532,
-0.12142365425825119,
-0.030262742191553116,
0.015543993562459946,
-0.027388116344809532,
-0.016109062358736992,
0.0014630735386162996,
0.0001382123155053705,
0.04172409698367119,
-0.032628268003463745,
0.05317765846848488,
-0.02021687664091587,
-0.07626242935657501,
-0.04234498739242554,
0.07381580770015717,
0.07047808170318604,
0.0417913980782032,
0.011149032041430473,
-0.034841179847717285,
0.0005913485656492412,
0.07923520356416702,
-0.039475634694099426,
0.019655153155326843,
-0.01914498209953308,
-0.0325363464653492,
0.0008116267854347825,
0.039743535220623016,
0.02261306159198284,
-0.05068543180823326,
-0.001564632635563612,
-0.07405555248260498,
-0.07035645842552185,
-0.050998345017433167,
-0.01010159496217966,
-0.03659680485725403,
-0.0113346166908741,
0.04150871932506561,
-0.00025376654230058193,
0.08084340393543243,
-0.038499049842357635,
-0.016610875725746155,
0.06331875920295715,
-0.03566918894648552,
-0.054024312645196915,
0.014758196659386158,
-0.004735742695629597,
0.0017123034922406077,
-0.017562517896294594,
0.060952961444854736,
-0.06419268995523453,
-0.015385424718260765,
0.011351981200277805,
0.01378115825355053,
-0.02678006887435913,
0.01053305622190237,
-0.01787148229777813,
-0.004993798676878214,
-0.050065550953149796,
-0.016014110296964645,
0.005891401320695877,
-0.008983255364000797,
-0.04492010921239853,
-0.09120934456586838,
-0.0018659321358427405,
-0.032107867300510406,
-0.02122567407786846,
0.09753517806529999,
0.11346488445997238,
0.03462103381752968,
0.028110360726714134,
-0.04848639294505119,
-0.08267419785261154,
0.03056979551911354,
-0.0016990514704957604,
0.02766496315598488,
0.05682428181171417,
0.02443000115454197,
-0.10018319636583328,
0.037126343697309494,
0.06913207471370697,
-0.06505616009235382,
0.06482388824224472,
0.07029315084218979,
-0.010748883709311485,
-0.06711726635694504,
0.015764057636260986,
0.021231720224022865,
-0.05391516536474228,
0.011991733685135841,
0.0827113464474678,
0.055145785212516785,
0.003318545175716281,
-0.042611993849277496,
0.07733142375946045,
-0.05947650223970413,
-0.0022758999839425087,
-0.02915394864976406,
0.03769155591726303,
0.03139878436923027,
0.0768020898103714,
0.025398777797818184,
0.04452502727508545,
-0.02304117940366268,
0.058044325560331345,
0.00775763439014554,
-0.05025297775864601,
-0.03382489085197449,
-0.0977659747004509,
-0.028293371200561523,
0.03097780980169773,
5.3419393030798505e-33,
0.022553682327270508,
0.00459203589707613,
-0.07375306636095047,
-0.002682784106582403,
0.12209626287221909,
0.05275965481996536,
-0.07387902587652206,
-0.02691374346613884,
-0.07498765736818314,
0.023826969787478447,
0.036565061658620834,
-0.0037366156466305256,
-0.03201545029878616,
0.05000799894332886,
-0.05707554146647453,
-0.09894204139709473,
0.13643081486225128,
0.006362332031130791,
-0.032615311443805695,
0.03363887593150139,
-0.05849785730242729,
0.03555513545870781,
0.004122494254261255,
-0.062090177088975906,
0.011263098567724228,
0.04287613183259964,
0.06241726130247116,
0.026547128334641457,
0.02838422916829586,
-0.005364722106605768,
-0.00047646157327108085,
0.00938402209430933,
0.05610891804099083,
0.048268914222717285,
-0.09564492106437683,
0.026261724531650543,
-0.016611602157354355,
0.016597021371126175,
0.035362254828214645,
0.09875034540891647,
-0.15060436725616455,
0.06140792369842529,
0.023325635120272636,
-0.031292177736759186,
0.06522369384765625,
0.043959591537714005,
0.003454064717516303,
0.11554379016160965,
-0.01571814902126789,
0.05711909011006355,
-0.07641984522342682,
-0.0023896819911897182,
0.02846050076186657,
-0.04227084666490555,
0.014169475995004177,
-0.019142713397741318,
-0.024134602397680283,
0.04069593921303749,
0.04704147204756737,
0.06043310463428497,
0.060721613466739655,
0.05147935450077057,
-0.006015552207827568,
-0.0440615676343441,
0.058118514716625214,
0.013583624735474586,
0.006001224275678396,
0.005928912200033665,
-0.05905692279338837,
-0.025809315964579582,
-0.0762314721941948,
0.029773134738206863,
0.02887781895697117,
0.04070473834872246,
0.01224751677364111,
-0.05692753568291664,
-0.022463984787464142,
-0.04858680069446564,
0.024664482101798058,
-0.05516809970140457,
-0.06621240079402924,
-0.008285915479063988,
-0.0051599182188510895,
-0.06559080630540848,
-0.01315521914511919,
-0.06981036812067032,
-0.024276461452245712,
0.03341986611485481,
-0.09847123920917511,
-0.05224612355232239,
-0.06041831895709038,
-0.0659375861287117,
0.029169753193855286,
-0.07143441587686539,
-0.0479721762239933,
-6.118163038649932e-33,
0.10728762298822403,
0.09135256707668304,
-0.017819983884692192,
0.06050190329551697,
0.019656147807836533,
0.05568460375070572,
0.05707146227359772,
0.009915615431964397,
0.0009712298633530736,
0.01661086268723011,
0.06636511534452438,
0.10196429491043091,
-0.10915417969226837,
-0.000720032025128603,
-0.01565956510603428,
0.029489455744624138,
0.00202559563331306,
0.08646803349256516,
-0.05829937756061554,
-0.011201300658285618,
-0.03361288830637932,
0.04616160690784454,
-0.07266368716955185,
0.05762900784611702,
-0.059613265097141266,
0.04063478484749794,
0.009661508724093437,
0.0157437976449728,
-0.09590104222297668,
0.0517694465816021,
-0.052057284861803055,
0.028629906475543976,
-0.10563340783119202,
-0.04889938607811928,
0.03163108229637146,
-0.02917489968240261,
-0.014793588779866695,
-0.10617227852344513,
-0.0917569175362587,
0.0037512565031647682,
0.028087301179766655,
0.026590818539261818,
0.0006941769970580935,
-0.018252931535243988,
-0.01815507374703884,
0.03460536152124405,
-0.12511231005191803,
-0.001172260264866054,
-0.020636899396777153,
-0.006032274104654789,
0.011881588958203793,
-0.0010800654999911785,
0.0027738858480006456,
0.08566900342702866,
-0.019012393429875374,
-0.07614357769489288,
-0.0008303641807287931,
0.06089332327246666,
-0.007966112345457077,
0.021744217723608017,
-0.016362739726901054,
-0.04803294688463211,
-0.06322538107633591,
-0.03938870504498482,
0.05674413591623306,
-0.031091734766960144,
0.041138190776109695,
-0.00824078917503357,
0.02354646846652031,
-0.04308348149061203,
0.06268096715211868,
-0.06384074687957764,
-0.11094121634960175,
-0.027162853628396988,
0.01263400074094534,
-0.02502044104039669,
0.030129792168736458,
-0.014750220812857151,
-0.060912635177373886,
0.12355759739875793,
0.06142210215330124,
-0.02459920570254326,
0.070978082716465,
-0.009313498623669147,
-0.07678239792585373,
0.04289178177714348,
-0.054726894944906235,
0.11806705594062805,
0.03730262443423271,
-0.09191524982452393,
-0.05862301588058472,
0.05425234138965607,
0.029365576803684235,
0.022235823795199394,
-0.046938687562942505,
-5.1861945848941104e-8,
0.012508341111242771,
-0.025799259543418884,
-0.012165877036750317,
-0.01637093909084797,
-0.025490062311291695,
-0.07712087035179138,
-0.04969650134444237,
-0.028657162562012672,
-0.04568476974964142,
-0.08642467111349106,
0.019564667716622353,
-0.008815154433250427,
-0.004421495366841555,
-0.02872483618557453,
0.05862933397293091,
0.01735623925924301,
-0.06243383511900902,
0.07945169508457184,
-0.007801535539329052,
-0.011097431182861328,
-0.009638862684369087,
0.020130423828959465,
-0.01513150054961443,
0.022248076274991035,
-0.028508277609944344,
-0.02472512796521187,
-0.009513283148407936,
0.03500517085194588,
0.03330105170607567,
0.0022957944311201572,
0.1360424906015396,
0.02724880911409855,
0.08266337960958481,
-0.008472922258079052,
-0.014526396989822388,
-0.044476915150880814,
-0.021868819370865822,
-0.0193895623087883,
0.0008845621487125754,
0.047136057168245316,
-0.0595366507768631,
-0.10977417975664139,
0.006333644036203623,
0.016828365623950958,
0.04130994901061058,
-0.10240735858678818,
0.05753595754504204,
-0.028517117723822594,
-0.01832231879234314,
-0.030166195705533028,
-0.02775745280086994,
0.02751089446246624,
0.027603009715676308,
0.015612712129950523,
-0.0067307427525520325,
-0.07411900907754898,
0.008818994276225567,
0.18708005547523499,
-0.06532832980155945,
0.005303298123180866,
0.037458501756191254,
-0.014410154893994331,
-0.01699400134384632,
-0.037599071860313416
] | 0.048798
|
new Password('r0sebud'); console.log(password); // Prints Password ``` See [Custom inspection functions on Objects][] for more details. ### `util.inspect.defaultOptions` The `defaultOptions` value allows customization of the default options used by `util.inspect`. This is useful for functions like `console.log` or `util.format` which implicitly call into `util.inspect`. It shall be set to an object containing one or more valid [`util.inspect()`][] options. Setting option properties directly is also supported. ```mjs import { inspect } from 'node:util'; const arr = Array(156).fill(0); console.log(arr); // Logs the truncated array inspect.defaultOptions.maxArrayLength = null; console.log(arr); // logs the full array ``` ```cjs const { inspect } = require('node:util'); const arr = Array(156).fill(0); console.log(arr); // Logs the truncated array inspect.defaultOptions.maxArrayLength = null; console.log(arr); // logs the full array ``` ## `util.isDeepStrictEqual(val1, val2[, options])` \* `val1` {any} \* `val2` {any} \* `skipPrototype` {boolean} If `true`, prototype and constructor comparison is skipped during deep strict equality check. \*\*Default:\*\* `false`. \* Returns: {boolean} Returns `true` if there is deep strict equality between `val1` and `val2`. Otherwise, returns `false`. By default, deep strict equality includes comparison of object prototypes and constructors. When `skipPrototype` is `true`, objects with different prototypes or constructors can still be considered equal if their enumerable properties are deeply strictly equal. ```js const util = require('node:util'); class Foo { constructor(a) { this.a = a; } } class Bar { constructor(a) { this.a = a; } } const foo = new Foo(1); const bar = new Bar(1); // Different constructors, same properties console.log(util.isDeepStrictEqual(foo, bar)); // false console.log(util.isDeepStrictEqual(foo, bar, true)); // true ``` See [`assert.deepStrictEqual()`][] for more information about deep strict equality. ## Class: `util.MIMEType` An implementation of [the MIMEType class](https://bmeck.github.io/node-proposal-mime-api/). In accordance with browser conventions, all properties of `MIMEType` objects are implemented as getters and setters on the class prototype, rather than as data properties on the object itself. A MIME string is a structured string containing multiple meaningful components. When parsed, a `MIMEType` object is returned containing properties for each of these components. ### `new MIMEType(input)` \* `input` {string} The input MIME to parse Creates a new `MIMEType` object by parsing the `input`. ```mjs import { MIMEType } from 'node:util'; const myMIME = new MIMEType('text/plain'); ``` ```cjs const { MIMEType } = require('node:util'); const myMIME = new MIMEType('text/plain'); ``` A `TypeError` will be thrown if the `input` is not a valid MIME. Note that an effort will be made to coerce the given values into strings. For instance: ```mjs import { MIMEType } from 'node:util'; const myMIME = new MIMEType({ toString: () => 'text/plain' }); console.log(String(myMIME)); // Prints: text/plain ``` ```cjs const { MIMEType } = require('node:util'); const myMIME = new MIMEType({ toString: () => 'text/plain' }); console.log(String(myMIME)); // Prints: text/plain ``` ### `mime.type` \* Type: {string} Gets and sets the type portion of the MIME. ```mjs import { MIMEType } from 'node:util'; const myMIME = new MIMEType('text/javascript'); console.log(myMIME.type); // Prints: text myMIME.type = 'application'; console.log(myMIME.type); // Prints: application console.log(String(myMIME)); // Prints: application/javascript ``` ```cjs const { MIMEType } = require('node:util'); const myMIME = new MIMEType('text/javascript'); console.log(myMIME.type); // Prints: text myMIME.type = 'application'; console.log(myMIME.type); // Prints: application console.log(String(myMIME)); // Prints: application/javascript ``` ### `mime.subtype` \* Type: {string} Gets and sets the subtype portion of the MIME. ```mjs import { MIMEType } from 'node:util'; const myMIME = new MIMEType('text/ecmascript'); console.log(myMIME.subtype); // Prints: ecmascript myMIME.subtype = 'javascript'; console.log(myMIME.subtype); // Prints: javascript console.log(String(myMIME)); // Prints: text/javascript ``` ```cjs const { MIMEType } = require('node:util'); const myMIME = new MIMEType('text/ecmascript'); console.log(myMIME.subtype); // Prints: ecmascript myMIME.subtype = 'javascript'; console.log(myMIME.subtype); // Prints: javascript console.log(String(myMIME)); // Prints: text/javascript ``` ### `mime.essence` \* Type: {string} Gets the essence of the MIME. This property is read only. Use `mime.type` or
|
https://github.com/nodejs/node/blob/main//doc/api/util.md
|
main
|
nodejs
|
[
-0.003955797292292118,
0.10428299009799957,
-0.05416366085410118,
0.02813704125583172,
-0.03517995402216911,
-0.032824113965034485,
0.0323583222925663,
0.08067040145397186,
-0.01203934382647276,
0.03429572284221649,
-0.05602290853857994,
0.016118556261062622,
-0.025414282456040382,
0.03943517059087753,
0.03583773970603943,
0.03288067877292633,
-0.05593566223978996,
0.04169832915067673,
-0.0036419322714209557,
-0.011575104668736458,
0.03189372643828392,
-0.07770814001560211,
0.0237385593354702,
-0.09233178198337555,
-0.04722249507904053,
0.010856890119612217,
0.06117631494998932,
0.01333690993487835,
0.003651478560641408,
-0.023293334990739822,
0.027105649933218956,
0.02458457089960575,
0.03334102779626846,
0.013360080309212208,
-0.08420464396476746,
0.08938303589820862,
-0.058945994824171066,
-0.07653922587633133,
0.02387894317507744,
-0.027555136010050774,
-0.03226476162672043,
0.12391512095928192,
-0.06663692742586136,
0.018068348988890648,
-0.03486331179738045,
0.018229039385914803,
-0.04241989925503731,
0.03129325807094574,
-0.004771206062287092,
0.005883912090212107,
0.025015078485012054,
0.030382949858903885,
0.04622119292616844,
-0.06475436687469482,
0.04356708377599716,
-0.03705581650137901,
-0.05481618270277977,
-0.05042463168501854,
0.09094224125146866,
-0.01505131646990776,
-0.0027238482143729925,
0.016482800245285034,
0.054108742624521255,
0.019130997359752655,
-0.021612489596009254,
0.048418138176202774,
-0.017524845898151398,
0.04047127813100815,
0.04561879485845566,
0.08916737884283066,
-0.027975575998425484,
-0.010544942691922188,
-0.01649041660130024,
-0.019514409825205803,
-0.01584986411035061,
0.032015733420848846,
-0.043836433440446854,
-0.004268256016075611,
-0.024447064846754074,
0.01127113401889801,
-0.11037056148052216,
-0.027139779180288315,
0.004401327110826969,
0.10994087159633636,
-0.024164827540516853,
0.13798686861991882,
-0.09196624904870987,
0.02233014814555645,
0.06991484016180038,
0.01875903457403183,
0.006042580585926771,
-0.11400599032640457,
-0.13738499581813812,
-0.008715122006833553,
-0.022152721881866455,
-0.02283317595720291,
0.02500826120376587,
-0.011246939189732075,
-0.12592612206935883,
0.026469487696886063,
0.007950332015752792,
-0.029306266456842422,
0.06835498660802841,
-0.013495068997144699,
0.025254901498556137,
-0.024990513920783997,
0.03283601999282837,
-0.03779198229312897,
0.016189303249120712,
0.07801499962806702,
0.005684457719326019,
0.12201210111379623,
0.00024232619034592062,
-0.026234595105051994,
0.08081720769405365,
0.05742514878511429,
0.05503349006175995,
-0.007701460272073746,
0.026912085711956024,
0.1301264762878418,
0.08880793303251266,
-0.000052606705139623955,
-0.028409095481038094,
-0.026552774012088776,
0.09031383693218231,
0.02778949774801731,
-0.020282946527004242,
2.576609046579574e-33,
0.013571144081652164,
-0.028873134404420853,
0.04020112380385399,
0.02642953209578991,
-0.01583903282880783,
0.05206237733364105,
0.0591902956366539,
0.014875423163175583,
-0.03438307344913483,
0.045888058841228485,
-0.04715663567185402,
0.05323884263634682,
0.02308625355362892,
-0.07601658999919891,
0.018739191815257072,
0.05764729902148247,
-0.011970209889113903,
0.01807926595211029,
0.06616844236850739,
-0.0014104278525337577,
-0.04013828560709953,
-0.0027263483498245478,
0.033993177115917206,
-0.029207028448581696,
0.02871817722916603,
-0.06972141563892365,
0.026372486725449562,
0.0066484264098107815,
-0.07847360521554947,
-0.017893295735120773,
0.023066533729434013,
0.05239280313253403,
0.011773744598031044,
0.06431493908166885,
0.008054406382143497,
-0.031147966161370277,
-0.005359400529414415,
0.04501480609178543,
-0.11655066907405853,
-0.038911640644073486,
-0.0026299338787794113,
-0.03431554511189461,
-0.003673763480037451,
0.03014640510082245,
-0.02179608680307865,
-0.05558211728930473,
-0.04509805887937546,
0.030303940176963806,
0.054589685052633286,
-0.005672241561114788,
-0.07523731887340546,
0.13693292438983917,
-0.05319967493414879,
-0.06319441646337509,
0.011192906647920609,
0.01914963126182556,
0.015365262515842915,
-0.010391142219305038,
-0.05766434967517853,
-0.08044774830341339,
0.03757914900779724,
0.021324964240193367,
0.02907855063676834,
0.03340940922498703,
-0.012365292757749557,
-0.008445680141448975,
0.0064916666597127914,
-0.049438849091529846,
0.04443362355232239,
0.026972739025950432,
-0.07533891499042511,
-0.008546116761863232,
-0.003918806090950966,
0.008786603808403015,
-0.0397397056221962,
0.013530601747334003,
0.030259814113378525,
0.015852097421884537,
0.08785028010606766,
-0.08959594368934631,
0.08795228600502014,
-0.007179755251854658,
-0.029312826693058014,
0.06772419810295105,
0.025955969467759132,
-0.05624964460730553,
-0.0012501530582085252,
-0.017288653180003166,
0.018938682973384857,
-0.014218470081686974,
0.02976153790950775,
-0.03588331118226051,
-0.0255141444504261,
-0.11769206821918488,
-0.09462800621986389,
-4.228680398635895e-33,
0.03210682049393654,
-0.04591713845729828,
0.021303920075297356,
0.0828901007771492,
-0.05048637092113495,
-0.02758878655731678,
0.04413094371557236,
0.03160226345062256,
-0.014722679741680622,
-0.017925234511494637,
0.012720062397420406,
0.04744037240743637,
-0.027693336829543114,
0.0023585036396980286,
0.04857320711016655,
0.053833916783332825,
-0.15435642004013062,
-0.006874686572700739,
0.05084633827209473,
-0.08008838444948196,
-0.019198575988411903,
0.02618723176419735,
0.002785647753626108,
0.02330598421394825,
-0.07390084117650986,
0.0021858657710254192,
-0.002153669251129031,
0.007115983869880438,
0.017590725794434547,
-0.056869618594646454,
-0.028878379613161087,
0.09536625444889069,
-0.0711480975151062,
0.14949342608451843,
0.027531320229172707,
-0.1216459572315216,
0.08670815080404282,
0.12760819494724274,
0.012305375188589096,
0.04066877067089081,
0.030651841312646866,
0.050527773797512054,
-0.0053455219604074955,
0.03838781639933586,
-0.006157867144793272,
-0.05640975385904312,
-0.030690347775816917,
0.01565021276473999,
0.04470043629407883,
-0.11668040603399277,
-0.08468811959028244,
-0.11181726306676865,
0.03248446807265282,
-0.005674353800714016,
-0.008903490379452705,
-0.03425291180610657,
-0.004987649153918028,
-0.08333824574947357,
0.08707844465970993,
0.08599800616502762,
-0.03523461893200874,
-0.04867205768823624,
-0.02232448011636734,
-0.021822065114974976,
-0.04828008636832237,
-0.01754223182797432,
-0.06229617819190025,
0.01013682596385479,
-0.03426302596926689,
-0.01770971529185772,
-0.02336016856133938,
-0.09497294574975967,
0.05380754545331001,
-0.029286270961165428,
0.048851627856492996,
-0.03842965140938759,
-0.023619189858436584,
-0.13072165846824646,
0.05314239487051964,
0.043731432408094406,
0.03078291565179825,
-0.0001770715316524729,
-0.06371231377124786,
0.05813930928707123,
-0.014956056140363216,
-0.06345149129629135,
-0.06364314258098602,
0.07586855441331863,
0.02966887690126896,
-0.01551933865994215,
-0.007188340183347464,
0.07939174026250839,
-0.07652392983436584,
-0.02270813100039959,
-0.026540745049715042,
-5.7020887567205136e-8,
-0.10048870742321014,
-0.06891387701034546,
-0.022422758862376213,
-0.018251987174153328,
0.051044613122940063,
0.009912658482789993,
-0.033445362001657486,
-0.0006961026811040938,
-0.018232258036732674,
-0.00550952460616827,
-0.0009624166414141655,
-0.0013166249264031649,
0.007719641085714102,
-0.02833864651620388,
-0.011624745093286037,
-0.05397126078605652,
-0.04933929815888405,
-0.015730781480669975,
-0.018869152292609215,
0.03740764409303665,
-0.031196916475892067,
0.008767789229750633,
0.00738523481413722,
0.00023744087957311422,
0.05886838957667351,
-0.05433148145675659,
-0.011102556250989437,
0.06681783497333527,
-0.033907465636730194,
0.0940440446138382,
-0.00772673636674881,
0.08040082454681396,
0.11564332246780396,
0.04014110192656517,
-0.06172383949160576,
0.007159698288887739,
-0.055837154388427734,
-0.004155072849243879,
0.04429441690444946,
0.043237775564193726,
-0.03001292236149311,
-0.027953477576375008,
-0.07762784510850906,
0.008666104637086391,
-0.11313948035240173,
-0.10371457040309906,
0.03145504370331764,
0.0258319191634655,
0.01896413043141365,
-0.04985017329454422,
0.05018118396401405,
0.013913952745497227,
0.05525621026754379,
0.014372476376593113,
-0.007390980608761311,
0.009676656685769558,
-0.005283259321004152,
-0.0451473593711853,
0.03676792234182358,
0.04556064307689667,
0.024215271696448326,
0.02403346262872219,
0.01554771140217781,
-0.03903219476342201
] | 0.044233
|
Prints: text/javascript ``` ```cjs const { MIMEType } = require('node:util'); const myMIME = new MIMEType('text/ecmascript'); console.log(myMIME.subtype); // Prints: ecmascript myMIME.subtype = 'javascript'; console.log(myMIME.subtype); // Prints: javascript console.log(String(myMIME)); // Prints: text/javascript ``` ### `mime.essence` \* Type: {string} Gets the essence of the MIME. This property is read only. Use `mime.type` or `mime.subtype` to alter the MIME. ```mjs import { MIMEType } from 'node:util'; const myMIME = new MIMEType('text/javascript;key=value'); console.log(myMIME.essence); // Prints: text/javascript myMIME.type = 'application'; console.log(myMIME.essence); // Prints: application/javascript console.log(String(myMIME)); // Prints: application/javascript;key=value ``` ```cjs const { MIMEType } = require('node:util'); const myMIME = new MIMEType('text/javascript;key=value'); console.log(myMIME.essence); // Prints: text/javascript myMIME.type = 'application'; console.log(myMIME.essence); // Prints: application/javascript console.log(String(myMIME)); // Prints: application/javascript;key=value ``` ### `mime.params` \* Type: {MIMEParams} Gets the [`MIMEParams`][] object representing the parameters of the MIME. This property is read-only. See [`MIMEParams`][] documentation for details. ### `mime.toString()` \* Returns: {string} The `toString()` method on the `MIMEType` object returns the serialized MIME. Because of the need for standard compliance, this method does not allow users to customize the serialization process of the MIME. ### `mime.toJSON()` \* Returns: {string} Alias for [`mime.toString()`][]. This method is automatically called when an `MIMEType` object is serialized with [`JSON.stringify()`][]. ```mjs import { MIMEType } from 'node:util'; const myMIMES = [ new MIMEType('image/png'), new MIMEType('image/gif'), ]; console.log(JSON.stringify(myMIMES)); // Prints: ["image/png", "image/gif"] ``` ```cjs const { MIMEType } = require('node:util'); const myMIMES = [ new MIMEType('image/png'), new MIMEType('image/gif'), ]; console.log(JSON.stringify(myMIMES)); // Prints: ["image/png", "image/gif"] ``` ## Class: `util.MIMEParams` The `MIMEParams` API provides read and write access to the parameters of a `MIMEType`. ### `new MIMEParams()` Creates a new `MIMEParams` object by with empty parameters ```mjs import { MIMEParams } from 'node:util'; const myParams = new MIMEParams(); ``` ```cjs const { MIMEParams } = require('node:util'); const myParams = new MIMEParams(); ``` ### `mimeParams.delete(name)` \* `name` {string} Remove all name-value pairs whose name is `name`. ### `mimeParams.entries()` \* Returns: {Iterator} Returns an iterator over each of the name-value pairs in the parameters. Each item of the iterator is a JavaScript `Array`. The first item of the array is the `name`, the second item of the array is the `value`. ### `mimeParams.get(name)` \* `name` {string} \* Returns: {string | null} A string or `null` if there is no name-value pair with the given `name`. Returns the value of the first name-value pair whose name is `name`. If there are no such pairs, `null` is returned. ### `mimeParams.has(name)` \* `name` {string} \* Returns: {boolean} Returns `true` if there is at least one name-value pair whose name is `name`. ### `mimeParams.keys()` \* Returns: {Iterator} Returns an iterator over the names of each name-value pair. ```mjs import { MIMEType } from 'node:util'; const { params } = new MIMEType('text/plain;foo=0;bar=1'); for (const name of params.keys()) { console.log(name); } // Prints: // foo // bar ``` ```cjs const { MIMEType } = require('node:util'); const { params } = new MIMEType('text/plain;foo=0;bar=1'); for (const name of params.keys()) { console.log(name); } // Prints: // foo // bar ``` ### `mimeParams.set(name, value)` \* `name` {string} \* `value` {string} Sets the value in the `MIMEParams` object associated with `name` to `value`. If there are any pre-existing name-value pairs whose names are `name`, set the first such pair's value to `value`. ```mjs import { MIMEType } from 'node:util'; const { params } = new MIMEType('text/plain;foo=0;bar=1'); params.set('foo', 'def'); params.set('baz', 'xyz'); console.log(params.toString()); // Prints: foo=def;bar=1;baz=xyz ``` ```cjs const { MIMEType } = require('node:util'); const { params } = new MIMEType('text/plain;foo=0;bar=1'); params.set('foo', 'def'); params.set('baz', 'xyz'); console.log(params.toString()); // Prints: foo=def;bar=1;baz=xyz ``` ### `mimeParams.values()` \* Returns: {Iterator} Returns an iterator over the values of each name-value pair. ### `mimeParams[Symbol.iterator]()` \* Returns: {Iterator} Alias for [`mimeParams.entries()`][]. ```mjs import
|
https://github.com/nodejs/node/blob/main//doc/api/util.md
|
main
|
nodejs
|
[
-0.03953646868467331,
0.038947056978940964,
0.09437429159879684,
0.08156675100326538,
0.03662528842687607,
-0.06162698194384575,
0.06921765208244324,
0.15661711990833282,
0.023979905992746353,
-0.09040261805057526,
-0.010470055043697357,
-0.01483027171343565,
0.0018875624518841505,
0.06385260820388794,
0.08333805948495865,
0.03121606446802616,
-0.05209840089082718,
0.0024662937503308058,
-0.016408519819378853,
-0.014338667504489422,
0.09231506288051605,
-0.0546344518661499,
0.03808162361383438,
-0.037306323647499084,
-0.034980908036231995,
0.007084460463374853,
-0.029793476685881615,
0.03718535229563713,
0.02566889300942421,
-0.008833182044327259,
0.09507089853286743,
0.039769161492586136,
0.06255830824375153,
-0.026041517034173012,
-0.014023536816239357,
0.18034708499908447,
0.012588141486048698,
-0.12924329936504364,
0.03032008931040764,
0.014347270131111145,
0.008594263345003128,
0.06344325840473175,
-0.06378642469644547,
-0.026988759636878967,
0.06376451998949051,
-0.028474897146224976,
0.03126681223511696,
-0.02545083314180374,
-0.08420178294181824,
0.015897799283266068,
0.0036588578950613737,
-0.03490948677062988,
-0.10811790823936462,
-0.008219732902944088,
-0.04320541396737099,
-0.041356444358825684,
-0.056865330785512924,
0.02878267876803875,
0.05772972106933594,
-0.011666527949273586,
-0.03657842427492142,
0.028439003974199295,
0.043685391545295715,
-0.05131999030709267,
0.032851751893758774,
0.01865079067647457,
-0.03906166926026344,
0.01615813933312893,
-0.012913264334201813,
-0.055771537125110626,
0.025429345667362213,
-0.03937878459692001,
-0.01985102891921997,
0.040333040058612823,
-0.01582447625696659,
-0.0015163358766585588,
0.04176650196313858,
-0.014609496109187603,
-0.04192924499511719,
0.012685157358646393,
-0.04894010350108147,
-0.06107368692755699,
0.0013746104668825865,
0.04666373133659363,
0.08910199254751205,
0.07605145871639252,
0.02641800232231617,
-0.016628310084342957,
0.01569851115345955,
0.049192000180482864,
-0.10247490555047989,
-0.0935811772942543,
-0.07702314853668213,
0.061774544417858124,
0.0705428496003151,
0.07085345685482025,
-0.08568429201841354,
0.04713369905948639,
-0.01759825088083744,
0.07893579453229904,
-0.03193291276693344,
0.034148093312978745,
0.04016106203198433,
-0.0017595296958461404,
0.07973720133304596,
-0.020253006368875504,
0.015184501186013222,
0.0629502460360527,
0.01500004157423973,
-0.044080812484025955,
-0.010459847748279572,
0.012927408330142498,
-0.08006439357995987,
-0.03578709065914154,
-0.0427485927939415,
0.03539856895804405,
0.05021757259964943,
-0.004191939253360033,
0.03963654860854149,
0.18564075231552124,
0.10450341552495956,
-0.04501136764883995,
-0.02736540138721466,
0.008896101266145706,
-0.02654162421822548,
-0.0019060632912442088,
0.00692958477884531,
4.5198077376643584e-33,
-0.020326215773820877,
-0.03562389686703682,
0.06440996378660202,
0.0694255381822586,
-0.10204532742500305,
-0.02435038425028324,
0.004239474423229694,
-0.02389765903353691,
-0.11528991162776947,
-0.08763126283884048,
-0.053200650960206985,
0.09436874091625214,
-0.026403719559311867,
0.04332178831100464,
-0.06374216079711914,
-0.03776221349835396,
0.026396723464131355,
-0.07408590614795685,
0.0712827667593956,
-0.05041593313217163,
-0.019331948831677437,
0.05989888310432434,
-0.04744682088494301,
-0.00809425301849842,
-0.047959744930267334,
0.004533811472356319,
0.009632042609155178,
-0.038330983370542526,
-0.034575268626213074,
-0.028025707229971886,
0.022943582385778427,
-0.04737348482012749,
0.0435289591550827,
0.060428399592638016,
-0.027352401986718178,
-0.014505802653729916,
0.03623355180025101,
0.003216430079191923,
-0.10954327881336212,
-0.015211853198707104,
0.04080166295170784,
-0.00037113571306690574,
0.011620049364864826,
-0.0034770695492625237,
-0.022993212565779686,
-0.0012956797145307064,
-0.07210475206375122,
-0.028554562479257584,
-0.03803539648652077,
-0.02751130610704422,
-0.03246611729264259,
0.05425962060689926,
0.03376459330320358,
0.03038908541202545,
0.05052867904305458,
0.045022882521152496,
-0.01067500002682209,
-0.026165878400206566,
-0.0025555361062288284,
-0.09306175261735916,
0.06170330196619034,
0.042643774300813675,
0.08194326609373093,
0.017904208973050117,
0.04499246925115585,
0.017275046557188034,
-0.02258932963013649,
0.02198810875415802,
-0.0328863188624382,
0.053634729236364365,
-0.07820406556129456,
0.012283657677471638,
-0.057020433247089386,
0.08374641835689545,
0.0007534822216257453,
-0.022415295243263245,
0.01699257642030716,
-0.02790839411318302,
-0.019733959808945656,
0.04373974725604057,
0.005825974512845278,
0.013658056035637856,
-0.003246423089876771,
0.08741119503974915,
-0.020316503942012787,
0.039618682116270065,
-0.011872570961713791,
-0.03507271781563759,
0.12351063638925552,
-0.0060832262970507145,
0.020973781123757362,
-0.0323149710893631,
-0.04345615208148956,
-0.09274344891309738,
-0.11063546687364578,
-5.711178241720455e-33,
-0.034724343568086624,
0.0410262867808342,
-0.08407427370548248,
0.07647261023521423,
-0.03859728202223778,
-0.01966017298400402,
0.0470050685107708,
0.04987996816635132,
0.005905922967940569,
0.0785893052816391,
-0.024768641218543053,
-0.009067164734005928,
-0.025624509900808334,
-0.06408550590276718,
-0.053419873118400574,
0.02259809337556362,
-0.07486439496278763,
0.032487090677022934,
0.0839344710111618,
-0.0009549017413519323,
-0.0673515647649765,
0.021096182987093925,
0.07890276610851288,
0.02847701869904995,
-0.058833975344896317,
0.032448384910821915,
-0.04074893891811371,
0.00844920426607132,
-0.08066950738430023,
-0.05696452036499977,
-0.07679849863052368,
0.006514629349112511,
0.0013938338961452246,
0.06730525940656662,
0.029985222965478897,
-0.07269969582557678,
-0.002890409668907523,
0.061207935214042664,
0.030667418614029884,
-0.017580119892954826,
0.039474163204431534,
0.015457839705049992,
0.003228279994800687,
0.028484852984547615,
-0.030956367030739784,
0.008034417405724525,
0.030957328155636787,
-0.007679709233343601,
0.0876019224524498,
-0.031454045325517654,
-0.015123611316084862,
-0.07772737741470337,
0.00968130026012659,
-0.027545485645532608,
-0.03216320276260376,
-0.049525558948516846,
0.030543463304638863,
-0.032277170568704605,
-0.015238286927342415,
0.08144071698188782,
0.06263487040996552,
-0.12307080626487732,
-0.024119552224874496,
-0.03275443986058235,
-0.0001041246359818615,
-0.0288119874894619,
-0.06291884183883667,
-0.0662086233496666,
-0.06636611372232437,
-0.00010543389362283051,
0.03916201740503311,
-0.025368690490722656,
0.014561724849045277,
-0.030619725584983826,
0.026718271896243095,
0.0046305409632623196,
-0.02048429101705551,
0.012883962132036686,
-0.0028109538834542036,
-0.009390374645590782,
0.09200307726860046,
0.05268807336688042,
-0.1028251200914383,
-0.008054602891206741,
0.05683378875255585,
-0.01868235319852829,
-0.08369017392396927,
0.06336270272731781,
-0.042774997651576996,
-0.03462368622422218,
-0.03821028396487236,
0.08459071815013885,
-0.039235733449459076,
-0.03259033337235451,
-0.011593754403293133,
-5.25226155900782e-8,
-0.1016099825501442,
-0.08157352358102798,
-0.06373564898967743,
-0.015627006068825722,
-0.0052473475225269794,
0.008027260191738605,
-0.0003500866296235472,
-0.08485312759876251,
0.04092720150947571,
-0.019776728004217148,
-0.006029472220689058,
-0.002428831299766898,
-0.03592805936932564,
-0.042703017592430115,
-0.05162159353494644,
0.003321112133562565,
-0.011281009763479233,
0.042353399097919464,
0.01626484841108322,
0.04518796131014824,
-0.021730009466409683,
0.01887231320142746,
-0.04706446826457977,
-0.012683290988206863,
0.07673775404691696,
-0.00006812983338022605,
0.07535151392221451,
0.05170157179236412,
-0.02544018253684044,
0.023800963535904884,
0.014748843386769295,
0.04311366751790047,
0.04887320101261139,
0.026918165385723114,
-0.1551913022994995,
0.025271063670516014,
0.004862964618951082,
-0.03349915146827698,
-0.01628855988383293,
0.08189309388399124,
0.11223385483026505,
0.02914578653872013,
-0.08546432852745056,
-0.021946031600236893,
0.009944291785359383,
-0.034045591950416565,
0.06160246953368187,
0.02496430277824402,
0.012972524389624596,
0.0638073980808258,
0.07170043885707855,
-0.02363268844783306,
-0.03791290894150734,
-0.0006160984630696476,
-0.042755354195833206,
-0.015362480655312538,
0.0045298184268176556,
-0.008928334340453148,
0.029609670862555504,
-0.05091400817036629,
-0.023283662274479866,
-0.03766214847564697,
0.07168667018413544,
-0.04935859143733978
] | 0.124971
|
foo=def;bar=1;baz=xyz ``` ```cjs const { MIMEType } = require('node:util'); const { params } = new MIMEType('text/plain;foo=0;bar=1'); params.set('foo', 'def'); params.set('baz', 'xyz'); console.log(params.toString()); // Prints: foo=def;bar=1;baz=xyz ``` ### `mimeParams.values()` \* Returns: {Iterator} Returns an iterator over the values of each name-value pair. ### `mimeParams[Symbol.iterator]()` \* Returns: {Iterator} Alias for [`mimeParams.entries()`][]. ```mjs import { MIMEType } from 'node:util'; const { params } = new MIMEType('text/plain;foo=bar;xyz=baz'); for (const [name, value] of params) { console.log(name, value); } // Prints: // foo bar // xyz baz ``` ```cjs const { MIMEType } = require('node:util'); const { params } = new MIMEType('text/plain;foo=bar;xyz=baz'); for (const [name, value] of params) { console.log(name, value); } // Prints: // foo bar // xyz baz ``` ## `util.parseArgs([config])` \* `config` {Object} Used to provide arguments for parsing and to configure the parser. `config` supports the following properties: \* `args` {string\[]} array of argument strings. \*\*Default:\*\* `process.argv` with `execPath` and `filename` removed. \* `options` {Object} Used to describe arguments known to the parser. Keys of `options` are the long names of options and values are an {Object} accepting the following properties: \* `type` {string} Type of argument, which must be either `boolean` or `string`. \* `multiple` {boolean} Whether this option can be provided multiple times. If `true`, all values will be collected in an array. If `false`, values for the option are last-wins. \*\*Default:\*\* `false`. \* `short` {string} A single character alias for the option. \* `default` {string | boolean | string\[] | boolean\[]} The value to assign to the option if it does not appear in the arguments to be parsed. The value must match the type specified by the `type` property. If `multiple` is `true`, it must be an array. No default value is applied when the option does appear in the arguments to be parsed, even if the provided value is falsy. \* `strict` {boolean} Should an error be thrown when unknown arguments are encountered, or when arguments are passed that do not match the `type` configured in `options`. \*\*Default:\*\* `true`. \* `allowPositionals` {boolean} Whether this command accepts positional arguments. \*\*Default:\*\* `false` if `strict` is `true`, otherwise `true`. \* `allowNegative` {boolean} If `true`, allows explicitly setting boolean options to `false` by prefixing the option name with `--no-`. \*\*Default:\*\* `false`. \* `tokens` {boolean} Return the parsed tokens. This is useful for extending the built-in behavior, from adding additional checks through to reprocessing the tokens in different ways. \*\*Default:\*\* `false`. \* Returns: {Object} The parsed command line arguments: \* `values` {Object} A mapping of parsed option names with their {string} or {boolean} values. \* `positionals` {string\[]} Positional arguments. \* `tokens` {Object\[] | undefined} See [parseArgs tokens](#parseargs-tokens) section. Only returned if `config` includes `tokens: true`. Provides a higher level API for command-line argument parsing than interacting with `process.argv` directly. Takes a specification for the expected arguments and returns a structured object with the parsed options and positionals. ```mjs import { parseArgs } from 'node:util'; const args = ['-f', '--bar', 'b']; const options = { foo: { type: 'boolean', short: 'f', }, bar: { type: 'string', }, }; const { values, positionals, } = parseArgs({ args, options }); console.log(values, positionals); // Prints: [Object: null prototype] { foo: true, bar: 'b' } [] ``` ```cjs const { parseArgs } = require('node:util'); const args = ['-f', '--bar', 'b']; const options = { foo: { type: 'boolean', short: 'f', }, bar: { type: 'string', }, }; const { values, positionals, } = parseArgs({ args, options }); console.log(values, positionals); // Prints: [Object: null prototype] { foo: true, bar: 'b' } [] ``` ### `parseArgs` `tokens` Detailed parse information is available for adding custom behaviors by specifying `tokens: true`
|
https://github.com/nodejs/node/blob/main//doc/api/util.md
|
main
|
nodejs
|
[
-0.08196177333593369,
0.03917776793241501,
0.008141054771840572,
0.07799267023801804,
-0.07075780630111694,
-0.02980947680771351,
0.10621234774589539,
0.10381762683391571,
-0.018182773143053055,
-0.09280170500278473,
-0.02098586969077587,
0.027243684977293015,
0.07491603493690491,
0.046221774071455,
0.043587036430835724,
0.07492571324110031,
-0.08486957103013992,
0.039859410375356674,
-0.028910689055919647,
-0.0501168891787529,
0.09102678298950195,
-0.014586622826755047,
0.03324725478887558,
-0.018510859459638596,
-0.03868136927485466,
0.008972233161330223,
-0.017238415777683258,
-0.014970853924751282,
0.03583604097366333,
0.012367677874863148,
0.0895703062415123,
0.029386652633547783,
-0.01337730884552002,
0.028807345777750015,
0.048670291900634766,
0.13545240461826324,
0.017669985070824623,
-0.09273284673690796,
0.010925622656941414,
0.027425915002822876,
0.0231199748814106,
0.06922311335802078,
-0.0556570440530777,
-0.04851119965314865,
0.07129836082458496,
0.024367131292819977,
0.07353565096855164,
0.04158449545502663,
-0.08065871894359589,
-0.014402170665562153,
0.01278719212859869,
-0.07203739881515503,
-0.11344899982213974,
0.017164552584290504,
0.00690125860273838,
-0.05216727405786514,
-0.06334812194108963,
0.020093386992812157,
0.02601202391088009,
-0.052217353135347366,
-0.10274338722229004,
0.006573891267180443,
0.03530358895659447,
-0.04319141432642937,
0.04791681095957756,
-0.029933379963040352,
-0.016605157405138016,
0.04513468220829964,
-0.009716085158288479,
0.048482343554496765,
-0.018536845222115517,
0.015035046264529228,
-0.004062158986926079,
0.013141471892595291,
-0.049838848412036896,
0.02427714131772518,
0.08936478942632675,
-0.023800848051905632,
-0.05938724800944328,
-0.002940558595582843,
-0.03079352155327797,
-0.08901155740022659,
-0.03662397339940071,
-0.05653609707951546,
0.059755660593509674,
0.038990721106529236,
-0.07789822667837143,
0.010759578086435795,
0.05071576312184334,
0.03599291667342186,
-0.09755221009254456,
-0.07484244555234909,
-0.06296468526124954,
0.08121653646230698,
0.056303419172763824,
0.08801119774580002,
0.0500301718711853,
-0.01947839930653572,
-0.01076059602200985,
0.06936036050319672,
-0.04163331538438797,
0.005557747092097998,
0.10316578298807144,
-0.05019066110253334,
0.02258509397506714,
-0.009265792556107044,
0.02944232150912285,
-0.01925569400191307,
-0.05031510069966316,
-0.03723502159118652,
-0.016301089897751808,
0.03305230289697647,
-0.02975723147392273,
0.0148228220641613,
-0.07357169687747955,
-0.0014015022898092866,
0.025568075478076935,
-0.01471079234033823,
0.08912967890501022,
0.008808351121842861,
0.04481649771332741,
-0.020334897562861443,
-0.03162967786192894,
0.04009385034441948,
-0.03506350517272949,
0.01974039152264595,
-0.04615963622927666,
7.431618549272508e-33,
-0.013987638056278229,
-0.02875746414065361,
0.029486995190382004,
0.0854152962565422,
-0.1412104368209839,
0.02382935769855976,
0.08280770480632782,
-0.03462287783622742,
-0.062468960881233215,
0.0035245006438344717,
-0.08158115297555923,
0.04830349236726761,
0.0020984855946153402,
-0.028363311663269997,
-0.032727714627981186,
-0.07123497128486633,
0.05606145039200783,
-0.03990036994218826,
0.013346168212592602,
0.015005591325461864,
0.025426015257835388,
0.04955276474356651,
-0.10294009000062943,
-0.033487580716609955,
-0.0359843485057354,
-0.028633881360292435,
0.036105312407016754,
-0.07669238746166229,
-0.036543529480695724,
-0.0319778248667717,
0.037636395543813705,
-0.036948587745428085,
0.03310335800051689,
0.07209175825119019,
0.03304692357778549,
0.031938858330249786,
0.07584517449140549,
0.005142220761626959,
-0.09442438930273056,
-0.03400963544845581,
0.020462436601519585,
-0.024557415395975113,
0.046403151005506516,
0.09970840811729431,
-0.042871471494436264,
-0.04680275544524193,
-0.1273590475320816,
-0.03785453736782074,
-0.015885187312960625,
-0.06386234611272812,
-0.006424478720873594,
0.05666171759366989,
-0.04222520440816879,
0.011801369488239288,
0.009716717526316643,
0.01563737727701664,
-0.04032064974308014,
-0.001124767353758216,
-0.0019492057617753744,
0.003434316720813513,
-0.001602716976776719,
0.0053886184468865395,
-0.0024409228935837746,
0.0008457343792542815,
0.059569548815488815,
-0.0015711033483967185,
0.02964647300541401,
0.03125201165676117,
-0.00020725082140415907,
0.0809779241681099,
-0.06607688218355179,
-0.020143073052167892,
-0.05975281447172165,
-0.03864310681819916,
0.032967306673526764,
-0.007612979039549828,
-0.03130444884300232,
-0.06773895025253296,
-0.012029671110212803,
-0.04248163476586342,
0.045735884457826614,
0.017922425642609596,
-0.02036364935338497,
0.11520542949438095,
0.031663086265325546,
0.035362716764211655,
0.0007636282243765891,
-0.06928762793540955,
0.026854773983359337,
-0.03883746266365051,
0.0031708532478660345,
0.007971148937940598,
-0.04150516539812088,
-0.11619582027196884,
-0.03641124442219734,
-7.997996706753641e-33,
0.013720683753490448,
0.027260415256023407,
0.013160438276827335,
0.13960181176662445,
0.024729808792471886,
-0.07154852151870728,
0.05441164970397949,
-0.003429669188335538,
-0.009475263766944408,
0.016374973580241203,
-0.1210278645157814,
-0.015051368623971939,
0.0031084169168025255,
-0.0699157789349556,
0.0014197848504409194,
0.08490753173828125,
-0.08410805463790894,
-0.00959731824696064,
0.0462300181388855,
-0.027648800984025,
-0.0760597512125969,
0.00776883028447628,
0.07614468783140182,
-0.0008398463251069188,
-0.1195097342133522,
0.020383069291710854,
-0.02420300990343094,
0.025399547070264816,
-0.013252033852040768,
0.029879925772547722,
-0.05824148654937744,
-0.059248365461826324,
0.030626235529780388,
0.022404029965400696,
-0.019978558644652367,
-0.06033793091773987,
0.017651649191975594,
0.06739634275436401,
0.03361958637833595,
0.03360804542899132,
0.060577310621738434,
-0.006202213000506163,
-0.02018006704747677,
0.05772225558757782,
-0.022180531173944473,
0.03223792836070061,
-0.033895496279001236,
0.026964642107486725,
0.048874907195568085,
-0.0036836499348282814,
0.007737589534372091,
-0.03416109085083008,
-0.0953851193189621,
-0.007912404835224152,
-0.022877512499690056,
-0.10958947986364365,
-0.04936128482222557,
-0.04724889248609543,
0.050657231360673904,
0.06133260577917099,
0.053920093923807144,
-0.07281101495027542,
0.03466637432575226,
-0.007513012271374464,
0.050491590052843094,
-0.004121472593396902,
-0.07377025485038757,
-0.12952707707881927,
-0.03387866169214249,
0.029854554682970047,
0.057004835456609726,
-0.046629875898361206,
-0.0167426448315382,
-0.025756070390343666,
0.00885527953505516,
-0.018972063437104225,
-0.05252651125192642,
0.0011309683322906494,
0.04149078205227852,
-0.00687608914449811,
0.0606672577559948,
0.047713302075862885,
-0.046848151832818985,
0.05839631333947182,
0.0417705737054348,
-0.02451753057539463,
0.03623586893081665,
0.16170765459537506,
-0.024868633598089218,
-0.034828849136829376,
0.045728493481874466,
0.04187114164233208,
0.04076670482754707,
0.018291356042027473,
-0.027188776060938835,
-5.6218588895262656e-8,
-0.14635929465293884,
-0.06782695651054382,
-0.10005846619606018,
0.02105632610619068,
-0.058290041983127594,
0.053193703293800354,
-0.00040532794082537293,
-0.016533993184566498,
0.06157059967517853,
-0.0690305083990097,
0.05615862086415291,
-0.022300394251942635,
0.017690062522888184,
-0.006381161045283079,
-0.024701615795493126,
0.020998980849981308,
0.003983996342867613,
0.015180534683167934,
-0.026950545608997345,
0.10411819070577621,
0.024179600179195404,
0.02660834975540638,
-0.07095834612846375,
0.0022034174762666225,
0.08446226269006729,
-0.020384278148412704,
0.04088076576590538,
0.07617315649986267,
0.0588870644569397,
0.027054164558649063,
-0.008991820737719536,
0.007693006657063961,
0.026256754994392395,
0.043631259351968765,
-0.11633162200450897,
0.018387002870440483,
-0.06107281520962715,
-0.03546060249209404,
0.05344470590353012,
0.07904842495918274,
0.011084482073783875,
-0.011774909682571888,
-0.030815085396170616,
0.031969938427209854,
0.020101236179471016,
-0.07443752884864807,
0.005279370117932558,
-0.01853923313319683,
0.02416934072971344,
0.06258613616228104,
-0.0005371571169234812,
-0.026545975357294083,
-0.0008011626196093857,
-0.04275451973080635,
-0.042155519127845764,
-0.05610019341111183,
-0.010529999621212482,
0.037360500544309616,
0.017605025321245193,
-0.040802039206027985,
-0.06209205090999603,
-0.04444931820034981,
0.01564893126487732,
0.029315203428268433
] | 0.023248
|
short: 'f', }, bar: { type: 'string', }, }; const { values, positionals, } = parseArgs({ args, options }); console.log(values, positionals); // Prints: [Object: null prototype] { foo: true, bar: 'b' } [] ``` ### `parseArgs` `tokens` Detailed parse information is available for adding custom behaviors by specifying `tokens: true` in the configuration. The returned tokens have properties describing: \* all tokens \* `kind` {string} One of 'option', 'positional', or 'option-terminator'. \* `index` {number} Index of element in `args` containing token. So the source argument for a token is `args[token.index]`. \* option tokens \* `name` {string} Long name of option. \* `rawName` {string} How option used in args, like `-f` of `--foo`. \* `value` {string | undefined} Option value specified in args. Undefined for boolean options. \* `inlineValue` {boolean | undefined} Whether option value specified inline, like `--foo=bar`. \* positional tokens \* `value` {string} The value of the positional argument in args (i.e. `args[index]`). \* option-terminator token The returned tokens are in the order encountered in the input args. Options that appear more than once in args produce a token for each use. Short option groups like `-xy` expand to a token for each option. So `-xxx` produces three tokens. For example, to add support for a negated option like `--no-color` (which `allowNegative` supports when the option is of `boolean` type), the returned tokens can be reprocessed to change the value stored for the negated option. ```mjs import { parseArgs } from 'node:util'; const options = { 'color': { type: 'boolean' }, 'no-color': { type: 'boolean' }, 'logfile': { type: 'string' }, 'no-logfile': { type: 'boolean' }, }; const { values, tokens } = parseArgs({ options, tokens: true }); // Reprocess the option tokens and overwrite the returned values. tokens .filter((token) => token.kind === 'option') .forEach((token) => { if (token.name.startsWith('no-')) { // Store foo:false for --no-foo const positiveName = token.name.slice(3); values[positiveName] = false; delete values[token.name]; } else { // Resave value so last one wins if both --foo and --no-foo. values[token.name] = token.value ?? true; } }); const color = values.color; const logfile = values.logfile ?? 'default.log'; console.log({ logfile, color }); ``` ```cjs const { parseArgs } = require('node:util'); const options = { 'color': { type: 'boolean' }, 'no-color': { type: 'boolean' }, 'logfile': { type: 'string' }, 'no-logfile': { type: 'boolean' }, }; const { values, tokens } = parseArgs({ options, tokens: true }); // Reprocess the option tokens and overwrite the returned values. tokens .filter((token) => token.kind === 'option') .forEach((token) => { if (token.name.startsWith('no-')) { // Store foo:false for --no-foo const positiveName = token.name.slice(3); values[positiveName] = false; delete values[token.name]; } else { // Resave value so last one wins if both --foo and --no-foo. values[token.name] = token.value ?? true; } }); const color = values.color; const logfile = values.logfile ?? 'default.log'; console.log({ logfile, color }); ``` Example usage showing negated options, and when an option is used multiple ways then last one wins. ```console $ node negate.js { logfile: 'default.log', color: undefined } $ node negate.js --no-logfile --no-color { logfile: false, color: false } $ node negate.js --logfile=test.log --color { logfile: 'test.log', color: true } $ node negate.js --no-logfile --logfile=test.log --color --no-color { logfile: 'test.log', color: false } ``` ## `util.parseEnv(content)` \* `content` {string} The raw contents of a `.env` file. \* Returns: {Object} Given an example `.env` file: ```cjs const { parseEnv } = require('node:util'); parseEnv('HELLO=world\nHELLO=oh my\n'); // Returns: { HELLO: 'oh my' } ``` ```mjs import { parseEnv } from 'node:util'; parseEnv('HELLO=world\nHELLO=oh my\n'); // Returns: { HELLO: 'oh my' } ``` ## `util.promisify(original)` \* `original` {Function} \* Returns: {Function} Takes a function following the common error-first
|
https://github.com/nodejs/node/blob/main//doc/api/util.md
|
main
|
nodejs
|
[
-0.058046091347932816,
0.0466877780854702,
0.032090071588754654,
0.04868943616747856,
-0.06584903597831726,
0.004712359048426151,
0.08603279292583466,
0.0767602026462555,
-0.016265220940113068,
-0.03363626077771187,
-0.027119005098938942,
0.0022693490609526634,
-0.04346456378698349,
0.002415818627923727,
0.0881509855389595,
0.06855960190296173,
-0.0749540701508522,
-0.026376303285360336,
-0.007789305876940489,
-0.039284929633140564,
0.059725839644670486,
-0.02978411130607128,
-0.07813549786806107,
-0.04119456559419632,
-0.03576944023370743,
0.052801746875047684,
-0.005082454066723585,
-0.028284365311264992,
0.04036090895533562,
-0.02989061176776886,
0.06971286237239838,
-0.0069404845125973225,
0.001827295869588852,
0.03556632250547409,
-0.05888926982879639,
0.12140372395515442,
-0.005759776569902897,
-0.07674911618232727,
0.059295881539583206,
-0.014817921444773674,
0.05202324688434601,
0.06982679665088654,
-0.1203053668141365,
-0.04029073566198349,
0.004308270290493965,
0.0823114812374115,
0.03391018882393837,
0.0020495301578193903,
-0.09723664820194244,
0.0038531036116182804,
0.008301857858896255,
0.021815665066242218,
0.007190758362412453,
0.007560769561678171,
0.03817629814147949,
-0.017678720876574516,
-0.04984185844659805,
-0.06566054373979568,
0.10571436583995819,
-0.050439588725566864,
0.04008718952536583,
-0.018191663548350334,
-0.013244835659861565,
-0.019157320261001587,
0.0025565228424966335,
-0.07530684024095535,
0.043195903301239014,
0.060008369386196136,
0.042665641754865646,
0.08011314272880554,
-0.045072294771671295,
0.034878939390182495,
-0.006414045114070177,
0.011065834201872349,
0.012142371386289597,
0.005420276429504156,
0.019837843254208565,
0.00814590509980917,
0.00037190757575444877,
-0.007334141992032528,
0.007604777812957764,
-0.0827069878578186,
0.04442429170012474,
0.11611365526914597,
-0.04457747936248779,
0.02314327284693718,
-0.06193102151155472,
0.001961752772331238,
0.032524947077035904,
0.02719275653362274,
-0.0610312893986702,
-0.18140795826911926,
-0.02816862240433693,
0.017981436103582382,
0.0877201035618782,
0.03992569074034691,
-0.03344849869608879,
-0.06762602180242538,
-0.03463389724493027,
0.029614219442009926,
-0.01886906661093235,
-0.007037465460598469,
0.10985279828310013,
-0.0695146843791008,
0.0021396346855908632,
0.03537189960479736,
-0.13693290948867798,
-0.09219709783792496,
0.03547470271587372,
0.049914658069610596,
-0.05183858796954155,
0.0796092227101326,
-0.011955786496400833,
0.04529980942606926,
-0.04272790625691414,
0.02734176255762577,
0.008019113913178444,
-0.060105640441179276,
0.0544419065117836,
0.04076385870575905,
0.11290539801120758,
0.023461367934942245,
-0.02106856182217598,
0.029395632445812225,
-0.05315174162387848,
0.049108270555734634,
-0.025370243936777115,
3.3025447664794934e-33,
-0.041819918900728226,
-0.029215596616268158,
0.011380956508219242,
-0.03914807364344597,
-0.0024293954484164715,
0.005453338380903006,
0.022228414192795753,
0.02339363470673561,
-0.005684930365532637,
0.053706537932157516,
-0.018904022872447968,
0.015471838414669037,
0.000593453471083194,
-0.0037969439290463924,
-0.01856185868382454,
-0.006100967992097139,
0.008527548983693123,
0.030363745987415314,
-0.039253730326890945,
-0.008235982619225979,
0.015477861277759075,
0.07150806486606598,
-0.07550184428691864,
-0.029803801327943802,
0.07138526439666748,
-0.04542798548936844,
0.036780230700969696,
-0.0441175252199173,
-0.08921962976455688,
-0.033601947128772736,
-0.013507927767932415,
-0.04785524681210518,
0.08367670327425003,
0.04809067025780678,
0.1160794124007225,
0.023182230070233345,
0.020466996356844902,
0.02308039367198944,
-0.09736190736293793,
-0.0644315630197525,
0.010976915247738361,
-0.021941209211945534,
-0.07193645089864731,
0.06136806681752205,
-0.06352002918720245,
-0.050369273871183395,
-0.06223204731941223,
0.02627229504287243,
0.04787946864962578,
0.037872105836868286,
-0.024847794324159622,
0.07423914968967438,
-0.02268412336707115,
-0.07690399140119553,
0.07566937059164047,
-0.04939069226384163,
-0.007172725163400173,
0.031942497938871384,
-0.007394266780465841,
-0.07504162937402725,
0.032054733484983444,
0.025817492976784706,
0.05133697763085365,
0.015724120661616325,
-0.03390660509467125,
0.02875606343150139,
0.005154615268111229,
-0.01813904382288456,
0.09739062935113907,
0.00546159315854311,
-0.07488802820444107,
0.059670589864254,
-0.034482441842556,
-0.04874109476804733,
-0.05773407220840454,
-0.04045472666621208,
-0.04162943735718727,
-0.05534512177109718,
-0.01347889844328165,
-0.005302093923091888,
0.010679076425731182,
-0.06803473830223083,
0.0014354619197547436,
0.10914624482393265,
0.0072700767777860165,
-0.03839089721441269,
0.006271838676184416,
-0.07567422837018967,
-0.009286902844905853,
-0.0751180425286293,
-0.014373749494552612,
-0.06052682548761368,
-0.1407099813222885,
-0.057650208473205566,
-0.011056984774768353,
-5.165925921775506e-33,
0.0529012568295002,
-0.030065378174185753,
0.014434177428483963,
0.07471238076686859,
-0.02403867244720459,
-0.04615533724427223,
0.03499860689043999,
0.02022579126060009,
0.013728504069149494,
-0.017266130074858665,
-0.12418712675571442,
0.08416401594877243,
0.0007765028858557343,
0.00827914010733366,
0.05352604016661644,
0.0767296776175499,
-0.16429506242275238,
-0.09039465337991714,
0.07434631139039993,
-0.04275331646203995,
0.0005500732804648578,
-0.013482770882546902,
-0.0015900010475888848,
0.06780784577131271,
-0.061900071799755096,
0.015219285152852535,
0.03162810951471329,
-0.01464790478348732,
0.021193889901041985,
0.026962140575051308,
-0.02893757075071335,
-0.020366894081234932,
0.006916208658367395,
0.03293374180793762,
-0.023540610447525978,
-0.05456151068210602,
0.028787320479750633,
0.13712424039840698,
0.005114635918289423,
-0.005643081851303577,
0.013132878579199314,
0.04905591160058975,
0.04816437140107155,
0.01989811100065708,
-0.011488543823361397,
0.06933808326721191,
0.03945222496986389,
0.01603388413786888,
-0.011987977661192417,
-0.06747301667928696,
0.04995004087686539,
-0.006658955477178097,
-0.08606355637311935,
0.03827188163995743,
-0.03805264085531235,
-0.08144522458314896,
-0.04277435317635536,
-0.06490616500377655,
-0.045544881373643875,
0.031114809215068817,
-0.031944505870342255,
-0.04415998235344887,
0.03240961208939552,
0.004936771467328072,
0.02681761048734188,
0.005690293852239847,
-0.08363252133131027,
-0.07375744730234146,
-0.007161627057939768,
-0.07571631669998169,
0.003450198331847787,
-0.07772690057754517,
0.029718682169914246,
0.034605275839567184,
0.04839380085468292,
0.029580730944871902,
0.004077727906405926,
-0.04155220836400986,
0.062058523297309875,
0.044825635850429535,
-0.03977993130683899,
-0.025409571826457977,
0.0015515091363340616,
0.11507242172956467,
-0.020914504304528236,
0.010669362731277943,
-0.02187409996986389,
0.20736822485923767,
-0.012061044573783875,
0.013117133639752865,
0.05642439052462578,
0.08918696641921997,
-0.0514831468462944,
0.02112780511379242,
-0.015896860510110855,
-5.015644077843717e-8,
-0.0811597928404808,
-0.05120036005973816,
-0.056339867413043976,
0.017938584089279175,
-0.07845085114240646,
0.033823005855083466,
0.0040766652673482895,
0.004798966459929943,
0.014035084284842014,
-0.034352220594882965,
-0.009595930576324463,
0.053451258689165115,
0.009298838675022125,
-0.07197225093841553,
0.006562915164977312,
0.01616261713206768,
-0.0538528636097908,
0.025002190843224525,
-0.04979982227087021,
0.0777820274233818,
0.015641968697309494,
0.015852145850658417,
0.014576059766113758,
-0.015808844938874245,
0.025675661861896515,
-0.017706725746393204,
-0.004444607999175787,
0.058819085359573364,
-0.021151024848222733,
0.05815834924578667,
0.022330446168780327,
0.11760507524013519,
0.01903134398162365,
0.01797107234597206,
-0.044283416122198105,
0.03203420341014862,
-0.01881404221057892,
-0.014546277932822704,
0.04828957840800285,
0.03406743332743645,
-0.006504204589873552,
0.01089777983725071,
-0.06440990418195724,
0.012427144683897495,
-0.08952177315950394,
-0.0029630735516548157,
-0.010342614725232124,
0.017291778698563576,
0.04901696741580963,
-0.025259407237172127,
-0.0250046756118536,
0.03364728391170502,
-0.04098569229245186,
0.04653508588671684,
-0.04897252470254898,
0.03887394815683365,
-0.03759259730577469,
-0.025086574256420135,
0.051662106066942215,
-0.020497135818004608,
0.03021840937435627,
-0.04810265824198723,
-0.009485778398811817,
0.04956698417663574
] | 0.078614
|
file: ```cjs const { parseEnv } = require('node:util'); parseEnv('HELLO=world\nHELLO=oh my\n'); // Returns: { HELLO: 'oh my' } ``` ```mjs import { parseEnv } from 'node:util'; parseEnv('HELLO=world\nHELLO=oh my\n'); // Returns: { HELLO: 'oh my' } ``` ## `util.promisify(original)` \* `original` {Function} \* Returns: {Function} Takes a function following the common error-first callback style, i.e. taking an `(err, value) => ...` callback as the last argument, and returns a version that returns promises. ```mjs import { promisify } from 'node:util'; import { stat } from 'node:fs'; const promisifiedStat = promisify(stat); promisifiedStat('.').then((stats) => { // Do something with `stats` }).catch((error) => { // Handle the error. }); ``` ```cjs const { promisify } = require('node:util'); const { stat } = require('node:fs'); const promisifiedStat = promisify(stat); promisifiedStat('.').then((stats) => { // Do something with `stats` }).catch((error) => { // Handle the error. }); ``` Or, equivalently using `async function`s: ```mjs import { promisify } from 'node:util'; import { stat } from 'node:fs'; const promisifiedStat = promisify(stat); async function callStat() { const stats = await promisifiedStat('.'); console.log(`This directory is owned by ${stats.uid}`); } callStat(); ``` ```cjs const { promisify } = require('node:util'); const { stat } = require('node:fs'); const promisifiedStat = promisify(stat); async function callStat() { const stats = await promisifiedStat('.'); console.log(`This directory is owned by ${stats.uid}`); } callStat(); ``` If there is an `original[util.promisify.custom]` property present, `promisify` will return its value, see [Custom promisified functions][]. `promisify()` assumes that `original` is a function taking a callback as its final argument in all cases. If `original` is not a function, `promisify()` will throw an error. If `original` is a function but its last argument is not an error-first callback, it will still be passed an error-first callback as its last argument. Using `promisify()` on class methods or other methods that use `this` may not work as expected unless handled specially: ```mjs import { promisify } from 'node:util'; class Foo { constructor() { this.a = 42; } bar(callback) { callback(null, this.a); } } const foo = new Foo(); const naiveBar = promisify(foo.bar); // TypeError: Cannot read properties of undefined (reading 'a') // naiveBar().then(a => console.log(a)); naiveBar.call(foo).then((a) => console.log(a)); // '42' const bindBar = naiveBar.bind(foo); bindBar().then((a) => console.log(a)); // '42' ``` ```cjs const { promisify } = require('node:util'); class Foo { constructor() { this.a = 42; } bar(callback) { callback(null, this.a); } } const foo = new Foo(); const naiveBar = promisify(foo.bar); // TypeError: Cannot read properties of undefined (reading 'a') // naiveBar().then(a => console.log(a)); naiveBar.call(foo).then((a) => console.log(a)); // '42' const bindBar = naiveBar.bind(foo); bindBar().then((a) => console.log(a)); // '42' ``` ### Custom promisified functions Using the `util.promisify.custom` symbol one can override the return value of [`util.promisify()`][]: ```mjs import { promisify } from 'node:util'; function doSomething(foo, callback) { // ... } doSomething[promisify.custom] = (foo) => { return getPromiseSomehow(); }; const promisified = promisify(doSomething); console.log(promisified === doSomething[promisify.custom]); // prints 'true' ``` ```cjs const { promisify } = require('node:util'); function doSomething(foo, callback) { // ... } doSomething[promisify.custom] = (foo) => { return getPromiseSomehow(); }; const promisified = promisify(doSomething); console.log(promisified === doSomething[promisify.custom]); // prints 'true' ``` This can be useful for cases where the original function does not follow the standard format of taking an error-first callback as the last argument. For example, with a function that takes in `(foo, onSuccessCallback, onErrorCallback)`: ```js doSomething[util.promisify.custom] = (foo) => { return new Promise((resolve, reject) => { doSomething(foo, resolve, reject); }); }; ``` If `promisify.custom` is defined but is not a function, `promisify()` will throw an error. ### `util.promisify.custom` \* Type: {symbol} that can be used to declare custom promisified variants of functions, see [Custom promisified functions][]. In addition to being accessible through `util.promisify.custom`, this symbol
|
https://github.com/nodejs/node/blob/main//doc/api/util.md
|
main
|
nodejs
|
[
-0.13590359687805176,
0.07128443568944931,
0.06519049406051636,
0.040905341506004333,
-0.005915553774684668,
-0.06250231713056564,
-0.037769120186567307,
0.05486185476183891,
0.038961704820394516,
-0.053265344351530075,
-0.03166481852531433,
0.018609367311000824,
-0.052846819162368774,
-0.03514745086431503,
0.04839685186743736,
-0.02851429022848606,
-0.05763942003250122,
0.01299525797367096,
-0.02416239306330681,
-0.07915396243333817,
-0.0075670876540243626,
0.02853240631520748,
-0.0021957268472760916,
0.0044454364106059074,
-0.00430322764441371,
-0.03817905858159065,
-0.03947168216109276,
0.05331510305404663,
0.05769260972738266,
-0.037342555820941925,
0.06280459463596344,
-0.034696534276008606,
0.001907249097712338,
0.05101214349269867,
-0.044508323073387146,
0.17805977165699005,
-0.09320904314517975,
-0.0984308198094368,
-0.010685657151043415,
-0.018407154828310013,
0.01908809319138527,
0.11409818381071091,
-0.062075175344944,
-0.044770754873752594,
0.11644542217254639,
-0.029591966420412064,
-0.00565350241959095,
0.03559795022010803,
-0.09984143078327179,
0.03958713263273239,
0.019243862479925156,
0.030565796419978142,
-0.07556585967540741,
0.0012949324445798993,
0.060321688652038574,
0.015508463606238365,
-0.005919951014220715,
-0.008186254650354385,
0.009802518412470818,
-0.005021644290536642,
-0.0372588150203228,
-0.02555830217897892,
0.030408186838030815,
-0.04723741114139557,
0.09663204103708267,
-0.05967739224433899,
-0.03187547251582146,
0.07360853999853134,
-0.007640605792403221,
0.07416026294231415,
-0.07355178147554398,
0.01915501058101654,
-0.015708141028881073,
0.0402069166302681,
-0.06543378531932831,
0.021168960258364677,
-0.0283336341381073,
0.005830409005284309,
-0.03736945986747742,
0.022805169224739075,
-0.02401668205857277,
-0.048391375690698624,
0.010190300643444061,
-0.005108446814119816,
0.0007504867971874774,
0.038192372769117355,
-0.05362173542380333,
0.005951265804469585,
0.06153834983706474,
-0.04391592741012573,
-0.06532109528779984,
-0.06475193798542023,
-0.09629955142736435,
0.06440814584493637,
0.017430871725082397,
0.06873136013746262,
-0.002458618488162756,
-0.06052468344569206,
0.011162943206727505,
0.06986935436725616,
-0.019719528034329414,
0.011762921698391438,
0.10253746807575226,
-0.0550837405025959,
0.0104542700573802,
0.053710952401161194,
-0.039233651012182236,
-0.04115721955895424,
0.01629437692463398,
-0.02217227593064308,
-0.027847496792674065,
0.046970635652542114,
-0.001297012553550303,
-0.010122360661625862,
-0.02673073671758175,
-0.031694844365119934,
0.03613542392849922,
-0.06222422793507576,
0.06983686983585358,
0.07663873583078384,
0.05694804713129997,
0.03259913995862007,
0.03949116915464401,
0.05238619074225426,
0.007316699251532555,
-0.029160339385271072,
0.05622391402721405,
5.9956537520912025e-33,
-0.05207094922661781,
-0.0742669478058815,
0.008825302124023438,
0.011970019899308681,
0.05440368875861168,
0.011990134604275227,
0.06596744060516357,
-0.056568801403045654,
-0.15793830156326294,
-0.028671758249402046,
-0.011291412636637688,
-0.014528494328260422,
-0.014315092004835606,
-0.04862990602850914,
-0.025771645829081535,
0.02144346944987774,
0.10161997377872467,
0.021173836663365364,
0.021852685138583183,
0.050816070288419724,
0.0530506931245327,
-0.03264213353395462,
-0.028047816827893257,
-0.0011299209436401725,
0.03214854747056961,
-0.030404116958379745,
0.043954037129879,
0.03746025264263153,
0.031037671491503716,
-0.05331059545278549,
0.06503873318433762,
-0.02617458812892437,
0.03808339685201645,
-0.013059199787676334,
0.046336911618709564,
-0.03323359042406082,
0.025375183671712875,
-0.020864244550466537,
-0.11363514512777328,
-0.06883424520492554,
-0.005061109084635973,
0.10967890918254852,
-0.05973496288061142,
0.06601548194885254,
-0.03526943176984787,
-0.08217960596084595,
-0.05100472643971443,
0.007144422736018896,
0.07622328400611877,
-0.03660036250948906,
-0.007691692560911179,
0.0650542750954628,
0.051098164170980453,
-0.09697611629962921,
0.08264729380607605,
-0.016234004870057106,
0.02731584757566452,
0.014320462010800838,
-0.0007197677623480558,
-0.044148918241262436,
0.0874900221824646,
-0.022041548043489456,
-0.06537910550832748,
-0.010144665837287903,
0.008835437707602978,
-0.00011145868484163657,
-0.03526753559708595,
0.0862058475613594,
0.029756741598248482,
0.009187709540128708,
-0.032765064388513565,
0.005875604692846537,
-0.07602839171886444,
0.031159743666648865,
0.03805334493517876,
-0.007395192515105009,
-0.0758296549320221,
-0.05956340953707695,
0.01785607635974884,
-0.12866872549057007,
-0.018549315631389618,
-0.007039772346615791,
-0.07143254578113556,
0.11890946328639984,
0.054840292781591415,
0.02319270372390747,
-0.03731980547308922,
-0.026810208335518837,
0.048552755266427994,
0.040478553622961044,
-0.00409075478091836,
-0.04906131327152252,
-0.04646295681595802,
-0.07283185422420502,
-0.09588293731212616,
-7.053367242380943e-33,
-0.0053970119915902615,
0.06935789436101913,
-0.07875610142946243,
0.13390660285949707,
-0.0022679606918245554,
-0.061426930129528046,
-0.02473369427025318,
-0.009476281702518463,
0.02858867682516575,
0.004915165714919567,
-0.03502756729722023,
0.01906159520149231,
0.1122099757194519,
0.01952338218688965,
0.06007521227002144,
0.07335038483142853,
-0.0681309700012207,
-0.031838998198509216,
-0.007126813288778067,
-0.0314737968146801,
-0.006199121940881014,
0.0048804208636283875,
0.03732670843601227,
0.031978558748960495,
-0.10977219045162201,
0.05308076739311218,
-0.015827257186174393,
0.026769200339913368,
-0.032393909990787506,
0.0005027304287068546,
-0.1106337159872055,
-0.011667798273265362,
-0.09598773717880249,
0.0578630194067955,
0.0248034056276083,
-0.0460674911737442,
-0.007490694522857666,
0.08855945616960526,
-0.02965693175792694,
-0.04217061772942543,
0.06191781163215637,
-0.011518118903040886,
-0.06032247096300125,
0.000587653077673167,
-0.03251812234520912,
-0.01806733012199402,
0.04401789605617523,
0.02388150244951248,
0.045853521674871445,
-0.05684187635779381,
-0.0472109280526638,
-0.00550936721265316,
-0.019699132069945335,
0.050259996205568314,
-0.057845890522003174,
-0.04825209826231003,
0.017650198191404343,
-0.019838601350784302,
0.015016400255262852,
0.007379811257123947,
-0.04994877800345421,
-0.12746211886405945,
0.03662118315696716,
-0.04862755537033081,
0.0023925930727273226,
-0.009309466928243637,
-0.12053585052490234,
-0.0163596011698246,
0.10823977738618851,
-0.00275984313338995,
0.0037430101074278355,
0.05137309804558754,
0.01635538414120674,
0.00026561482809484005,
0.006258081644773483,
-0.00614234758540988,
-0.011117272078990936,
-0.09530282765626907,
0.05813543125987053,
0.10236074775457382,
-0.0030373376794159412,
0.04807668551802635,
0.020092938095331192,
0.019787749275565147,
0.04481897130608559,
-0.03362996503710747,
0.039353348314762115,
0.04618193581700325,
-0.05025921016931534,
0.017875559628009796,
0.049615297466516495,
0.036114804446697235,
-0.06769780814647675,
-0.04889939725399017,
-0.026189584285020828,
-5.743396869206663e-8,
-0.11160597205162048,
-0.043115559965372086,
-0.06371399760246277,
-0.007442070636898279,
-0.010288097895681858,
0.014034342020750046,
-0.006326096132397652,
-0.045768097043037415,
0.02398262917995453,
-0.06462866067886353,
0.01461364421993494,
0.010945250280201435,
0.08209491521120071,
-0.03470234572887421,
-0.005383166950196028,
0.03890014812350273,
0.02687348984181881,
0.034112781286239624,
-0.054125428199768066,
0.030671369284391403,
-0.06365779787302017,
0.0680881142616272,
0.00824566651135683,
-0.012262243777513504,
0.03328053280711174,
0.008847642689943314,
0.0420849472284317,
0.02921147085726261,
-0.005716611631214619,
-0.009039126336574554,
0.011097454465925694,
0.025540364906191826,
0.10922659933567047,
0.016141129657626152,
-0.042841240763664246,
0.017525851726531982,
0.039932236075401306,
0.049316149204969406,
0.0912238135933876,
0.01714794524013996,
0.05355610325932503,
0.041435033082962036,
-0.07018829882144928,
0.05481415614485741,
-0.04729850962758064,
-0.05539236590266228,
0.002841607201844454,
-0.0037706615403294563,
0.024382244795560837,
-0.03843321651220322,
0.051520589739084244,
-0.0862436294555664,
-0.04417775198817253,
-0.010158640332520008,
0.04734969511628151,
-0.0340423658490181,
0.005536849610507488,
-0.04550451785326004,
-0.022130850702524185,
-0.012089606374502182,
0.05885285139083862,
-0.008022456429898739,
0.09685734659433365,
-0.053468625992536545
] | 0.114829
|
{ doSomething(foo, resolve, reject); }); }; ``` If `promisify.custom` is defined but is not a function, `promisify()` will throw an error. ### `util.promisify.custom` \* Type: {symbol} that can be used to declare custom promisified variants of functions, see [Custom promisified functions][]. In addition to being accessible through `util.promisify.custom`, this symbol is [registered globally][global symbol registry] and can be accessed in any environment as `Symbol.for('nodejs.util.promisify.custom')`. For example, with a function that takes in `(foo, onSuccessCallback, onErrorCallback)`: ```js const kCustomPromisifiedSymbol = Symbol.for('nodejs.util.promisify.custom'); doSomething[kCustomPromisifiedSymbol] = (foo) => { return new Promise((resolve, reject) => { doSomething(foo, resolve, reject); }); }; ``` ## `util.stripVTControlCharacters(str)` \* `str` {string} \* Returns: {string} Returns `str` with any ANSI escape codes removed. ```js console.log(util.stripVTControlCharacters('\u001B[4mvalue\u001B[0m')); // Prints "value" ``` ## `util.styleText(format, text[, options])` \* `format` {string | Array} A text format or an Array of text formats defined in `util.inspect.colors`. \* `text` {string} The text to to be formatted. \* `options` {Object} \* `validateStream` {boolean} When true, `stream` is checked to see if it can handle colors. \*\*Default:\*\* `true`. \* `stream` {Stream} A stream that will be validated if it can be colored. \*\*Default:\*\* `process.stdout`. This function returns a formatted text considering the `format` passed for printing in a terminal. It is aware of the terminal's capabilities and acts according to the configuration set via `NO\_COLOR`, `NODE\_DISABLE\_COLORS` and `FORCE\_COLOR` environment variables. ```mjs import { styleText } from 'node:util'; import { stderr } from 'node:process'; const successMessage = styleText('green', 'Success!'); console.log(successMessage); const errorMessage = styleText( 'red', 'Error! Error!', // Validate if process.stderr has TTY { stream: stderr }, ); console.error(errorMessage); ``` ```cjs const { styleText } = require('node:util'); const { stderr } = require('node:process'); const successMessage = styleText('green', 'Success!'); console.log(successMessage); const errorMessage = styleText( 'red', 'Error! Error!', // Validate if process.stderr has TTY { stream: stderr }, ); console.error(errorMessage); ``` `util.inspect.colors` also provides text formats such as `italic`, and `underline` and you can combine both: ```cjs console.log( util.styleText(['underline', 'italic'], 'My italic underlined message'), ); ``` When passing an array of formats, the order of the format applied is left to right so the following style might overwrite the previous one. ```cjs console.log( util.styleText(['red', 'green'], 'text'), // green ); ``` The special format value `none` applies no additional styling to the text. The full list of formats can be found in [modifiers][]. ## Class: `util.TextDecoder` An implementation of the [WHATWG Encoding Standard][] `TextDecoder` API. ```js const decoder = new TextDecoder(); const u8arr = new Uint8Array([72, 101, 108, 108, 111]); console.log(decoder.decode(u8arr)); // Hello ``` ### WHATWG supported encodings Per the [WHATWG Encoding Standard][], the encodings supported by the `TextDecoder` API are outlined in the tables below. For each encoding, one or more aliases may be used. Different Node.js build configurations support different sets of encodings. (see [Internationalization][]) #### Encodings supported by default (with full ICU data) | Encoding | Aliases | | ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `'ibm866'` | `'866'`, `'cp866'`, `'csibm866'` | | `'iso-8859-2'` | `'csisolatin2'`, `'iso-ir-101'`, `'iso8859-2'`, `'iso88592'`, `'iso\_8859-2'`, `'iso\_8859-2:1987'`, `'l2'`, `'latin2'` | | `'iso-8859-3'` | `'csisolatin3'`, `'iso-ir-109'`, `'iso8859-3'`, `'iso88593'`, `'iso\_8859-3'`, `'iso\_8859-3:1988'`, `'l3'`, `'latin3'` | | `'iso-8859-4'` | `'csisolatin4'`, `'iso-ir-110'`, `'iso8859-4'`, `'iso88594'`, `'iso\_8859-4'`, `'iso\_8859-4:1988'`, `'l4'`, `'latin4'` | | `'iso-8859-5'` | `'csisolatincyrillic'`, `'cyrillic'`, `'iso-ir-144'`, `'iso8859-5'`, `'iso88595'`, `'iso\_8859-5'`, `'iso\_8859-5:1988'` | | `'iso-8859-6'` | `'arabic'`, `'asmo-708'`, `'csiso88596e'`, `'csiso88596i'`, `'csisolatinarabic'`, `'ecma-114'`, `'iso-8859-6-e'`, `'iso-8859-6-i'`, `'iso-ir-127'`, `'iso8859-6'`, `'iso88596'`, `'iso\_8859-6'`, `'iso\_8859-6:1987'` | | `'iso-8859-7'` | `'csisolatingreek'`, `'ecma-118'`, `'elot\_928'`, `'greek'`, `'greek8'`, `'iso-ir-126'`, `'iso8859-7'`, `'iso88597'`, `'iso\_8859-7'`, `'iso\_8859-7:1987'`, `'sun\_eu\_greek'` | | `'iso-8859-8'` | `'csiso88598e'`, `'csisolatinhebrew'`, `'hebrew'`, `'iso-8859-8-e'`, `'iso-ir-138'`, `'iso8859-8'`, `'iso88598'`, `'iso\_8859-8'`, `'iso\_8859-8:1988'`, `'visual'` | | `'iso-8859-8-i'` | `'csiso88598i'`, `'logical'` | | `'iso-8859-10'` | `'csisolatin6'`, `'iso-ir-157'`, `'iso8859-10'`, `'iso885910'`, `'l6'`, `'latin6'` | | `'iso-8859-13'` | `'iso8859-13'`, `'iso885913'` | | `'iso-8859-14'` | `'iso8859-14'`, `'iso885914'`
|
https://github.com/nodejs/node/blob/main//doc/api/util.md
|
main
|
nodejs
|
[
-0.028953371569514275,
0.046830371022224426,
0.07119148224592209,
0.02403087168931961,
-0.042232684791088104,
0.00477075157687068,
0.025578955188393593,
0.025772973895072937,
0.02598513849079609,
-0.04066552594304085,
-0.024807434529066086,
-0.0075617218390107155,
-0.03984053432941437,
-0.01162952370941639,
0.07931087166070938,
-0.00653777876868844,
0.03770068660378456,
-0.037257250398397446,
-0.005519814323633909,
0.010072347708046436,
0.03039713017642498,
-0.004415854811668396,
-0.0030229156836867332,
-0.005284611601382494,
-0.05349697545170784,
-0.04103809595108032,
0.010562950745224953,
0.006577830296009779,
0.06762484461069107,
0.0054832701571285725,
0.020334744825959206,
0.026300102472305298,
-0.08715975284576416,
0.04183368757367134,
-0.050252899527549744,
0.11403163522481918,
-0.04296794906258583,
-0.06023823469877243,
0.04283694922924042,
-0.05819205194711685,
0.060673896223306656,
0.04742728918790817,
-0.0737966001033783,
-0.043225038796663284,
0.08332651108503342,
-0.04224437475204468,
0.008370602503418922,
-0.013938275165855885,
-0.12327524274587631,
-0.00455179437994957,
0.0868750810623169,
-0.019098853692412376,
-0.04970794916152954,
-0.004371405113488436,
0.04393342509865761,
-0.007347858045250177,
-0.030576225370168686,
-0.0402405820786953,
0.061349935829639435,
-0.015509402379393578,
-0.05113554000854492,
-0.04407268017530441,
0.05201101675629616,
-0.03204274922609329,
0.0190195944160223,
-0.002099639503285289,
-0.024751195684075356,
0.055864833295345306,
0.0432719960808754,
0.07590901851654053,
-0.029191620647907257,
-0.006093714386224747,
0.06132262945175171,
0.08324315398931503,
0.0015202176291495562,
-0.0057427301071584225,
0.015669170767068863,
0.002453179331496358,
-0.07394039630889893,
-0.022818680852651596,
-0.07366405427455902,
-0.01911919377744198,
0.04591340571641922,
0.008544477634131908,
0.006087539717555046,
0.0971260666847229,
-0.08541377633810043,
-0.014698532409965992,
0.07382317632436752,
-0.0010384800843894482,
-0.044908735901117325,
-0.06764800101518631,
-0.08435767889022827,
-0.03335251659154892,
-0.008482681587338448,
0.0019079056801274419,
-0.010976415127515793,
-0.08361662179231644,
0.03101145103573799,
0.07498344033956528,
-0.00032479214132763445,
-0.0027701708022505045,
0.05368020012974739,
-0.10282345116138458,
0.057521119713783264,
0.09633328020572662,
-0.06377949565649033,
-0.05841076746582985,
-0.0013354604598134756,
-0.00778574962168932,
-0.042156197130680084,
-0.008218087255954742,
0.06414230912923813,
-0.04560904577374458,
-0.002321412554010749,
0.06859444826841354,
0.010631909593939781,
-0.04153363034129143,
0.07335302978754044,
0.024404412135481834,
0.054174501448869705,
-0.0104058887809515,
0.09054889529943466,
-0.026947950944304466,
0.010354755446314812,
0.021903838962316513,
-0.049866318702697754,
5.500843731449961e-33,
0.005468369927257299,
-0.004647788591682911,
-0.07753680646419525,
0.03940167650580406,
0.022629860788583755,
-0.007121393922716379,
0.03892957791686058,
-0.03785177320241928,
-0.06725871562957764,
-0.00329496618360281,
0.0755516067147255,
0.0521746464073658,
-0.0324702225625515,
-0.023500243201851845,
0.028367584571242332,
0.04746110737323761,
0.0874866172671318,
0.03280160576105118,
-0.006757502444088459,
0.034747593104839325,
0.028892043977975845,
-0.03068472631275654,
-0.07232790440320969,
0.04565085470676422,
-0.03544717654585838,
-0.01354621909558773,
0.027037836611270905,
0.054381441324949265,
-0.020784439519047737,
-0.033539071679115295,
0.04433252289891243,
0.01130744069814682,
-0.011136102490127087,
0.08206482231616974,
0.048088110983371735,
0.010610652156174183,
-0.0034035569988191128,
-0.01249024085700512,
-0.09339895099401474,
-0.0316428579390049,
0.0024765089619904757,
0.021738357841968536,
-0.09592822194099426,
0.02436915971338749,
0.021256759762763977,
-0.09166993200778961,
0.005089260172098875,
-0.07420684397220612,
0.09136898815631866,
-0.09325720369815826,
-0.034897059202194214,
0.05914846062660217,
0.037930313497781754,
-0.057426854968070984,
0.1234460398554802,
0.004571169149130583,
0.018704893067479134,
0.03230590745806694,
0.04412665218114853,
-0.029163740575313568,
0.027401985600590706,
-0.03765358030796051,
-0.05261186137795448,
-0.029495634138584137,
-0.04405059292912483,
0.03732724115252495,
-0.0631587877869606,
0.004761537536978722,
-0.023587699979543686,
-0.03912552073597908,
0.008183511905372143,
0.024798765778541565,
0.02310020849108696,
0.0350830964744091,
0.048571716994047165,
-0.016595743596553802,
-0.04914064705371857,
-0.001743098022416234,
-0.001880289288237691,
-0.11421164870262146,
-0.03715338930487633,
0.006001302041113377,
-0.08576269447803497,
0.15305165946483612,
0.04814181476831436,
0.004977729171514511,
0.003992924932390451,
-0.03635604307055473,
0.03358624503016472,
-0.007147063035517931,
-0.058199744671583176,
0.009361582808196545,
-0.09054722636938095,
-0.06354396790266037,
-0.07930336147546768,
-7.460964031056817e-33,
0.016875574365258217,
0.09151598811149597,
-0.08693819493055344,
0.07474685460329056,
-0.0171982292085886,
-0.02722691185772419,
0.01724034920334816,
-0.029877472668886185,
-0.0006013518432155252,
-0.08726975321769714,
0.0064961607567965984,
0.0009463119204156101,
0.09055734425783157,
0.006697418633848429,
-0.006397828925400972,
0.04708664491772652,
-0.09735830128192902,
-0.044221896678209305,
0.023414090275764465,
-0.047784313559532166,
-0.018726784735918045,
0.0231401938945055,
-0.010807075537741184,
0.0041507515124976635,
-0.1080196276307106,
0.05681564286351204,
-0.07445208728313446,
0.018287742510437965,
0.013269112445414066,
0.014616071246564388,
-0.058576688170433044,
-0.0025764775928109884,
-0.06200804561376572,
0.006907321512699127,
0.050401706248521805,
-0.06809459626674652,
-0.0627288743853569,
0.020906878635287285,
-0.05558916926383972,
-0.058717336505651474,
0.015811165794730186,
-0.03189985454082489,
-0.0361015722155571,
0.025075897574424744,
-0.015636155381798744,
-0.02834935113787651,
-0.004379380960017443,
-0.04494018852710724,
0.13970410823822021,
-0.0935295820236206,
-0.012866968289017677,
-0.027371302247047424,
-0.017494382336735725,
0.04121055081486702,
-0.09179061651229858,
0.017620569095015526,
0.07494159042835236,
-0.03323289752006531,
0.053085438907146454,
0.07127528637647629,
-0.0020422046072781086,
-0.12181701511144638,
0.08940518647432327,
0.006874361075460911,
-0.03720775991678238,
-0.023540455847978592,
-0.08383992314338684,
-0.037933140993118286,
0.09582174569368362,
0.05408664792776108,
-0.026490630581974983,
0.01656923070549965,
0.008768073283135891,
-0.0024057647679001093,
0.04489513859152794,
0.00017070760077331215,
0.03680834174156189,
-0.06482027471065521,
0.050855547189712524,
0.11288540065288544,
-0.03446679934859276,
0.031481802463531494,
-0.017853885889053345,
-0.0009087042999453843,
0.03240519389510155,
-0.01247184444218874,
-0.07601554691791534,
0.09126628190279007,
-0.08508064597845078,
-0.012363455258309841,
0.02950822189450264,
-0.025516755878925323,
-0.10377514362335205,
-0.018700918182730675,
-0.05083907023072243,
-5.481001608131919e-8,
-0.13866537809371948,
0.007703201845288277,
-0.062313832342624664,
-0.06475303322076797,
-0.02083856426179409,
0.029667645692825317,
-0.01479949802160263,
-0.08333862572908401,
-0.016398504376411438,
-0.03984340280294418,
-0.0629577562212944,
0.06044786050915718,
0.0508454255759716,
-0.013825882226228714,
-0.009339122101664543,
-0.02359897643327713,
-0.01049250178039074,
0.07482267171144485,
-0.07158670574426651,
0.024500597268342972,
-0.023836756125092506,
0.049167465418577194,
-0.015111261047422886,
-0.08835949748754501,
-0.0025259037502110004,
0.017439691349864006,
0.05955061316490173,
0.08974207192659378,
-0.02705313265323639,
0.06419464945793152,
-0.043307114392519,
0.06652331352233887,
0.048639386892318726,
0.02915191650390625,
0.007160222623497248,
0.05291888862848282,
0.011988711543381214,
0.037427399307489395,
0.10832659900188446,
0.10807006806135178,
0.07373381406068802,
-0.05707018822431564,
-0.09773305803537369,
0.0624329075217247,
-0.0228571854531765,
0.01766006462275982,
0.05695105344057083,
0.04463518038392067,
0.01442218478769064,
0.04568713158369064,
-0.00521960249170661,
-0.005053234286606312,
-0.09189800918102264,
0.025927869603037834,
0.010101337917149067,
0.03687479346990585,
-0.019686859101057053,
-0.04889984801411629,
-0.06173337996006012,
-0.015533185563981533,
0.0205497108399868,
-0.014046325348317623,
0.09577000886201859,
-0.07618283480405807
] | 0.102329
|
`'greek'`, `'greek8'`, `'iso-ir-126'`, `'iso8859-7'`, `'iso88597'`, `'iso\_8859-7'`, `'iso\_8859-7:1987'`, `'sun\_eu\_greek'` | | `'iso-8859-8'` | `'csiso88598e'`, `'csisolatinhebrew'`, `'hebrew'`, `'iso-8859-8-e'`, `'iso-ir-138'`, `'iso8859-8'`, `'iso88598'`, `'iso\_8859-8'`, `'iso\_8859-8:1988'`, `'visual'` | | `'iso-8859-8-i'` | `'csiso88598i'`, `'logical'` | | `'iso-8859-10'` | `'csisolatin6'`, `'iso-ir-157'`, `'iso8859-10'`, `'iso885910'`, `'l6'`, `'latin6'` | | `'iso-8859-13'` | `'iso8859-13'`, `'iso885913'` | | `'iso-8859-14'` | `'iso8859-14'`, `'iso885914'` | | `'iso-8859-15'` | `'csisolatin9'`, `'iso8859-15'`, `'iso885915'`, `'iso\_8859-15'`, `'l9'` | | `'koi8-r'` | `'cskoi8r'`, `'koi'`, `'koi8'`, `'koi8\_r'` | | `'koi8-u'` | `'koi8-ru'` | | `'macintosh'` | `'csmacintosh'`, `'mac'`, `'x-mac-roman'` | | `'windows-874'` | `'dos-874'`, `'iso-8859-11'`, `'iso8859-11'`, `'iso885911'`, `'tis-620'` | | `'windows-1250'` | `'cp1250'`, `'x-cp1250'` | | `'windows-1251'` | `'cp1251'`, `'x-cp1251'` | | `'windows-1252'` | `'ansi\_x3.4-1968'`, `'ascii'`, `'cp1252'`, `'cp819'`, `'csisolatin1'`, `'ibm819'`, `'iso-8859-1'`, `'iso-ir-100'`, `'iso8859-1'`, `'iso88591'`, `'iso\_8859-1'`, `'iso\_8859-1:1987'`, `'l1'`, `'latin1'`, `'us-ascii'`, `'x-cp1252'` | | `'windows-1253'` | `'cp1253'`, `'x-cp1253'` | | `'windows-1254'` | `'cp1254'`, `'csisolatin5'`, `'iso-8859-9'`, `'iso-ir-148'`, `'iso8859-9'`, `'iso88599'`, `'iso\_8859-9'`, `'iso\_8859-9:1989'`, `'l5'`, `'latin5'`, `'x-cp1254'` | | `'windows-1255'` | `'cp1255'`, `'x-cp1255'` | | `'windows-1256'` | `'cp1256'`, `'x-cp1256'` | | `'windows-1257'` | `'cp1257'`, `'x-cp1257'` | | `'windows-1258'` | `'cp1258'`, `'x-cp1258'` | | `'x-mac-cyrillic'` | `'x-mac-ukrainian'` | | `'gbk'` | `'chinese'`, `'csgb2312'`, `'csiso58gb231280'`, `'gb2312'`, `'gb\_2312'`, `'gb\_2312-80'`, `'iso-ir-58'`, `'x-gbk'` | | `'gb18030'` | | | `'big5'` | `'big5-hkscs'`, `'cn-big5'`, `'csbig5'`, `'x-x-big5'` | | `'euc-jp'` | `'cseucpkdfmtjapanese'`, `'x-euc-jp'` | | `'iso-2022-jp'` | `'csiso2022jp'` | | `'shift\_jis'` | `'csshiftjis'`, `'ms932'`, `'ms\_kanji'`, `'shift-jis'`, `'sjis'`, `'windows-31j'`, `'x-sjis'` | | `'euc-kr'` | `'cseuckr'`, `'csksc56011987'`, `'iso-ir-149'`, `'korean'`, `'ks\_c\_5601-1987'`, `'ks\_c\_5601-1989'`, `'ksc5601'`, `'ksc\_5601'`, `'windows-949'` | #### Encodings supported when Node.js is built with the `small-icu` option | Encoding | Aliases | | ------------ | ------------------------------- | | `'utf-8'` | `'unicode-1-1-utf-8'`, `'utf8'` | | `'utf-16le'` | `'utf-16'` | | `'utf-16be'` | | #### Encodings supported when ICU is disabled | Encoding | Aliases | | ------------ | ------------------------------- | | `'utf-8'` | `'unicode-1-1-utf-8'`, `'utf8'` | | `'utf-16le'` | `'utf-16'` | The `'iso-8859-16'` encoding listed in the [WHATWG Encoding Standard][] is not supported. ### `new TextDecoder([encoding[, options]])` \* `encoding` {string} Identifies the `encoding` that this `TextDecoder` instance supports. \*\*Default:\*\* `'utf-8'`. \* `options` {Object} \* `fatal` {boolean} `true` if decoding failures are fatal. This option is not supported when ICU is disabled (see [Internationalization][]). \*\*Default:\*\* `false`. \* `ignoreBOM` {boolean} When `true`, the `TextDecoder` will include the byte order mark in the decoded result. When `false`, the byte order mark will be removed from the output. This option is only used when `encoding` is `'utf-8'`, `'utf-16be'`, or `'utf-16le'`. \*\*Default:\*\* `false`. Creates a new `TextDecoder` instance. The `encoding` may specify one of the supported encodings or an alias. The `TextDecoder` class is also available on the global object. ### `textDecoder.decode([input[, options]])` \* `input` {ArrayBuffer|DataView|TypedArray} An `ArrayBuffer`, `DataView`, or `TypedArray` instance containing the encoded data. \* `options` {Object} \* `stream` {boolean} `true` if additional chunks of data are expected. \*\*Default:\*\* `false`. \* Returns: {string} Decodes the `input` and returns a string. If `options.stream` is `true`, any incomplete byte sequences occurring at the end of the `input` are buffered internally and emitted after the next call to `textDecoder.decode()`. If `textDecoder.fatal` is `true`, decoding errors that occur will result in a `TypeError` being thrown. ### `textDecoder.encoding` \* Type: {string} The encoding supported by the `TextDecoder` instance. ### `textDecoder.fatal` \* Type: {boolean} The value will be `true` if decoding errors result in a `TypeError` being thrown. ### `textDecoder.ignoreBOM` \* Type: {boolean} The value will be `true` if the decoding result will include the byte order mark. ## Class: `util.TextEncoder` An implementation of the [WHATWG Encoding Standard][] `TextEncoder` API. All instances of `TextEncoder` only support UTF-8 encoding. ```js const encoder = new TextEncoder(); const uint8array = encoder.encode('this is some data'); ``` The `TextEncoder` class is also available on the global object. ### `textEncoder.encode([input])` \* `input`
|
https://github.com/nodejs/node/blob/main//doc/api/util.md
|
main
|
nodejs
|
[
0.01973061077296734,
-0.011559699662029743,
-0.0006923857727088034,
-0.03850824758410454,
-0.044368926435709,
-0.0039963689632713795,
0.08107024431228638,
-0.0028263204731047153,
0.006497986614704132,
0.0177520252764225,
0.1259240061044693,
-0.04297667369246483,
0.02591864764690399,
0.048292048275470734,
-0.022724639624357224,
-0.056289203464984894,
-0.06819489598274231,
0.02335510402917862,
-0.02501131407916546,
-0.12697559595108032,
-0.00178138364572078,
0.04584468528628349,
0.04934914410114288,
-0.025548165664076805,
0.038915541023015976,
0.006251414306461811,
-0.07630259543657303,
0.0675673633813858,
0.03417707234621048,
-0.09988665580749512,
-0.053368013352155685,
0.04846544936299324,
0.08441884815692902,
0.03455166146159172,
0.06494642794132233,
0.024280399084091187,
-0.025301937013864517,
-0.016216179355978966,
0.005570606328547001,
0.04944740608334541,
-0.025702429935336113,
-0.06781802326440811,
0.03471595048904419,
0.021111246198415756,
-0.023324783891439438,
0.025230037048459053,
-0.07650603353977203,
0.015592644922435284,
-0.035250697284936905,
0.005167779512703419,
-0.12568338215351105,
0.011654438450932503,
-0.040716152638196945,
0.11499182879924774,
-0.01499851979315281,
-0.045174527913331985,
-0.0037571608554571867,
0.010557501576840878,
-0.03477418050169945,
-0.014205229468643665,
-0.02918410114943981,
0.004362944979220629,
-0.07571259140968323,
0.04324540123343468,
-0.10064606368541718,
0.03916536644101143,
0.022214708849787712,
-0.012127624824643135,
-0.010531594976782799,
0.04272667318582535,
-0.062458910048007965,
0.010920703411102295,
-0.03606225922703743,
0.12030515819787979,
-0.12321712076663971,
0.05281607434153557,
0.05988505482673645,
-0.07661042362451553,
-0.01770191639661789,
-0.08102605491876602,
-0.08172039687633514,
-0.0011853256728500128,
-0.030158914625644684,
0.05405903607606888,
-0.0023059332743287086,
0.017332689836621284,
-0.026036441326141357,
0.029710110276937485,
-0.04263206571340561,
-0.020563215017318726,
-0.028842568397521973,
-0.018665816634893417,
0.08325785398483276,
-0.012483585625886917,
-0.02040398307144642,
0.049408625811338425,
0.07547999918460846,
0.06841658800840378,
-0.012662770226597786,
0.05750162526965141,
0.027794839814305305,
-0.023429837077856064,
-0.02366865798830986,
-0.05992059037089348,
-0.07150287181138992,
-0.023166513070464134,
-0.04814234375953674,
-0.04323045536875725,
0.031336601823568344,
-0.021119585260748863,
-0.06746915727853775,
-0.05600162595510483,
-0.024972885847091675,
-0.1225428432226181,
-0.0055181654170155525,
0.007786550093442202,
0.00447137700393796,
0.04172976687550545,
0.0826365128159523,
0.04336588829755783,
-0.06183256208896637,
-0.022989816963672638,
0.0009016867843456566,
0.055352240800857544,
-0.033624883741140366,
-0.043381426483392715,
0.0008082789136096835,
1.0835607743543996e-33,
0.021023377776145935,
0.0424220971763134,
0.022941283881664276,
-0.03391346335411072,
-0.013048190623521805,
0.006550487596541643,
-0.08174709975719452,
-0.010611100122332573,
-0.09606781601905823,
0.012177935801446438,
-0.07438018172979355,
0.03983466699719429,
-0.062393806874752045,
0.05860544368624687,
0.07660318911075592,
0.03538607060909271,
0.057595133781433105,
0.006590245291590691,
-0.1047842800617218,
0.0005021172109991312,
0.0032904979307204485,
0.03956450894474983,
0.03038688935339451,
0.01214398629963398,
-0.021306607872247696,
-0.0144199188798666,
0.03892200440168381,
-0.033872090280056,
0.009315556846559048,
0.028064625337719917,
-0.012543543241918087,
-0.041744209825992584,
-0.02694176696240902,
-0.022266244515776634,
-0.006877163890749216,
-0.0036478855181485415,
-0.12232033908367157,
0.008432368747889996,
-0.052501339465379715,
0.0028738370165228844,
0.02748849056661129,
0.019041648134589195,
0.0017156238900497556,
0.048558395355939865,
0.14936476945877075,
-0.00393585255369544,
-0.04588296636939049,
-0.044371411204338074,
-0.017931193113327026,
0.004451107233762741,
-0.0024250459391623735,
0.029200982302427292,
-0.0054233623668551445,
0.011328889057040215,
0.02800247259438038,
-0.0035604513250291348,
0.03294911980628967,
0.020172979682683945,
-0.0338345468044281,
0.04910004511475563,
-0.03771720826625824,
0.1049976497888565,
0.08077415078878403,
-0.05024489387869835,
0.05186767131090164,
-0.00577518017962575,
-0.036086469888687134,
0.03013034164905548,
0.006369499024003744,
0.050509996712207794,
-0.08578412234783173,
-0.010361537337303162,
0.07156571000814438,
0.03638700395822525,
-0.03208242729306221,
0.02095329947769642,
-0.03363717347383499,
-0.09176526963710785,
-0.07402054220438004,
-0.006913462188094854,
-0.06120629981160164,
-0.05667097866535187,
-0.05095185711979866,
-0.04210970178246498,
-0.020785996690392494,
-0.014521738514304161,
0.006480645854026079,
-0.008694066666066647,
0.015002327971160412,
-0.05857247859239578,
-0.003420861205086112,
-0.005886899307370186,
0.06372641772031784,
-0.11014202982187271,
-0.14795508980751038,
-3.537565760143209e-33,
-0.00956661719828844,
-0.017822882160544395,
-0.017725978046655655,
-0.03906865790486336,
-0.052807971835136414,
-0.054937694221735,
0.06026573106646538,
0.16498291492462158,
0.030942417681217194,
0.03694082051515579,
-0.007750781252980232,
-0.04981449246406555,
0.042474325746297836,
-0.11177386343479156,
-0.004910331219434738,
0.00542529346421361,
0.007320288103073835,
0.1059466302394867,
0.02260703034698963,
0.0501587875187397,
-0.07471809536218643,
0.06365302205085754,
-0.04084412008523941,
0.12900830805301666,
0.05270751565694809,
-0.00857413187623024,
0.08121680468320847,
0.04390349239110947,
-0.051571112126111984,
-0.010867543518543243,
-0.004112572874873877,
-0.05071988329291344,
-0.06784753501415253,
0.033304356038570404,
-0.016568077728152275,
-0.06038112938404083,
0.022826220840215683,
0.04894168674945831,
-0.059259962290525436,
0.037086911499500275,
-0.048656534403562546,
0.03643960878252983,
0.007452377583831549,
0.07355630397796631,
-0.06403880566358566,
-0.03746175393462181,
-0.04032526910305023,
-0.013309723697602749,
-0.10999077558517456,
-0.023563992232084274,
0.032640717923641205,
-0.028383031487464905,
-0.03410045802593231,
-0.004278914537280798,
0.09886683523654938,
-0.02870824746787548,
-0.07744189351797104,
0.035328201949596405,
-0.07905299216508865,
0.011553879827260971,
0.018351156264543533,
-0.019154194742441177,
0.02448420599102974,
0.0015937798889353871,
0.0590287484228611,
-0.09223160147666931,
-0.07099202275276184,
0.042032234370708466,
-0.08505333960056305,
-0.023657098412513733,
0.06743728369474411,
-0.029592417180538177,
-0.05865095555782318,
0.05375273898243904,
-0.001458307495340705,
-0.003176509402692318,
-0.026274342089891434,
0.028750283643603325,
-0.07227307558059692,
0.03657444566488266,
-0.0331856943666935,
-0.031101448461413383,
0.02429940365254879,
0.12258821725845337,
0.03186492249369621,
-0.004930421710014343,
0.0029071629978716373,
0.08181034028530121,
0.07071655243635178,
0.0331205315887928,
-0.0009515046258457005,
0.08554970473051071,
0.04861659184098244,
0.05913083627820015,
0.08977823704481125,
-3.484193555891579e-8,
0.0375937856733799,
-0.08160662651062012,
0.031699296087026596,
-0.007878577336668968,
0.051930710673332214,
-0.052457161247730255,
-0.020846564322710037,
0.018972553312778473,
-0.06851131469011307,
-0.05421280488371849,
0.04809170588850975,
0.059315625578165054,
-0.0892309844493866,
-0.017778931185603142,
0.027627412229776382,
0.029933350160717964,
0.022412912920117378,
0.09737495332956314,
-0.008179989643394947,
0.007846483960747719,
0.03864356502890587,
0.043203093111515045,
0.027234993875026703,
-0.017359789460897446,
-0.06637607514858246,
0.01644948497414589,
-0.010079056955873966,
0.014574731700122356,
0.013444558717310429,
-0.05255863443017006,
0.0522836372256279,
-0.006141830235719681,
0.06363534927368164,
-0.11289311200380325,
-0.02008497342467308,
0.03393878415226936,
-0.02396913804113865,
0.0037489840760827065,
-0.028823377564549446,
0.04650256410241127,
0.06843101978302002,
-0.07870189845561981,
-0.05647367611527443,
0.046161212027072906,
0.036418408155441284,
-0.06970027089118958,
0.013820456340909004,
0.020867295563220978,
-0.004088114015758038,
-0.057527050375938416,
-0.05264521762728691,
-0.005376496817916632,
-0.010372004471719265,
-0.02883058413863182,
0.019244151189923286,
-0.027366332709789276,
-0.0018478429410606623,
0.06592593342065811,
-0.002896113321185112,
-0.018009701743721962,
0.1204509437084198,
0.03624368831515312,
0.03862098604440689,
-0.012779214419424534
] | 0.189195
|
order mark. ## Class: `util.TextEncoder` An implementation of the [WHATWG Encoding Standard][] `TextEncoder` API. All instances of `TextEncoder` only support UTF-8 encoding. ```js const encoder = new TextEncoder(); const uint8array = encoder.encode('this is some data'); ``` The `TextEncoder` class is also available on the global object. ### `textEncoder.encode([input])` \* `input` {string} The text to encode. \*\*Default:\*\* an empty string. \* Returns: {Uint8Array} UTF-8 encodes the `input` string and returns a `Uint8Array` containing the encoded bytes. ### `textEncoder.encodeInto(src, dest)` \* `src` {string} The text to encode. \* `dest` {Uint8Array} The array to hold the encode result. \* Returns: {Object} \* `read` {number} The read Unicode code units of src. \* `written` {number} The written UTF-8 bytes of dest. UTF-8 encodes the `src` string to the `dest` Uint8Array and returns an object containing the read Unicode code units and written UTF-8 bytes. ```js const encoder = new TextEncoder(); const src = 'this is some data'; const dest = new Uint8Array(10); const { read, written } = encoder.encodeInto(src, dest); ``` ### `textEncoder.encoding` \* Type: {string} The encoding supported by the `TextEncoder` instance. Always set to `'utf-8'`. ## `util.toUSVString(string)` \* `string` {string} Returns the `string` after replacing any surrogate code points (or equivalently, any unpaired surrogate code units) with the Unicode "replacement character" U+FFFD. ## `util.transferableAbortController()` Creates and returns an {AbortController} instance whose {AbortSignal} is marked as transferable and can be used with `structuredClone()` or `postMessage()`. ## `util.transferableAbortSignal(signal)` \* `signal` {AbortSignal} \* Returns: {AbortSignal} Marks the given {AbortSignal} as transferable so that it can be used with `structuredClone()` and `postMessage()`. ```js const signal = transferableAbortSignal(AbortSignal.timeout(100)); const channel = new MessageChannel(); channel.port2.postMessage(signal, [signal]); ``` ## `util.aborted(signal, resource)` \* `signal` {AbortSignal} \* `resource` {Object} Any non-null object tied to the abortable operation and held weakly. If `resource` is garbage collected before the `signal` aborts, the promise remains pending, allowing Node.js to stop tracking it. This helps prevent memory leaks in long-running or non-cancelable operations. \* Returns: {Promise} Listens to abort event on the provided `signal` and returns a promise that resolves when the `signal` is aborted. If `resource` is provided, it weakly references the operation's associated object, so if `resource` is garbage collected before the `signal` aborts, then returned promise shall remain pending. This prevents memory leaks in long-running or non-cancelable operations. ```cjs const { aborted } = require('node:util'); // Obtain an object with an abortable signal, like a custom resource or operation. const dependent = obtainSomethingAbortable(); // Pass `dependent` as the resource, indicating the promise should only resolve // if `dependent` is still in memory when the signal is aborted. aborted(dependent.signal, dependent).then(() => { // This code runs when `dependent` is aborted. console.log('Dependent resource was aborted.'); }); // Simulate an event that triggers the abort. dependent.on('event', () => { dependent.abort(); // This will cause the `aborted` promise to resolve. }); ``` ```mjs import { aborted } from 'node:util'; // Obtain an object with an abortable signal, like a custom resource or operation. const dependent = obtainSomethingAbortable(); // Pass `dependent` as the resource, indicating the promise should only resolve // if `dependent` is still in memory when the signal is aborted. aborted(dependent.signal, dependent).then(() => { // This code runs when `dependent` is aborted. console.log('Dependent resource was aborted.'); }); // Simulate an event that triggers the abort. dependent.on('event', () => { dependent.abort(); // This will cause the `aborted` promise to resolve. }); ``` ## `util.types` `util.types` provides type checks for different kinds of built-in objects. Unlike `instanceof` or `Object.prototype.toString.call(value)`, these checks do not inspect properties of the object that are accessible from JavaScript (like their prototype), and usually have the overhead of calling into C++. The result
|
https://github.com/nodejs/node/blob/main//doc/api/util.md
|
main
|
nodejs
|
[
-0.06163492053747177,
0.03607872501015663,
0.017056046053767204,
-0.0009759233798831701,
-0.09411606937646866,
0.020494982600212097,
-0.02951263263821602,
0.022097691893577576,
0.03176519274711609,
-0.029505329206585884,
-0.016370605677366257,
0.06088366359472275,
-0.013337776064872742,
0.06230267882347107,
0.0125340037047863,
0.028311919420957565,
-0.06713304668664932,
0.010586922988295555,
-0.06288224458694458,
-0.09472806751728058,
0.09964273869991302,
-0.0018058889545500278,
0.012766228057444096,
-0.010266279801726341,
0.0752786248922348,
0.040762439370155334,
0.00889530684798956,
0.017737219110131264,
0.06111234426498413,
0.005655447952449322,
0.07651732116937637,
-0.06893396377563477,
0.021414637565612793,
0.06370305269956589,
-0.09596845507621765,
0.05366665497422218,
-0.04210546985268593,
-0.1450439989566803,
0.0628277063369751,
-0.02153373882174492,
-0.04577259719371796,
0.08289515227079391,
-0.06416047364473343,
0.00011468087905086577,
0.05730230733752251,
-0.0005956576205790043,
-0.044414255768060684,
-0.0010471473215147853,
-0.0817686915397644,
-0.009123691357672215,
0.01166964415460825,
0.030596420168876648,
-0.0029387883841991425,
0.0409676730632782,
0.05675187334418297,
-0.022832905873656273,
-0.03670060262084007,
-0.02046021819114685,
0.05671378970146179,
0.052737489342689514,
-0.016585923731327057,
-0.005463331006467342,
0.05297081172466278,
0.02330549992620945,
0.011915895156562328,
-0.05001062899827957,
0.04774518311023712,
0.06972502917051315,
-0.066738560795784,
-0.043323732912540436,
-0.023104703053832054,
-0.03355205059051514,
0.030357753857970238,
0.059482552111148834,
0.015063419006764889,
0.030017761513590813,
-0.0029425458051264286,
0.03633085638284683,
0.016071168705821037,
-0.031220760196447372,
-0.004329486284404993,
-0.07143764197826385,
0.08129888772964478,
0.14355668425559998,
0.07654865086078644,
0.06766464561223984,
-0.04695049300789833,
0.0747467502951622,
0.021954679861664772,
0.04404202103614807,
-0.06362805515527725,
-0.09595116227865219,
-0.025519995018839836,
0.0710223838686943,
0.028507621958851814,
-0.004984201397746801,
0.059541672468185425,
0.07385216653347015,
-0.08057108521461487,
-0.00465658912435174,
0.00904939230531454,
-0.01091744378209114,
0.013400929048657417,
-0.03928522393107414,
-0.010074770078063011,
0.005981450900435448,
0.0688747763633728,
0.015354537405073643,
-0.013587513007223606,
-0.038815855979919434,
-0.0031729198526591063,
0.056753236800432205,
-0.02660202607512474,
-0.0789940282702446,
-0.062068693339824677,
-0.025545883923768997,
-0.06288913637399673,
-0.04850435256958008,
0.10502268373966217,
0.027677128091454506,
-0.007794677745550871,
0.021877069026231766,
-0.10003792494535446,
0.048092540353536606,
-0.023423807695508003,
0.02103075385093689,
0.020198693498969078,
6.797130779736793e-33,
0.015120386146008968,
0.021826546639204025,
-0.01799704134464264,
-0.022065753117203712,
-0.03111235424876213,
-0.02719734236598015,
-0.09139460325241089,
0.010965518653392792,
-0.08842245489358902,
-0.01360970176756382,
-0.009525185450911522,
0.002025434747338295,
0.015029010362923145,
0.06251432001590729,
0.02421906590461731,
-0.05622594803571701,
0.038149770349264145,
-0.025397174060344696,
0.03855090215802193,
0.0011785004753619432,
-0.019039873033761978,
0.08246259391307831,
-0.03352229297161102,
-0.02147749438881874,
-0.03010863997042179,
0.06935400515794754,
0.024103432893753052,
-0.0753641352057457,
-0.046537917107343674,
-0.024401213973760605,
0.008494381792843342,
-0.07503794878721237,
0.0010316456900909543,
-0.040477581322193146,
0.02277134172618389,
-0.05963630601763725,
0.003711890894919634,
0.060948148369789124,
-0.10922758281230927,
-0.002187961246818304,
0.08045414835214615,
0.020459240302443504,
-0.06358340382575989,
-0.011031405068933964,
0.015894552692770958,
-0.02060636319220066,
-0.02458592690527439,
0.003177384380251169,
0.05452685058116913,
-0.014017010107636452,
-0.05805489420890808,
0.08126794546842575,
-0.029542049393057823,
-0.003249937202781439,
0.042236994951963425,
-0.008753715083003044,
0.09714948385953903,
-0.08101720362901688,
0.0018896113615483046,
-0.029415324330329895,
-0.050659820437431335,
0.029611673206090927,
0.05725853517651558,
0.012932246550917625,
0.014227060601115227,
-0.07436557859182358,
0.024587033316493034,
-0.07685548812150955,
-0.04411197826266289,
0.029111120849847794,
-0.09710757434368134,
0.0398854985833168,
0.017386483028531075,
-0.005247358698397875,
-0.011193321086466312,
0.035651322454214096,
-0.14144007861614227,
-0.046649109572172165,
-0.05727360397577286,
-0.07647238671779633,
0.0036774161271750927,
-0.06029866263270378,
0.00884250458329916,
0.06922689080238342,
0.0437246598303318,
0.032398246228694916,
-0.016765084117650986,
-0.08600941300392151,
0.07789070904254913,
0.061259765177965164,
0.01889319345355034,
-0.10993044078350067,
-0.03540309891104698,
-0.1059112474322319,
0.022463414818048477,
-7.852248631563124e-33,
0.033638276159763336,
0.0827869400382042,
-0.02111186273396015,
0.09342348575592041,
-0.06137833371758461,
-0.046393100172281265,
0.03247423842549324,
0.07306189090013504,
0.008254812099039555,
-0.015804976224899292,
0.008122237399220467,
0.04804917424917221,
0.1070968508720398,
-0.022088266909122467,
0.06331289559602737,
0.06881164759397507,
-0.1057848185300827,
0.04066938906908035,
0.06642849743366241,
-0.07956123352050781,
0.039896491914987564,
0.008460840210318565,
0.05333360657095909,
0.0759386345744133,
0.007064308505505323,
0.029161499813199043,
0.08627208322286606,
0.06538567692041397,
0.016962897032499313,
-0.047877758741378784,
-0.01771516166627407,
-0.016903484240174294,
-0.012027840130031109,
0.06707436591386795,
-0.07339809089899063,
-0.012044351547956467,
0.06610196828842163,
0.035897791385650635,
-0.05257130041718483,
-0.017270106822252274,
0.0683104619383812,
-0.004934484604746103,
-0.05534759908914566,
0.0657220259308815,
-0.02057373709976673,
0.007359787356108427,
-0.08096645772457123,
0.07538432627916336,
0.020083896815776825,
-0.005642775911837816,
0.0348709337413311,
-0.01339819747954607,
-0.08895909786224365,
-0.077813521027565,
-0.010186907835304737,
-0.05386439710855484,
-0.02319176122546196,
-0.031168535351753235,
0.02087419107556343,
0.08409515768289566,
-0.010943867266178131,
-0.05431723967194557,
0.1082201600074768,
-0.07386000454425812,
-0.010447160340845585,
-0.0404345728456974,
-0.12207844853401184,
0.004785090684890747,
-0.006799666211009026,
-0.07211972773075104,
0.06872083246707916,
-0.09669157862663269,
0.030483167618513107,
0.06336970627307892,
0.0182460006326437,
-0.039349090307950974,
0.023018300533294678,
-0.0011366084218025208,
-0.010637017898261547,
-0.007898636162281036,
0.021962005645036697,
0.039605263620615005,
0.004289568867534399,
0.08399119228124619,
0.07089219242334366,
0.06473679095506668,
-0.0016178078949451447,
0.026780875399708748,
-0.056844767183065414,
-0.048357799649238586,
0.015358621254563332,
0.1476675570011139,
-0.007821419276297092,
0.012281224131584167,
-0.0024032872170209885,
-5.0337050083726353e-8,
-0.07638118416070938,
-0.10798560082912445,
-0.09676497429609299,
-0.04102558270096779,
-0.07843401283025742,
-0.024495532736182213,
0.007465881295502186,
-0.004674968309700489,
-0.007206331472843885,
-0.06285598129034042,
0.08870955556631088,
0.0025302553549408913,
-0.08772128075361252,
-0.01956000179052353,
0.0053069922141730785,
0.0374738946557045,
0.017712745815515518,
-0.033437419682741165,
-0.01045807171612978,
-0.010900614783167839,
-0.00679484847933054,
0.0013412439730018377,
-0.01072599831968546,
-0.05926797538995743,
0.015142886899411678,
-0.025698145851492882,
-0.04511558637022972,
0.10387717187404633,
0.02839750051498413,
0.0013322511222213507,
0.028353117406368256,
0.05695819482207298,
0.043376319110393524,
-0.06298349797725677,
-0.01117314025759697,
0.0006589324329979718,
-0.026211069896817207,
-0.038067951798439026,
0.09600596874952316,
0.019793903455138206,
0.08579763025045395,
0.0035055470652878284,
-0.08978664129972458,
0.0043098703026771545,
-0.028325561434030533,
-0.029290730133652687,
0.013365956954658031,
-0.040078647434711456,
0.06670118123292923,
0.00533531978726387,
-0.0010202676057815552,
-0.022023363038897514,
-0.009710556827485561,
-0.03423308953642845,
-0.025302328169345856,
-0.040863629430532455,
-0.04958663880825043,
-0.024970808997750282,
0.04399573430418968,
0.013120343908667564,
0.03077879548072815,
0.006356930360198021,
0.008255377411842346,
-0.04830319434404373
] | 0.090365
|
`aborted` promise to resolve. }); ``` ## `util.types` `util.types` provides type checks for different kinds of built-in objects. Unlike `instanceof` or `Object.prototype.toString.call(value)`, these checks do not inspect properties of the object that are accessible from JavaScript (like their prototype), and usually have the overhead of calling into C++. The result generally does not make any guarantees about what kinds of properties or behavior a value exposes in JavaScript. They are primarily useful for addon developers who prefer to do type checking in JavaScript. The API is accessible via `require('node:util').types` or `require('node:util/types')`. ### `util.types.isAnyArrayBuffer(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a built-in {ArrayBuffer} or {SharedArrayBuffer} instance. See also [`util.types.isArrayBuffer()`][] and [`util.types.isSharedArrayBuffer()`][]. ```js util.types.isAnyArrayBuffer(new ArrayBuffer()); // Returns true util.types.isAnyArrayBuffer(new SharedArrayBuffer()); // Returns true ``` ### `util.types.isArrayBufferView(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is an instance of one of the {ArrayBuffer} views, such as typed array objects or {DataView}. Equivalent to [`ArrayBuffer.isView()`][]. ```js util.types.isArrayBufferView(new Int8Array()); // true util.types.isArrayBufferView(Buffer.from('hello world')); // true util.types.isArrayBufferView(new DataView(new ArrayBuffer(16))); // true util.types.isArrayBufferView(new ArrayBuffer()); // false ``` ### `util.types.isArgumentsObject(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is an `arguments` object. ```js function foo() { util.types.isArgumentsObject(arguments); // Returns true } ``` ### `util.types.isArrayBuffer(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a built-in {ArrayBuffer} instance. This does \_not\_ include {SharedArrayBuffer} instances. Usually, it is desirable to test for both; See [`util.types.isAnyArrayBuffer()`][] for that. ```js util.types.isArrayBuffer(new ArrayBuffer()); // Returns true util.types.isArrayBuffer(new SharedArrayBuffer()); // Returns false ``` ### `util.types.isAsyncFunction(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is an [async function][]. This only reports back what the JavaScript engine is seeing; in particular, the return value may not match the original source code if a transpilation tool was used. ```js util.types.isAsyncFunction(function foo() {}); // Returns false util.types.isAsyncFunction(async function foo() {}); // Returns true ``` ### `util.types.isBigInt64Array(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a `BigInt64Array` instance. ```js util.types.isBigInt64Array(new BigInt64Array()); // Returns true util.types.isBigInt64Array(new BigUint64Array()); // Returns false ``` ### `util.types.isBigIntObject(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a BigInt object, e.g. created by `Object(BigInt(123))`. ```js util.types.isBigIntObject(Object(BigInt(123))); // Returns true util.types.isBigIntObject(BigInt(123)); // Returns false util.types.isBigIntObject(123); // Returns false ``` ### `util.types.isBigUint64Array(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a `BigUint64Array` instance. ```js util.types.isBigUint64Array(new BigInt64Array()); // Returns false util.types.isBigUint64Array(new BigUint64Array()); // Returns true ``` ### `util.types.isBooleanObject(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a boolean object, e.g. created by `new Boolean()`. ```js util.types.isBooleanObject(false); // Returns false util.types.isBooleanObject(true); // Returns false util.types.isBooleanObject(new Boolean(false)); // Returns true util.types.isBooleanObject(new Boolean(true)); // Returns true util.types.isBooleanObject(Boolean(false)); // Returns false util.types.isBooleanObject(Boolean(true)); // Returns false ``` ### `util.types.isBoxedPrimitive(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is any boxed primitive object, e.g. created by `new Boolean()`, `new String()` or `Object(Symbol())`. For example: ```js util.types.isBoxedPrimitive(false); // Returns false util.types.isBoxedPrimitive(new Boolean(false)); // Returns true util.types.isBoxedPrimitive(Symbol('foo')); // Returns false util.types.isBoxedPrimitive(Object(Symbol('foo'))); // Returns true util.types.isBoxedPrimitive(Object(BigInt(5))); // Returns true ``` ### `util.types.isCryptoKey(value)` \* `value` {Object} \* Returns: {boolean} Returns `true` if `value` is a {CryptoKey}, `false` otherwise. ### `util.types.isDataView(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a built-in {DataView} instance. ```js const ab = new ArrayBuffer(20); util.types.isDataView(new DataView(ab)); // Returns true util.types.isDataView(new Float64Array()); // Returns false ``` See also [`ArrayBuffer.isView()`][]. ### `util.types.isDate(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a built-in {Date} instance. ```js util.types.isDate(new Date()); // Returns true ``` ### `util.types.isExternal(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if
|
https://github.com/nodejs/node/blob/main//doc/api/util.md
|
main
|
nodejs
|
[
-0.07165738940238953,
0.06224416568875313,
0.033014506101608276,
0.09631101042032242,
-0.005853081587702036,
-0.03235190361738205,
0.03943604230880737,
0.017817042768001556,
0.0061325556598603725,
-0.06670776009559631,
-0.1127346083521843,
0.0010514596942812204,
-0.08618353307247162,
0.021358875557780266,
0.06019335985183716,
0.012234552763402462,
0.04091307893395424,
-0.07789500057697296,
0.0024315104819834232,
-0.001924255513586104,
0.044457919895648956,
-0.05665983632206917,
0.010397529229521751,
-0.0020363074727356434,
0.0012433681404218078,
0.002465285360813141,
-0.030233485624194145,
-0.07922693341970444,
0.03212166577577591,
0.023325782269239426,
-0.01741884835064411,
0.012892959639430046,
-0.09044769406318665,
0.01083990279585123,
-0.09200876951217651,
0.1270018070936203,
0.029529938474297523,
-0.07367169857025146,
0.014614778570830822,
-0.031436625868082047,
0.031910210847854614,
0.11053221672773361,
-0.0601365752518177,
-0.030920857563614845,
0.052404869347810745,
-0.009770488366484642,
-0.020844832062721252,
-0.050788477063179016,
-0.06302128732204437,
-0.00887842383235693,
0.022058716043829918,
0.018156278878450394,
-0.0099057387560606,
-0.015423481352627277,
0.0379207544028759,
-0.04648657515645027,
-0.050800759345293045,
0.02098928391933441,
0.03398191183805466,
0.1046183854341507,
0.00864903349429369,
-0.06207571551203728,
0.05917845293879509,
0.0006865677423775196,
0.03357724845409393,
0.0022196811623871326,
0.016710549592971802,
-0.030037036165595055,
0.042291417717933655,
-0.03613390028476715,
0.007369151804596186,
0.002896777121350169,
0.03252139687538147,
0.05346432700753212,
-0.0022353804670274258,
-0.019901471212506294,
0.04359929636120796,
-0.04857120290398598,
-0.018310559913516045,
0.017723117023706436,
-0.08011405915021896,
-0.0786423459649086,
-0.04146508499979973,
0.09001227468252182,
0.02505573444068432,
0.09222029894590378,
-0.012973155826330185,
0.026041310280561447,
-0.01207009144127369,
0.10156150162220001,
-0.055884458124637604,
-0.10938290506601334,
-0.11375782638788223,
0.07243207842111588,
0.07506398856639862,
-0.05640796199440956,
0.01530339103192091,
-0.02213425002992153,
-0.0648401528596878,
0.019443998113274574,
-0.003153782105073333,
-0.007103283889591694,
0.074282206594944,
-0.063680000603199,
0.05733378976583481,
0.03983384370803833,
-0.0004142378456890583,
-0.07955407351255417,
-0.006678651552647352,
0.062212564051151276,
-0.04225372523069382,
0.04321407899260521,
0.02029314450919628,
-0.0013189163291826844,
-0.044107586145401,
-0.003141002496704459,
-0.018824266269803047,
-0.10808730870485306,
0.08383158594369888,
0.05314851552248001,
0.12043958902359009,
0.009512468241155148,
0.08664657920598984,
0.03499096259474754,
0.0014847156126052141,
0.010816045105457306,
-0.02177439071238041,
2.9790810472278475e-33,
0.0024637074675410986,
-0.02404327690601349,
-0.006150278728455305,
0.0563664436340332,
-0.021382708102464676,
0.022693734616041183,
-0.004753605928272009,
0.0757545605301857,
-0.042371973395347595,
-0.012165045365691185,
-0.018145233392715454,
0.09764605760574341,
-0.033906564116477966,
-0.004519498907029629,
0.05018129572272301,
0.027258576825261116,
0.08428815752267838,
-0.06541484594345093,
-0.012864882126450539,
0.04897375404834747,
-0.007970639504492283,
0.03334062546491623,
-0.02583816833794117,
0.06774803251028061,
-0.0073449257761240005,
-0.02067359909415245,
0.0029796860180795193,
0.029088012874126434,
-0.02286163903772831,
-0.024644454941153526,
-0.02946338802576065,
0.008465684950351715,
-0.032203882932662964,
0.05915370583534241,
-0.0024775706697255373,
0.007319045718759298,
0.014572340995073318,
0.001782111474312842,
-0.09834930300712585,
-0.04949495941400528,
0.0015142185147851706,
0.04246816039085388,
-0.04966692626476288,
0.02372153475880623,
0.00856135692447424,
-0.08721252530813217,
-0.05041556805372238,
-0.02698131464421749,
0.04725341498851776,
-0.027073711156845093,
-0.07126651704311371,
0.11032286286354065,
0.03306002542376518,
0.016090264543890953,
0.05504829064011574,
-0.02291794680058956,
0.051367342472076416,
-0.004166507162153721,
-0.027224959805607796,
0.0038860600907355547,
0.09071163088083267,
-0.046960972249507904,
0.007554994430392981,
0.003645565826445818,
-0.13141049444675446,
0.06123456731438637,
-0.04106124863028526,
0.00692790187895298,
0.0240097027271986,
0.03765885904431343,
-0.01891678012907505,
0.08990229666233063,
-0.07656224071979523,
0.0420030914247036,
-0.0015193867729976773,
-0.02377656102180481,
-0.06516116857528687,
-0.03437921777367592,
0.022519700229167938,
-0.014262552373111248,
0.06920435279607773,
-0.008388765156269073,
0.01062182430177927,
0.11485346406698227,
-0.04487680271267891,
0.03352212533354759,
-0.002662619575858116,
-0.034359004348516464,
0.08551428467035294,
0.010205085389316082,
0.012275373563170433,
-0.02035342901945114,
-0.08179991692304611,
-0.06558781117200851,
-0.08690284937620163,
-6.088573641787827e-33,
0.007568285800516605,
-0.06090148538351059,
-0.06674179434776306,
0.057623133063316345,
-0.05208296328783035,
-0.04271332547068596,
0.016532549634575844,
-0.006415491923689842,
-0.0073108007200062275,
-0.0585978738963604,
0.01348534133285284,
0.003350274171680212,
0.06194746494293213,
-0.01119386125355959,
0.012290547601878643,
-0.0003884164907503873,
-0.12122416496276855,
-0.1122422069311142,
0.09633609652519226,
-0.04824770987033844,
0.014368793927133083,
0.002417022828012705,
0.08304474502801895,
0.009622461162507534,
-0.10383733361959457,
0.038388691842556,
-0.05348725616931915,
-0.06403458118438721,
-0.006165441125631332,
-0.04763249307870865,
-0.010504295118153095,
-0.01815936714410782,
-0.0463581383228302,
0.02203081175684929,
0.03451632335782051,
-0.019590269774198532,
0.0458841510117054,
0.08835180848836899,
-0.024572040885686874,
-0.055599939078092575,
0.07646571099758148,
-0.039343900978565216,
-0.04881593585014343,
-0.0020842666272073984,
0.010062144137918949,
0.016629982739686966,
0.009264407679438591,
0.05329320952296257,
0.09885657578706741,
-0.05317732319235802,
0.07467053830623627,
-0.07568460702896118,
-0.006951341405510902,
0.012238099239766598,
-0.03088916465640068,
-0.0641610249876976,
0.002259026048704982,
-0.054684873670339584,
0.04494283348321915,
0.0964827612042427,
-0.03762161359190941,
-0.0950889065861702,
0.003934803418815136,
-0.023790370672941208,
-0.11227232217788696,
0.018985997885465622,
-0.06776605546474457,
-0.08603721857070923,
0.09820365160703659,
-0.0014759562909603119,
0.03740975633263588,
-0.0533098429441452,
0.006516526453197002,
-0.03385450690984726,
-0.03174033761024475,
0.010771561414003372,
-0.016667013987898827,
-0.07316543161869049,
0.056172892451286316,
0.020353909581899643,
0.008372040465474129,
0.04676011949777603,
0.02461722120642662,
0.03291339427232742,
0.06370355188846588,
0.0007620828109793365,
-0.033439572900533676,
-0.009103987365961075,
-0.10090845823287964,
0.018921563401818275,
0.04208836331963539,
0.06892570108175278,
-0.21220643818378448,
-0.036184120923280716,
-0.04635048285126686,
-5.574406003461263e-8,
-0.02705121412873268,
-0.01172988023608923,
-0.09873361140489578,
-0.041986383497714996,
-0.008722534403204918,
-0.03321953862905502,
-0.0038693102542310953,
-0.050970278680324554,
0.018548743799328804,
0.022485576570034027,
-0.02590041048824787,
0.01142606046050787,
0.028695333749055862,
0.006355881690979004,
0.020466359332203865,
0.0058654239401221275,
-0.020249616354703903,
0.01035337708890438,
-0.02007542923092842,
0.018734503537416458,
-0.01159129198640585,
-0.033872202038764954,
-0.060712698847055435,
-0.018251929432153702,
-0.05120662599802017,
-0.020068632438778877,
0.018325459212064743,
0.0637793242931366,
0.01595100201666355,
0.020287737250328064,
-0.06463425606489182,
0.06884629279375076,
0.03922147676348686,
0.01642007753252983,
0.05236269161105156,
0.10685408860445023,
-0.03745603188872337,
0.026477336883544922,
0.02281607687473297,
0.05620196461677551,
0.09781932085752487,
0.01250174455344677,
-0.037747543305158615,
0.04386604204773903,
0.025007037445902824,
-0.017816299572587013,
0.04361245408654213,
0.04803767800331116,
0.0001360136375296861,
-0.0027926387265324593,
0.057507552206516266,
0.040741417557001114,
-0.041996683925390244,
0.04955455660820007,
-0.10432235151529312,
0.0007181848050095141,
-0.04965215548872948,
-0.06558401137590408,
0.011800830252468586,
-0.0021020183339715004,
0.07038914412260056,
-0.10047585517168045,
0.051319729536771774,
-0.02304181270301342
] | 0.119799
|
util.types.isDataView(new DataView(ab)); // Returns true util.types.isDataView(new Float64Array()); // Returns false ``` See also [`ArrayBuffer.isView()`][]. ### `util.types.isDate(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a built-in {Date} instance. ```js util.types.isDate(new Date()); // Returns true ``` ### `util.types.isExternal(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a native `External` value. A native `External` value is a special type of object that contains a raw C++ pointer (`void\*`) for access from native code, and has no other properties. Such objects are created either by Node.js internals or native addons. In JavaScript, they are [frozen][`Object.freeze()`] objects with a `null` prototype. ```c #include #include napi\_value result; static napi\_value MyNapi(napi\_env env, napi\_callback\_info info) { int\* raw = (int\*) malloc(1024); napi\_status status = napi\_create\_external(env, (void\*) raw, NULL, NULL, &result); if (status != napi\_ok) { napi\_throw\_error(env, NULL, "napi\_create\_external failed"); return NULL; } return result; } ... DECLARE\_NAPI\_PROPERTY("myNapi", MyNapi) ... ``` ```mjs import native from 'napi\_addon.node'; import { types } from 'node:util'; const data = native.myNapi(); types.isExternal(data); // returns true types.isExternal(0); // returns false types.isExternal(new String('foo')); // returns false ``` ```cjs const native = require('napi\_addon.node'); const { types } = require('node:util'); const data = native.myNapi(); types.isExternal(data); // returns true types.isExternal(0); // returns false types.isExternal(new String('foo')); // returns false ``` For further information on `napi\_create\_external`, refer to [`napi\_create\_external()`][]. ### `util.types.isFloat16Array(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a built-in {Float16Array} instance. ```js util.types.isFloat16Array(new ArrayBuffer()); // Returns false util.types.isFloat16Array(new Float16Array()); // Returns true util.types.isFloat16Array(new Float32Array()); // Returns false ``` ### `util.types.isFloat32Array(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a built-in {Float32Array} instance. ```js util.types.isFloat32Array(new ArrayBuffer()); // Returns false util.types.isFloat32Array(new Float32Array()); // Returns true util.types.isFloat32Array(new Float64Array()); // Returns false ``` ### `util.types.isFloat64Array(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a built-in {Float64Array} instance. ```js util.types.isFloat64Array(new ArrayBuffer()); // Returns false util.types.isFloat64Array(new Uint8Array()); // Returns false util.types.isFloat64Array(new Float64Array()); // Returns true ``` ### `util.types.isGeneratorFunction(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a generator function. This only reports back what the JavaScript engine is seeing; in particular, the return value may not match the original source code if a transpilation tool was used. ```js util.types.isGeneratorFunction(function foo() {}); // Returns false util.types.isGeneratorFunction(function\* foo() {}); // Returns true ``` ### `util.types.isGeneratorObject(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a generator object as returned from a built-in generator function. This only reports back what the JavaScript engine is seeing; in particular, the return value may not match the original source code if a transpilation tool was used. ```js function\* foo() {} const generator = foo(); util.types.isGeneratorObject(generator); // Returns true ``` ### `util.types.isInt8Array(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a built-in {Int8Array} instance. ```js util.types.isInt8Array(new ArrayBuffer()); // Returns false util.types.isInt8Array(new Int8Array()); // Returns true util.types.isInt8Array(new Float64Array()); // Returns false ``` ### `util.types.isInt16Array(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a built-in {Int16Array} instance. ```js util.types.isInt16Array(new ArrayBuffer()); // Returns false util.types.isInt16Array(new Int16Array()); // Returns true util.types.isInt16Array(new Float64Array()); // Returns false ``` ### `util.types.isInt32Array(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a built-in {Int32Array} instance. ```js util.types.isInt32Array(new ArrayBuffer()); // Returns false util.types.isInt32Array(new Int32Array()); // Returns true util.types.isInt32Array(new Float64Array()); // Returns false ``` ### `util.types.isKeyObject(value)` \* `value` {Object} \* Returns: {boolean} Returns `true` if `value` is a {KeyObject}, `false` otherwise. ### `util.types.isMap(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a built-in {Map} instance. ```js util.types.isMap(new Map()); // Returns true ``` ### `util.types.isMapIterator(value)` \* `value` {any} \* Returns:
|
https://github.com/nodejs/node/blob/main//doc/api/util.md
|
main
|
nodejs
|
[
-0.03205518797039986,
-0.015112188644707203,
-0.029890097677707672,
0.05119467154145241,
0.009936182759702206,
-0.013860191218554974,
0.01404162123799324,
0.015915414318442345,
0.015384956263005733,
-0.014305423945188522,
-0.0038402345962822437,
-0.041830841451883316,
-0.08641848713159561,
-0.006504913326352835,
-0.017215143889188766,
-0.005679085850715637,
-0.03683675453066826,
-0.12536101043224335,
-0.0324336439371109,
0.05383128300309181,
0.03992690145969391,
-0.021398257464170456,
-0.06714046746492386,
-0.012163725681602955,
0.10039796680212021,
0.06505920737981796,
0.029262619093060493,
-0.09402008354663849,
0.08759921044111252,
-0.0009129626560024917,
-0.060955800116062164,
0.049502573907375336,
-0.054225217550992966,
0.04431314393877983,
-0.029033754020929337,
0.03457481414079666,
0.021646196022629738,
0.007306003477424383,
-0.04711058363318443,
-0.041412342339754105,
-0.010523306205868721,
0.04471871256828308,
-0.06318703293800354,
-0.036459386348724365,
-0.0005987125914543867,
-0.005382883828133345,
-0.0075752693228423595,
-0.03274085745215416,
-0.11578209698200226,
0.034705791622400284,
-0.02812460996210575,
0.028403006494045258,
-0.05416359007358551,
0.04160149022936821,
0.12476649880409241,
0.006171952933073044,
-0.054142504930496216,
-0.017466841265559196,
0.009769551455974579,
0.11815115809440613,
0.006077799014747143,
0.00926795694977045,
0.03295483440160751,
0.06297598779201508,
0.026033693924546242,
-0.05052045360207558,
0.03264857083559036,
-0.012413978576660156,
0.05880945548415184,
-0.10112931579351425,
-0.027885740622878075,
0.02570466324687004,
0.01244824007153511,
0.04825790226459503,
-0.03089924529194832,
-0.035743165761232376,
0.08112415671348572,
-0.061402518302202225,
0.033563096076250076,
-0.007742749992758036,
-0.005483101587742567,
-0.056571584194898605,
-0.06715987622737885,
0.09035548567771912,
0.07797762751579285,
0.024798696860671043,
-0.01796787790954113,
0.07622778415679932,
-0.03489323705434799,
0.06343669444322586,
0.020339978858828545,
-0.02286641113460064,
-0.07327313721179962,
0.0813533216714859,
0.06683970987796783,
0.009401480667293072,
0.040679093450307846,
0.014516983181238174,
0.034849923104047775,
0.02619853988289833,
0.019546087831258774,
0.024801047518849373,
-0.027361808344721794,
0.029093444347381592,
0.024699896574020386,
-0.10463766753673553,
0.06721595674753189,
-0.04544863477349281,
-0.07332859933376312,
0.01662915199995041,
0.03622433543205261,
0.018857350572943687,
-0.019727913662791252,
-0.035469524562358856,
-0.13088476657867432,
-0.035723645240068436,
-0.05617961287498474,
-0.08467233180999756,
0.060807857662439346,
-0.0003913618566002697,
0.023046256974339485,
0.08379560708999634,
0.09474941343069077,
0.005847501568496227,
0.02262798324227333,
-0.01892416551709175,
-0.03040509857237339,
2.5016633838619835e-33,
-0.015979016199707985,
-0.09306197613477707,
0.031217191368341446,
-0.09555395692586899,
-0.015448984690010548,
-0.017448479309678078,
-0.05231922119855881,
0.06977307051420212,
0.006167484447360039,
-0.005209633149206638,
-0.02107633277773857,
0.0661235898733139,
0.031186483800411224,
0.007187529467046261,
0.10758158564567566,
0.007981386967003345,
0.040915969759225845,
0.006235476583242416,
0.02478884719312191,
0.008129384368658066,
0.05488390475511551,
0.014570771716535091,
-0.034690454602241516,
0.04649869352579117,
-0.011853856965899467,
-0.027187924832105637,
0.00951444823294878,
0.08902917802333832,
-0.05930149182677269,
-0.008585170842707157,
-0.022377539426088333,
-0.036028049886226654,
-0.008399289101362228,
0.05636238306760788,
0.07491371780633926,
0.0399862676858902,
-0.04495680332183838,
-0.011361474171280861,
-0.06384732574224472,
-0.019483890384435654,
-0.03257932513952255,
0.0265838373452425,
-0.06202620640397072,
-0.05775849148631096,
0.012088115327060223,
-0.08699274063110352,
-0.027151403948664665,
0.007432086393237114,
-0.009320097975432873,
-0.009132455103099346,
-0.07888168096542358,
0.07877999544143677,
0.0034469084348529577,
-0.04526381567120552,
-0.002889021532610059,
0.027335945516824722,
0.04857213795185089,
0.029219571501016617,
-0.05937788635492325,
0.020746733993291855,
0.0004314906836953014,
0.05223485082387924,
0.015051255002617836,
-0.027693679556250572,
-0.15355943143367767,
0.11361167579889297,
-0.004534388426691294,
-0.059004463255405426,
0.03851979225873947,
-0.03518163785338402,
-0.006949030794203281,
0.04251205548644066,
0.04952690005302429,
-0.020426500588655472,
-0.010378126986324787,
-0.024438681080937386,
-0.0816313698887825,
-0.0381271094083786,
-0.005074964836239815,
-0.05585487559437752,
0.06836501508951187,
-0.051833271980285645,
-0.018805600702762604,
0.12262125313282013,
-0.007843629457056522,
0.004091133829206228,
-0.05019800364971161,
-0.0030005662702023983,
0.07554731518030167,
0.06906679272651672,
0.00675225630402565,
-0.05006466433405876,
-0.0718114823102951,
-0.13016796112060547,
0.00900292955338955,
-5.0373701861497344e-33,
0.03972804918885231,
0.014876403845846653,
-0.05077844858169556,
0.017222853377461433,
0.010059843771159649,
-0.02773424983024597,
-0.00212305155582726,
0.11878632009029388,
0.058530911803245544,
-0.05727139115333557,
0.008035605773329735,
0.06609071046113968,
0.03241564705967903,
-0.008577113971114159,
0.045084524899721146,
0.04759138822555542,
-0.08492029458284378,
-0.10973314940929413,
-0.03969143331050873,
-0.04213309660553932,
-0.019532082602381706,
0.08437717705965042,
-0.002112477784976363,
0.051650404930114746,
0.026671335101127625,
0.056658320128917694,
-0.012690071016550064,
-0.007559329271316528,
-0.021309640258550644,
-0.018581878393888474,
-0.032919757068157196,
-0.0373229905962944,
-0.044824305921792984,
-0.01647518016397953,
-0.030449679121375084,
-0.007013150956481695,
0.06468229740858078,
-0.07229748368263245,
-0.033203646540641785,
-0.011662616394460201,
-0.012512779794633389,
0.029254209250211716,
0.012903038412332535,
0.03637479618191719,
-0.009228017181158066,
-0.0017753492575138807,
-0.009088228456676006,
0.09400789439678192,
0.03573243319988251,
-0.09612676501274109,
0.027606075629591942,
-0.1037495955824852,
0.02292543649673462,
0.005580183584243059,
0.019284037873148918,
-0.007248210720717907,
-0.015497277490794659,
-0.03554471582174301,
0.018183911219239235,
0.024829497560858727,
0.008261991664767265,
-0.20034624636173248,
-0.021800410002470016,
-0.00043133096187375486,
-0.09446283429861069,
-0.02933802641928196,
-0.022889450192451477,
-0.026972277089953423,
0.012598305940628052,
-0.023567967116832733,
0.05255948752164841,
-0.044475819915533066,
-0.0802222341299057,
-0.049057699739933014,
-0.04846971854567528,
0.04033155366778374,
0.02036767266690731,
-0.04249758645892143,
0.01157978642731905,
0.0196660328656435,
0.03924558684229851,
0.05105159804224968,
0.034139931201934814,
0.08288045227527618,
0.06334803253412247,
-0.0038933150935918093,
-0.0539432130753994,
-0.0008469397434964776,
-0.09138605743646622,
-0.027117395773530006,
-0.09291543811559677,
0.034506820142269135,
-0.21502982079982758,
0.046712473034858704,
-0.027876175940036774,
-5.4800405990818035e-8,
-0.04569685459136963,
-0.07491610199213028,
-0.06642166525125504,
0.031837448477745056,
0.012675467878580093,
-0.061901602894067764,
0.02360706590116024,
-0.011981028132140636,
0.07934705913066864,
0.000039330756408162415,
0.06332563608884811,
0.014091560617089272,
0.00045664128265343606,
-0.06879495829343796,
0.06725829839706421,
0.008751866407692432,
0.003292107256129384,
-0.05045286566019058,
-0.02966484986245632,
0.02439488098025322,
-0.0020022622775286436,
-0.0711989551782608,
-0.016302594915032387,
-0.006833561696112156,
-0.01052993442863226,
0.028886567801237106,
0.001114003942348063,
0.06317322701215744,
0.07137244939804077,
0.03191826120018959,
0.01162023190408945,
0.08687656372785568,
0.096200130879879,
0.029475878924131393,
0.03815283253788948,
0.025148311629891396,
0.025809675455093384,
0.05575345456600189,
0.015445079654455185,
0.08643656224012375,
0.07364387810230255,
0.03463590890169144,
-0.08115129917860031,
0.06954260915517807,
-0.013148274272680283,
-0.003817396704107523,
-0.02958047017455101,
0.056820571422576904,
0.0016221640398725867,
-0.002723530400544405,
-0.02533048950135708,
0.04212746024131775,
-0.06133203208446503,
0.028065642341971397,
-0.01944943703711033,
-0.020479906350374222,
-0.04083157330751419,
-0.023284584283828735,
-0.010037893429398537,
0.07794702798128128,
0.04998115822672844,
-0.010596327483654022,
0.04027871787548065,
0.010399464517831802
] | 0.14339
|
``` ### `util.types.isKeyObject(value)` \* `value` {Object} \* Returns: {boolean} Returns `true` if `value` is a {KeyObject}, `false` otherwise. ### `util.types.isMap(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a built-in {Map} instance. ```js util.types.isMap(new Map()); // Returns true ``` ### `util.types.isMapIterator(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is an iterator returned for a built-in {Map} instance. ```js const map = new Map(); util.types.isMapIterator(map.keys()); // Returns true util.types.isMapIterator(map.values()); // Returns true util.types.isMapIterator(map.entries()); // Returns true util.types.isMapIterator(map[Symbol.iterator]()); // Returns true ``` ### `util.types.isModuleNamespaceObject(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is an instance of a [Module Namespace Object][]. ```mjs import \* as ns from './a.js'; util.types.isModuleNamespaceObject(ns); // Returns true ``` ### `util.types.isNativeError(value)` > Stability: 0 - Deprecated: Use [`Error.isError`][] instead. \*\*Note:\*\* As of Node.js 24, `Error.isError()` is currently slower than `util.types.isNativeError()`. If performance is critical, consider benchmarking both in your environment. \* `value` {any} \* Returns: {boolean} Returns `true` if the value was returned by the constructor of a [built-in `Error` type][]. ```js console.log(util.types.isNativeError(new Error())); // true console.log(util.types.isNativeError(new TypeError())); // true console.log(util.types.isNativeError(new RangeError())); // true ``` Subclasses of the native error types are also native errors: ```js class MyError extends Error {} console.log(util.types.isNativeError(new MyError())); // true ``` A value being `instanceof` a native error class is not equivalent to `isNativeError()` returning `true` for that value. `isNativeError()` returns `true` for errors which come from a different [realm][] while `instanceof Error` returns `false` for these errors: ```mjs import { createContext, runInContext } from 'node:vm'; import { types } from 'node:util'; const context = createContext({}); const myError = runInContext('new Error()', context); console.log(types.isNativeError(myError)); // true console.log(myError instanceof Error); // false ``` ```cjs const { createContext, runInContext } = require('node:vm'); const { types } = require('node:util'); const context = createContext({}); const myError = runInContext('new Error()', context); console.log(types.isNativeError(myError)); // true console.log(myError instanceof Error); // false ``` Conversely, `isNativeError()` returns `false` for all objects which were not returned by the constructor of a native error. That includes values which are `instanceof` native errors: ```js const myError = { \_\_proto\_\_: Error.prototype }; console.log(util.types.isNativeError(myError)); // false console.log(myError instanceof Error); // true ``` ### `util.types.isNumberObject(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a number object, e.g. created by `new Number()`. ```js util.types.isNumberObject(0); // Returns false util.types.isNumberObject(new Number(0)); // Returns true ``` ### `util.types.isPromise(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a built-in {Promise}. ```js util.types.isPromise(Promise.resolve(42)); // Returns true ``` ### `util.types.isProxy(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a {Proxy} instance. ```js const target = {}; const proxy = new Proxy(target, {}); util.types.isProxy(target); // Returns false util.types.isProxy(proxy); // Returns true ``` ### `util.types.isRegExp(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a regular expression object. ```js util.types.isRegExp(/abc/); // Returns true util.types.isRegExp(new RegExp('abc')); // Returns true ``` ### `util.types.isSet(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a built-in {Set} instance. ```js util.types.isSet(new Set()); // Returns true ``` ### `util.types.isSetIterator(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is an iterator returned for a built-in {Set} instance. ```js const set = new Set(); util.types.isSetIterator(set.keys()); // Returns true util.types.isSetIterator(set.values()); // Returns true util.types.isSetIterator(set.entries()); // Returns true util.types.isSetIterator(set[Symbol.iterator]()); // Returns true ``` ### `util.types.isSharedArrayBuffer(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a built-in {SharedArrayBuffer} instance. This does \_not\_ include {ArrayBuffer} instances. Usually, it is desirable to test for both; See [`util.types.isAnyArrayBuffer()`][] for that. ```js util.types.isSharedArrayBuffer(new ArrayBuffer()); // Returns false util.types.isSharedArrayBuffer(new SharedArrayBuffer()); // Returns true ``` ### `util.types.isStringObject(value)` \* `value` {any} \*
|
https://github.com/nodejs/node/blob/main//doc/api/util.md
|
main
|
nodejs
|
[
0.013509433716535568,
0.08583804219961166,
0.038462378084659576,
0.00528333056718111,
-0.008068909868597984,
-0.011622443795204163,
0.03374047204852104,
0.027234254404902458,
-0.02665560133755207,
-0.010919662192463875,
-0.02632232941687107,
-0.05319315567612648,
-0.022535325959324837,
-0.0026969383470714092,
0.058409884572029114,
0.007436714600771666,
0.013166205957531929,
-0.0039929780177772045,
0.0312839075922966,
-0.03858080506324768,
0.03515417501330376,
-0.06330794095993042,
-0.028906909748911858,
-0.030910490080714226,
-0.007825942710042,
0.08134027570486069,
-0.010477468371391296,
-0.09759534895420074,
0.0033920560963451862,
-0.035186946392059326,
-0.038699861615896225,
-0.007997407577931881,
-0.03035430796444416,
0.043408095836639404,
0.035439033061265945,
0.11320280283689499,
0.014047414995729923,
-0.014989626593887806,
0.029464492574334145,
-0.013406355865299702,
-0.03053940460085869,
0.07122257351875305,
-0.04156870022416115,
-0.06209548935294151,
0.05314241722226143,
0.04016371816396713,
-0.012502827681601048,
-0.0022509642876684666,
-0.08613131195306778,
0.014834201894700527,
-0.018295612186193466,
0.06020480394363403,
-0.04745711013674736,
-0.012984964065253735,
0.06569838523864746,
0.0354885533452034,
-0.03455200046300888,
-0.07604698836803436,
0.022857410833239555,
-0.019861923530697823,
-0.03192070499062538,
-0.004609567113220692,
0.03111676126718521,
-0.038980498909950256,
0.08569815754890442,
-0.007845956832170486,
-0.0002474857901688665,
-0.037539172917604446,
0.0832284465432167,
0.011599012650549412,
0.03342244774103165,
-0.0005288440152071416,
0.08733288198709488,
-0.021453088149428368,
-0.03820853307843208,
-0.008571440353989601,
0.01987333595752716,
0.007041329517960548,
0.008872034028172493,
0.02972543239593506,
-0.09475242346525192,
-0.10315050184726715,
-0.03393850848078728,
0.01820235513150692,
0.009272708557546139,
-0.015364298596978188,
-0.056498460471630096,
-0.03319936245679855,
0.029844626784324646,
0.1105109453201294,
-0.03534117713570595,
-0.07207860052585602,
0.030156485736370087,
0.09734000265598297,
0.1398586481809616,
0.015844006091356277,
-0.005205814726650715,
-0.0017653278773650527,
0.0315609872341156,
0.01381872408092022,
-0.019748518243432045,
-0.04521244764328003,
0.04186069965362549,
-0.15561532974243164,
0.02852320298552513,
0.012549293227493763,
-0.008184551261365414,
-0.13446275889873505,
-0.03672688081860542,
0.026892732828855515,
0.009711411781609058,
-0.034639522433280945,
0.05761542543768883,
-0.0034948268439620733,
-0.12442076951265335,
0.029180927202105522,
-0.01887996681034565,
-0.018787173554301262,
0.03570972755551338,
0.10470795631408691,
0.054021429270505905,
-0.05572378635406494,
0.10576266795396805,
0.01510677207261324,
-0.0373648963868618,
-0.004062640480697155,
-0.07029370963573456,
2.343272315915396e-33,
-0.012481712736189365,
-0.0032605999149382114,
0.02209516055881977,
0.025695381686091423,
-0.04064173251390457,
0.011808143928647041,
-0.0061447396874427795,
0.023650480434298515,
-0.06469481438398361,
0.008835417218506336,
0.012103822082281113,
0.14050628244876862,
-0.09929104149341583,
0.0753755271434784,
0.039534930139780045,
-0.021878771483898163,
0.041873667389154434,
-0.06722859293222427,
-0.095386803150177,
-0.062277473509311676,
-0.008867701515555382,
0.00867608841508627,
-0.07387746870517731,
0.02430630661547184,
0.04294572025537491,
-0.04347437620162964,
-0.03036734275519848,
0.06517486274242401,
-0.08568418771028519,
-0.007255994249135256,
0.06536762416362762,
0.0030762862879782915,
-0.07081642746925354,
0.08254243433475494,
0.02690720185637474,
0.06477148085832596,
-0.008056889288127422,
0.021059606224298477,
-0.12201075255870819,
-0.12565594911575317,
-0.034676987677812576,
-0.04097310081124306,
-0.08099595457315445,
-0.01892804354429245,
0.04033248871564865,
-0.10090123862028122,
-0.041257113218307495,
-0.03348085656762123,
0.027059748768806458,
0.007407084573060274,
0.05333654582500458,
0.038352180272340775,
-0.03454495966434479,
0.01280300784856081,
0.0022097439505159855,
0.012853200547397137,
0.04310944303870201,
0.079875148832798,
0.06270726770162582,
0.09311824291944504,
-0.05988287180662155,
0.014831683598458767,
0.029011443257331848,
-0.002352410228922963,
-0.0765465497970581,
0.05500369518995285,
0.01446764450520277,
-0.027329131960868835,
0.017453668639063835,
-0.03103659115731716,
0.04664815217256546,
0.04312846064567566,
-0.025699684396386147,
0.061249006539583206,
-0.039148226380348206,
-0.044245604425668716,
-0.0980929359793663,
-0.018833279609680176,
-0.049990441650152206,
-0.1114264726638794,
-0.010765339247882366,
0.019295433536171913,
-0.018398670479655266,
0.11086416244506836,
0.00027680190396495163,
0.048332177102565765,
-0.06483806669712067,
-0.002164552453905344,
0.09537665545940399,
0.06965413689613342,
-0.043494828045368195,
0.000571046897675842,
-0.06060145050287247,
-0.06444743275642395,
-0.05916108191013336,
-5.5675027100072315e-33,
-0.015498848631978035,
-0.011737151071429253,
-0.02500149793922901,
0.069135881960392,
-0.057836972177028656,
-0.02512011118233204,
0.07457354664802551,
-0.031248051673173904,
0.009869463741779327,
-0.027251943945884705,
-0.04146987944841385,
-0.0007181052351370454,
0.11034595221281052,
-0.015434199944138527,
0.009239680133759975,
0.04995032027363777,
-0.07347767055034637,
-0.08026982843875885,
0.038214825093746185,
0.00035287014907225966,
0.019789163023233414,
0.017988182604312897,
0.038189101964235306,
0.052685774862766266,
-0.041217971593141556,
0.040164556354284286,
-0.06529811024665833,
-0.0010030186967924237,
0.04098379611968994,
0.007753618992865086,
0.023995516821742058,
0.025046933442354202,
0.03876294568181038,
-0.006436272524297237,
0.00027324780239723623,
-0.07580062001943588,
0.05247589945793152,
0.08496994525194168,
-0.05769139155745506,
0.019336123019456863,
-0.009149213321506977,
-0.06304755061864853,
0.015461508184671402,
-0.013558404520154,
-0.0544419139623642,
-0.002569216303527355,
0.08350257575511932,
0.059720154851675034,
0.07086341083049774,
-0.0010746995685622096,
0.08719317615032196,
-0.07557910680770874,
-0.02576514147222042,
0.03138551488518715,
-0.031251613050699234,
-0.002845095470547676,
-0.05763476341962814,
-0.061247535049915314,
0.011514882557094097,
0.0762983188033104,
0.009025669656693935,
-0.17451685667037964,
0.07217623293399811,
0.04510026425123215,
0.003054445842280984,
-0.0636068731546402,
-0.06653344631195068,
-0.03046402707695961,
0.01482430100440979,
0.012538701295852661,
0.0755152702331543,
-0.016031872481107712,
-0.01357887964695692,
-0.042760420590639114,
0.03529702499508858,
0.018779469653964043,
0.0172207560390234,
-0.010388837195932865,
0.0949830487370491,
-0.08281207829713821,
-0.030795950442552567,
-0.010666154325008392,
0.043949007987976074,
0.02261224575340748,
-0.0038140572141855955,
0.02374069020152092,
0.041817307472229004,
-0.011805337853729725,
-0.05591411888599396,
0.05675828829407692,
0.030964862555265427,
0.038105204701423645,
-0.1475701481103897,
-0.03521161898970604,
-0.0284038744866848,
-4.6835477718332186e-8,
-0.016567816957831383,
-0.05880651995539665,
-0.02122609317302704,
0.018710235133767128,
-0.013944583013653755,
-0.053742021322250366,
0.07184548676013947,
0.011224474757909775,
0.007036398630589247,
-0.0699281096458435,
-0.008732251822948456,
0.03223641589283943,
0.014404133893549442,
-0.06223364546895027,
0.10014992952346802,
-0.04065936803817749,
-0.04564373940229416,
0.026278764009475708,
-0.0569247268140316,
0.08693572133779526,
-0.00888653565198183,
-0.032838743180036545,
-0.034490056335926056,
0.0470660962164402,
0.018058540299534798,
0.02413540706038475,
0.032713618129491806,
-0.022045567631721497,
0.06030631437897682,
0.020961612462997437,
-0.04375331848859787,
0.04942208528518677,
0.0626603290438652,
0.002001014770939946,
-0.02632349729537964,
0.039323750883340836,
0.0095906937494874,
-0.00989952776581049,
-0.009593230672180653,
0.09697648137807846,
0.03204109147191048,
0.004871032666414976,
-0.07971495389938354,
0.0079137422144413,
-0.09487223625183105,
0.012114175595343113,
-0.0009429638739675283,
0.051148947328329086,
-0.05040287598967552,
0.0194120854139328,
-0.11208786815404892,
0.04197702184319496,
-0.019150493666529655,
-0.004478820133954287,
-0.07971993088722229,
0.013274570927023888,
0.026771407574415207,
0.038435231894254684,
-0.0035436057951301336,
-0.0016788530629128218,
0.08253653347492218,
-0.06028560921549797,
-0.005249279551208019,
-0.01422728132456541
] | 0.086241
|
{any} \* Returns: {boolean} Returns `true` if the value is a built-in {SharedArrayBuffer} instance. This does \_not\_ include {ArrayBuffer} instances. Usually, it is desirable to test for both; See [`util.types.isAnyArrayBuffer()`][] for that. ```js util.types.isSharedArrayBuffer(new ArrayBuffer()); // Returns false util.types.isSharedArrayBuffer(new SharedArrayBuffer()); // Returns true ``` ### `util.types.isStringObject(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a string object, e.g. created by `new String()`. ```js util.types.isStringObject('foo'); // Returns false util.types.isStringObject(new String('foo')); // Returns true ``` ### `util.types.isSymbolObject(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a symbol object, created by calling `Object()` on a `Symbol` primitive. ```js const symbol = Symbol('foo'); util.types.isSymbolObject(symbol); // Returns false util.types.isSymbolObject(Object(symbol)); // Returns true ``` ### `util.types.isTypedArray(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a built-in {TypedArray} instance. ```js util.types.isTypedArray(new ArrayBuffer()); // Returns false util.types.isTypedArray(new Uint8Array()); // Returns true util.types.isTypedArray(new Float64Array()); // Returns true ``` See also [`ArrayBuffer.isView()`][]. ### `util.types.isUint8Array(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a built-in {Uint8Array} instance. ```js util.types.isUint8Array(new ArrayBuffer()); // Returns false util.types.isUint8Array(new Uint8Array()); // Returns true util.types.isUint8Array(new Float64Array()); // Returns false ``` ### `util.types.isUint8ClampedArray(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a built-in {Uint8ClampedArray} instance. ```js util.types.isUint8ClampedArray(new ArrayBuffer()); // Returns false util.types.isUint8ClampedArray(new Uint8ClampedArray()); // Returns true util.types.isUint8ClampedArray(new Float64Array()); // Returns false ``` ### `util.types.isUint16Array(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a built-in {Uint16Array} instance. ```js util.types.isUint16Array(new ArrayBuffer()); // Returns false util.types.isUint16Array(new Uint16Array()); // Returns true util.types.isUint16Array(new Float64Array()); // Returns false ``` ### `util.types.isUint32Array(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a built-in {Uint32Array} instance. ```js util.types.isUint32Array(new ArrayBuffer()); // Returns false util.types.isUint32Array(new Uint32Array()); // Returns true util.types.isUint32Array(new Float64Array()); // Returns false ``` ### `util.types.isWeakMap(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a built-in {WeakMap} instance. ```js util.types.isWeakMap(new WeakMap()); // Returns true ``` ### `util.types.isWeakSet(value)` \* `value` {any} \* Returns: {boolean} Returns `true` if the value is a built-in {WeakSet} instance. ```js util.types.isWeakSet(new WeakSet()); // Returns true ``` ## Deprecated APIs The following APIs are deprecated and should no longer be used. Existing applications and modules should be updated to find alternative approaches. ### `util.\_extend(target, source)` > Stability: 0 - Deprecated: Use [`Object.assign()`][] instead. \* `target` {Object} \* `source` {Object} The `util.\_extend()` method was never intended to be used outside of internal Node.js modules. The community found and used it anyway. It is deprecated and should not be used in new code. JavaScript comes with very similar built-in functionality through [`Object.assign()`][]. ### `util.isArray(object)` > Stability: 0 - Deprecated: Use [`Array.isArray()`][] instead. \* `object` {any} \* Returns: {boolean} Alias for [`Array.isArray()`][]. Returns `true` if the given `object` is an `Array`. Otherwise, returns `false`. ```js const util = require('node:util'); util.isArray([]); // Returns: true util.isArray(new Array()); // Returns: true util.isArray({}); // Returns: false ``` An automated migration is available ([source](https://github.com/nodejs/userland-migrations/tree/main/recipes/util-is)): ```bash npx codemod@latest @nodejs/util-is ``` [Common System Errors]: errors.md#common-system-errors [Custom inspection functions on objects]: #custom-inspection-functions-on-objects [Custom promisified functions]: #custom-promisified-functions [Customizing `util.inspect` colors]: #customizing-utilinspect-colors [Internationalization]: intl.md [Module Namespace Object]: https://tc39.github.io/ecma262/#sec-module-namespace-exotic-objects [WHATWG Encoding Standard]: https://encoding.spec.whatwg.org/ [`'uncaughtException'`]: process.md#event-uncaughtexception [`'warning'`]: process.md#event-warning [`Array.isArray()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Array/isArray [`ArrayBuffer.isView()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/ArrayBuffer/isView [`Error.isError`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Error/isError [`JSON.stringify()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/JSON/stringify [`MIMEparams`]: #class-utilmimeparams [`Object.assign()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Object/assign [`Object.freeze()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Object/freeze [`Runtime.ScriptId`]: https://chromedevtools.github.io/devtools-protocol/1-3/Runtime/#type-ScriptId [`assert.deepStrictEqual()`]: assert.md#assertdeepstrictequalactual-expected-message [`console.error()`]: console.md#consoleerrordata-args [`mime.toString()`]: #mimetostring [`mimeParams.entries()`]: #mimeparamsentries [`napi\_create\_external()`]: n-api.md#napi\_create\_external [`target` and `handler`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Proxy#terminology [`tty.hasColors()`]: tty.md#writestreamhascolorscount-env [`util.diff()`]: #utildiffactual-expected [`util.format()`]: #utilformatformat-args [`util.inspect()`]: #utilinspectobject-options [`util.promisify()`]: #utilpromisifyoriginal [`util.types.isAnyArrayBuffer()`]: #utiltypesisanyarraybuffervalue [`util.types.isArrayBuffer()`]: #utiltypesisarraybuffervalue [`util.types.isSharedArrayBuffer()`]: #utiltypesissharedarraybuffervalue [async function]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async\_function [built-in `Error` type]: https://tc39.es/ecma262/#sec-error-objects [compare function]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Array/sort#parameters [constructor]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Object/constructor [default sort]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Array/sort [global symbol registry]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Symbol/for [list of deprecated APIS]: deprecations.md#list-of-deprecated-apis [modifiers]: #modifiers [realm]: https://tc39.es/ecma262/#realm [semantically incompatible]: https://github.com/nodejs/node/issues/4179 [util.inspect.custom]: #utilinspectcustom
|
https://github.com/nodejs/node/blob/main//doc/api/util.md
|
main
|
nodejs
|
[
0.009863616898655891,
0.03514495864510536,
-0.01239930372685194,
0.0414954274892807,
-0.05973121151328087,
-0.014908716082572937,
0.0916655883193016,
-0.07797448337078094,
0.005150702781975269,
-0.08454211056232452,
-0.05364436283707619,
-0.024375107139348984,
-0.04033515229821205,
0.029527723789215088,
0.041004251688718796,
-0.005597969517111778,
0.02079668827354908,
-0.09090857207775116,
-0.009906667284667492,
0.0001974283077288419,
0.05860945209860802,
-0.03571000695228577,
-0.04645731672644615,
-0.01168963871896267,
0.0027714676689356565,
0.07828649878501892,
-0.0015121153555810452,
-0.08317127823829651,
0.06528503447771072,
-0.007617267780005932,
-0.004433066118508577,
-0.00927331205457449,
-0.06328175961971283,
0.004289948847144842,
0.0012227663537487388,
0.06258457154035568,
0.002894015982747078,
-0.029428472742438316,
0.02453995868563652,
-0.05115223303437233,
0.0022118776105344296,
0.05179247632622719,
-0.12035759538412094,
-0.02555122599005699,
0.014029771089553833,
0.0010408104863017797,
-0.060913339257240295,
-0.019560864195227623,
-0.08489584177732468,
-0.031807396560907364,
-0.015690160915255547,
-0.018914248794317245,
-0.006240079179406166,
-0.007964752614498138,
0.09759369492530823,
-0.007992486469447613,
-0.06718738377094269,
0.005897881463170052,
-0.04230710119009018,
0.03301535174250603,
-0.026789069175720215,
-0.011702420189976692,
0.022952070459723473,
0.037790827453136444,
0.06685669720172882,
-0.07320575416088104,
0.050312042236328125,
0.030443038791418076,
0.08065291494131088,
-0.04963337257504463,
-0.062168706208467484,
0.03525479510426521,
0.04197749122977257,
0.020310411229729652,
0.014932706952095032,
0.042565640062093735,
0.08630339801311493,
-0.012705143541097641,
0.043221551924943924,
-0.0011545165907591581,
-0.10230758041143417,
-0.0647345781326294,
-0.040806036442518234,
0.018703501671552658,
0.03434023633599281,
0.06098504737019539,
-0.09014957398176193,
0.012566745281219482,
-0.04647952690720558,
0.07214782387018204,
-0.021236712113022804,
-0.058013368397951126,
-0.038615357130765915,
0.08881383389234543,
0.07773630321025848,
-0.02390764094889164,
-0.007454378996044397,
0.01949370838701725,
0.012214099057018757,
0.043217550963163376,
-0.007403485011309385,
0.03144126757979393,
0.11626970767974854,
-0.040386781096458435,
0.070160873234272,
0.03929285705089569,
0.020804572850465775,
-0.08767837285995483,
-0.03793368116021156,
0.002231449820101261,
-0.04064974933862686,
0.05935915559530258,
0.03033873438835144,
-0.00217680842615664,
-0.13104145228862762,
-0.007162007037550211,
-0.00005333029548637569,
-0.04506082087755203,
0.020232733339071274,
0.05206093192100525,
0.034515783190727234,
-0.04892995208501816,
0.12558910250663757,
0.057916294783353806,
-0.015241874381899834,
0.06706550717353821,
-0.10394222289323807,
2.6141793153997928e-33,
0.021465275436639786,
-0.04903508722782135,
-0.024162253364920616,
-0.05455421283841133,
-0.08580762147903442,
0.017207061871886253,
-0.07023891061544418,
0.12734325230121613,
0.04045528545975685,
0.0053135668858885765,
0.01932704634964466,
0.06852027028799057,
-0.010075092315673828,
0.06256075203418732,
0.05915583670139313,
0.004993692506104708,
0.08122915029525757,
-0.04363558068871498,
0.00723868515342474,
0.00031025809585116804,
-0.04311472922563553,
0.10884060710668564,
-0.07505630701780319,
0.0015165653312578797,
-0.04857353866100311,
-0.038630496710538864,
0.04019957408308983,
-0.004477674141526222,
-0.06524649262428284,
0.00919917318969965,
0.01837240904569626,
-0.04455818980932236,
-0.02749677374958992,
0.03616007789969444,
0.052038200199604034,
0.04429132491350174,
-0.016515981405973434,
0.019765788689255714,
-0.11751659959554672,
-0.060228802263736725,
-0.011887235566973686,
-0.012574782595038414,
-0.03950158879160881,
-0.01954968087375164,
0.04479551315307617,
-0.11468955874443054,
-0.10916578769683838,
-0.01570761203765869,
0.018968697637319565,
-0.023362569510936737,
-0.014444203115999699,
0.10932637751102448,
0.017929520457983017,
0.07306339591741562,
0.0436805821955204,
-0.019827621057629585,
0.04081900790333748,
0.04159630462527275,
-0.0038507687859237194,
0.020099850371479988,
-0.035456281155347824,
0.0013086379040032625,
-0.018211830407381058,
0.03273893892765045,
-0.11019805073738098,
0.09244383871555328,
0.007447159383445978,
-0.0721796452999115,
0.006296777632087469,
-0.0003732311597559601,
-0.019397065043449402,
0.08409993350505829,
-0.0446685366332531,
0.05040014162659645,
-0.028895070776343346,
-0.0645253136754036,
-0.08031784743070602,
0.0016780294245108962,
0.03767966851592064,
-0.089961476624012,
0.04287702962756157,
-0.02670963481068611,
-0.03480937331914902,
0.08244670182466507,
-0.05803212150931358,
0.10649808496236801,
-0.009578282944858074,
-0.0683276578783989,
0.07745326310396194,
0.0314660482108593,
-0.00017235336417797953,
0.004174547269940376,
-0.11102122068405151,
-0.11425098031759262,
-0.010033155791461468,
-5.9120845526133844e-33,
0.05309700965881348,
0.042017750442028046,
-0.05851399898529053,
0.015447504818439484,
-0.061298269778490067,
-0.03407207131385803,
0.08072564005851746,
-0.015360924415290356,
-0.015759076923131943,
-0.054346803575754166,
-0.0002985779719892889,
0.03442170470952988,
0.05841295048594475,
-0.014979375526309013,
-0.03209492564201355,
0.04259657487273216,
-0.056661661714315414,
-0.10245414078235626,
0.08681115508079529,
-0.0008316734456457198,
0.009463878348469734,
0.06401016563177109,
0.09325563162565231,
0.027911240234971046,
-0.0500960610806942,
0.002289233496412635,
-0.04865184798836708,
-0.000024463830413878895,
-0.007094461936503649,
0.02191818505525589,
0.0436689518392086,
-0.012203251011669636,
-0.0060566687025129795,
0.005906917154788971,
-0.026128659024834633,
-0.07422170788049698,
0.017779896035790443,
0.08200524747371674,
-0.029881468042731285,
-0.04369111731648445,
0.036305081099271774,
-0.022239891812205315,
-0.027836356312036514,
0.034030672162771225,
-0.02972627617418766,
0.012153577990829945,
-0.03976444527506828,
0.043805330991744995,
0.06465558707714081,
-0.04273739084601402,
0.04139105603098869,
-0.036917462944984436,
-0.014575760811567307,
0.050349801778793335,
-0.015947284176945686,
-0.052825525403022766,
0.011608856730163097,
-0.048893045634031296,
-0.004976711235940456,
0.09383594244718552,
0.01549266092479229,
-0.1010940819978714,
0.008888129144906998,
-0.017756706103682518,
-0.06536037474870682,
-0.08355686813592911,
-0.023781822994351387,
0.025343550369143486,
0.11204666644334793,
-0.039043575525283813,
0.022798558697104454,
-0.013305543921887875,
-0.03375229984521866,
-0.04984644800424576,
-0.0024421890266239643,
0.09757035970687866,
0.016667451709508896,
-0.09159746021032333,
0.045035962015390396,
0.03942403569817543,
0.00838807225227356,
0.014818429946899414,
0.026105592027306557,
0.02253926917910576,
0.041843462735414505,
-0.006903530564159155,
0.009261645376682281,
-0.03750218451023102,
-0.12446486949920654,
0.03218879550695419,
0.059282779693603516,
0.07407041639089584,
-0.13977432250976562,
-0.0625087097287178,
-0.02059588022530079,
-5.3176165693002986e-8,
0.0017576015088707209,
-0.08130809664726257,
-0.036134272813797,
0.007417125161737204,
-0.02975449711084366,
-0.06669902801513672,
-0.04513740539550781,
-0.08046199381351471,
-0.06044134497642517,
-0.03949495404958725,
0.02742251567542553,
0.04786939546465874,
-0.024356454610824585,
-0.00047096385969780385,
0.03940357267856598,
-0.0326373428106308,
-0.032842136919498444,
-0.020958220586180687,
-0.054719146341085434,
0.04513828828930855,
-0.0461188480257988,
-0.006511121056973934,
-0.05653291940689087,
0.000004772231477545574,
0.004714164417237043,
0.03668203204870224,
0.012874924577772617,
0.00551958940923214,
0.04040759801864624,
0.00994096603244543,
0.022586088627576828,
0.09306501597166061,
0.07212624698877335,
0.023910392075777054,
0.04198512062430382,
0.08507449179887772,
-0.021580370143055916,
0.029615022242069244,
0.009669453836977482,
0.11671601235866547,
0.06604188680648804,
0.009449177421629429,
-0.034413211047649384,
0.05117012560367584,
0.0014153377851471305,
-0.05657056346535683,
0.01998426951467991,
0.030649762600660324,
-0.0220665130764246,
-0.010009238496422768,
0.01966274157166481,
0.04326113685965538,
-0.012541533447802067,
0.019775237888097763,
-0.07456998527050018,
-0.05855709686875343,
-0.02977169305086136,
0.04415661096572876,
0.06480521708726883,
-0.002980479970574379,
0.09751152992248535,
-0.029399234801530838,
0.04503806307911873,
-0.038891036063432693
] | 0.106034
|
[`tty.hasColors()`]: tty.md#writestreamhascolorscount-env [`util.diff()`]: #utildiffactual-expected [`util.format()`]: #utilformatformat-args [`util.inspect()`]: #utilinspectobject-options [`util.promisify()`]: #utilpromisifyoriginal [`util.types.isAnyArrayBuffer()`]: #utiltypesisanyarraybuffervalue [`util.types.isArrayBuffer()`]: #utiltypesisarraybuffervalue [`util.types.isSharedArrayBuffer()`]: #utiltypesissharedarraybuffervalue [async function]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async\_function [built-in `Error` type]: https://tc39.es/ecma262/#sec-error-objects [compare function]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Array/sort#parameters [constructor]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Object/constructor [default sort]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Array/sort [global symbol registry]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Symbol/for [list of deprecated APIS]: deprecations.md#list-of-deprecated-apis [modifiers]: #modifiers [realm]: https://tc39.es/ecma262/#realm [semantically incompatible]: https://github.com/nodejs/node/issues/4179 [util.inspect.custom]: #utilinspectcustom
|
https://github.com/nodejs/node/blob/main//doc/api/util.md
|
main
|
nodejs
|
[
0.011652909219264984,
0.0010484112426638603,
-0.054608214646577835,
0.03827435523271561,
-0.046312980353832245,
-0.004840041510760784,
0.01066754013299942,
0.01188826933503151,
-0.018896309658885002,
-0.06212128326296806,
-0.10242880135774612,
-0.06060946732759476,
-0.03412599116563797,
0.02081306278705597,
-0.0002620148879941553,
0.00842356588691473,
-0.050961434841156006,
-0.06808676570653915,
-0.0004025450616609305,
-0.04496915638446808,
0.059638623148202896,
-0.06443050503730774,
0.06334377825260162,
-0.046220649033784866,
0.019605865702033043,
0.029936840757727623,
0.06904125958681107,
-0.03889412805438042,
0.02445663884282112,
-0.04614085704088211,
0.002783246338367462,
-0.013860882259905338,
-0.012117964215576649,
-0.07986084371805191,
0.018212849274277687,
0.022898558527231216,
0.07095837593078613,
-0.08545773476362228,
0.01408194750547409,
0.016474463045597076,
0.08995690941810608,
0.059342674911022186,
-0.08775435388088226,
-0.027120094746351242,
-0.0024276096373796463,
-0.06566701084375381,
-0.023842081427574158,
-0.007873539812862873,
-0.10954976826906204,
-0.01624222658574581,
0.031141694635152817,
0.06025749444961548,
0.0010575838387012482,
0.007866219617426395,
0.01713857427239418,
0.005143357440829277,
-0.030878856778144836,
0.06005334109067917,
0.012485790997743607,
0.035989683121442795,
-0.06552295386791229,
-0.010920213535428047,
-0.02417115680873394,
-0.02526659332215786,
0.009484614245593548,
0.11741799116134644,
0.03431474044919014,
-0.03239069879055023,
0.024229159578680992,
-0.06851514428853989,
-0.04784766584634781,
-0.057516057044267654,
0.08309730887413025,
0.041906051337718964,
-0.02008247561752796,
0.00300497654825449,
0.1282457411289215,
0.035138651728630066,
-0.11825450509786606,
-0.07028784602880478,
0.0010227605234831572,
-0.07097240537405014,
0.012764997780323029,
0.08554387092590332,
0.13049037754535675,
0.10222291946411133,
-0.11304657906293869,
0.023706655949354172,
-0.04400897026062012,
0.05418252944946289,
-0.06772346049547195,
-0.01938406191766262,
-0.07369133830070496,
0.040689900517463684,
0.05304598808288574,
0.018963271751999855,
0.045301083475351334,
-0.014660028740763664,
-0.015005367808043957,
0.004956543445587158,
-0.009421412833034992,
-0.062429897487163544,
-0.0015826479066163301,
0.0026021364610642195,
0.003066753037273884,
-0.03854503110051155,
0.087735116481781,
0.02882940135896206,
-0.059963323175907135,
0.0031247208826243877,
0.00939248688519001,
0.07434647530317307,
0.024581557139754295,
0.05830153077840805,
0.0118870185688138,
0.013414056040346622,
-0.06118866056203842,
-0.029336491599678993,
0.09385824203491211,
0.05524832755327225,
0.12276384234428406,
-0.018653402104973793,
0.013886967673897743,
0.026204366236925125,
0.03799668699502945,
-0.04218123108148575,
0.053346212953329086,
7.503145911152106e-33,
0.012019256129860878,
-0.026456890627741814,
0.03218289092183113,
-0.00504525750875473,
0.015574872493743896,
0.09141702204942703,
0.04523729905486107,
-0.030400842428207397,
-0.053921863436698914,
-0.0709998831152916,
0.028754087164998055,
0.058674346655607224,
-0.08554893732070923,
-0.018202422186732292,
-0.029358789324760437,
-0.017825810238718987,
0.008657277561724186,
-0.013698200695216656,
0.004424090031534433,
0.07248006761074066,
-0.016001641750335693,
0.10446706414222717,
0.023800421506166458,
-0.0037413868121802807,
-0.08519956469535828,
0.03306330367922783,
-0.0271742045879364,
0.09289499372243881,
-0.06036132574081421,
0.01160389557480812,
0.027102988213300705,
0.05821700394153595,
-0.04064015671610832,
0.05252338573336601,
-0.04542827233672142,
-0.08378788828849792,
-0.014808649197220802,
0.006823678966611624,
-0.1017366349697113,
0.08881016820669174,
-0.1039985865354538,
0.07122744619846344,
-0.06862252205610275,
0.009630024433135986,
-0.06554849445819855,
-0.029547685757279396,
0.00023572736245114356,
-0.01030982006341219,
0.03262108191847801,
0.0353299044072628,
-0.0900537520647049,
0.05457261577248573,
-0.03419331833720207,
-0.058944057673215866,
0.023758793249726295,
-0.04601304233074188,
0.06561156362295151,
-0.0014500056859105825,
0.03905552253127098,
-0.003384481882676482,
0.07233423739671707,
0.0016932003200054169,
-0.010394921526312828,
-0.07458450645208359,
-0.004216743633151054,
-0.028995651751756668,
-0.006598351057618856,
-0.024235637858510017,
-0.08960389345884323,
-0.054505132138729095,
-0.0008760758792050183,
0.07143853604793549,
0.020020095631480217,
0.0016018830938264728,
0.06244261935353279,
-0.003371864091604948,
-0.004363954532891512,
0.010512965731322765,
-0.029950551688671112,
-0.051062650978565216,
0.06518509238958359,
0.0036642381455749273,
-0.03954256698489189,
-0.016156740486621857,
-0.04378699138760567,
0.08541765809059143,
0.026869144290685654,
-0.027337584644556046,
-0.0039527527987957,
0.04100032523274422,
-0.023638751357793808,
-0.026419244706630707,
-0.03424915298819542,
-0.10267632454633713,
-0.013147583231329918,
-9.207171909462864e-33,
0.06905089318752289,
0.0006893175886943936,
-0.07969062030315399,
0.0416141115128994,
-0.023175103589892387,
-0.0512937568128109,
0.09571687132120132,
0.07768657803535461,
0.003187729511409998,
-0.05520060285925865,
0.07520066201686859,
0.058916669338941574,
-0.0457332618534565,
0.0024073689710348845,
-0.07962331920862198,
0.06316635757684708,
0.0030875892844051123,
-0.028458300977945328,
0.06348259001970291,
-0.09740960597991943,
-0.026052288711071014,
0.015557307749986649,
0.0346125029027462,
0.04826149716973305,
-0.10206696391105652,
0.03526882827281952,
0.03728495165705681,
-0.0035257276613265276,
-0.05232981592416763,
-0.04219210892915726,
0.0194600448012352,
0.04670827463269234,
-0.04057086259126663,
0.04598376154899597,
0.03171519190073013,
-0.0272546224296093,
0.053725022822618484,
-0.04520085081458092,
-0.0917779877781868,
0.02629736065864563,
0.06937471032142639,
-0.04423834756016731,
-0.01190126407891512,
-0.03847261518239975,
0.010876532644033432,
0.03119574673473835,
-0.06186015531420708,
0.002675349358469248,
0.05759750306606293,
-0.052869465202093124,
0.10319916158914566,
-0.0273552518337965,
-0.018980616703629494,
0.04993612319231033,
0.003406106261536479,
-0.04887564107775688,
0.05901789292693138,
-0.028297768905758858,
0.03864217922091484,
0.1232132688164711,
-0.014140027575194836,
-0.03736228868365288,
-0.037319619208574295,
-0.1178942620754242,
0.006435898598283529,
-0.06034388393163681,
-0.025112103670835495,
-0.01932472549378872,
0.11842848360538483,
0.06929191201925278,
0.04407334327697754,
-0.132614865899086,
0.05830321088433266,
0.026346290484070778,
0.02340513840317726,
-0.03254259005188942,
-0.040741872042417526,
-0.07192074507474899,
0.04762342944741249,
0.07135248929262161,
0.011524276807904243,
0.03295913711190224,
-0.022279007360339165,
-0.0020312892738729715,
0.009816257283091545,
0.0355931855738163,
0.000764532363973558,
0.05922836437821388,
-0.029103798791766167,
-0.06454864889383316,
0.0722520649433136,
0.036489758640527725,
-0.07894265651702881,
-0.009603393264114857,
0.003502381034195423,
-5.513015466362958e-8,
-0.07353831082582474,
-0.08530821651220322,
-0.040340714156627655,
-0.004005621187388897,
-0.026758557185530663,
-0.027270179241895676,
-0.02390040084719658,
-0.06565125286579132,
0.07248563319444656,
-0.023120660334825516,
-0.0197600144892931,
-0.022590823471546173,
0.08041393756866455,
0.027443641796708107,
-0.028917508199810982,
0.015860917046666145,
-0.027662988752126694,
0.028126908466219902,
0.014638428576290607,
-0.002972756279632449,
-0.08536960929632187,
-0.003440435975790024,
-0.08025996387004852,
-0.06659780442714691,
-0.028904536738991737,
-0.0007207141607068479,
-0.0028185679111629725,
0.07348521053791046,
0.055188361555337906,
-0.0032323873601853848,
-0.03665977343916893,
0.059035927057266235,
0.03978826478123665,
-0.057216089218854904,
-0.009741936810314655,
0.040527939796447754,
-0.030958514660596848,
0.0058126188814640045,
0.04361565411090851,
0.07021234184503555,
0.02053043618798256,
-0.01150837354362011,
-0.04022287204861641,
0.03860297426581383,
0.03733847662806511,
-0.01136088464409113,
-0.025116123259067535,
0.10751369595527649,
-0.04223199188709259,
0.010917861945927143,
0.020936982706189156,
-0.01452435553073883,
-0.02216198481619358,
0.039098259061574936,
-0.07506515830755234,
-0.10459890216588974,
-0.028932731598615646,
-0.029169563204050064,
0.051606185734272,
0.06570340692996979,
0.05557893216609955,
-0.0859055444598198,
0.051872026175260544,
-0.00641681719571352
] | 0.009722
|
# Single executable applications > Stability: 1.1 - Active development This feature allows the distribution of a Node.js application conveniently to a system that does not have Node.js installed. Node.js supports the creation of [single executable applications][] by allowing the injection of a blob prepared by Node.js, which can contain a bundled script, into the `node` binary. During start up, the program checks if anything has been injected. If the blob is found, it executes the script in the blob. Otherwise Node.js operates as it normally does. The single executable application feature currently only supports running a single embedded script using the [CommonJS][] module system. Users can create a single executable application from their bundled script with the `node` binary itself and any tool which can inject resources into the binary. 1. Create a JavaScript file: ```bash echo 'console.log(`Hello, ${process.argv[2]}!`);' > hello.js ``` 2. Create a configuration file building a blob that can be injected into the single executable application (see [Generating single executable preparation blobs][] for details): \* On systems other than Windows: ```bash echo '{ "main": "hello.js", "output": "sea" }' > sea-config.json ``` \* On Windows: ```bash echo '{ "main": "hello.js", "output": "sea.exe" }' > sea-config.json ``` The `.exe` extension is necessary. 3. Generate the target executable: ```bash node --build-sea sea-config.json ``` 4. Sign the binary (macOS and Windows only): \* On macOS: ```bash codesign --sign - hello ``` \* On Windows (optional): A certificate needs to be present for this to work. However, the unsigned binary would still be runnable. ```powershell signtool sign /fd SHA256 hello.exe ``` 5. Run the binary: \* On systems other than Windows ```console $ ./hello world Hello, world! ``` \* On Windows ```console $ .\hello.exe world Hello, world! ``` ## Generating single executable applications with `--build-sea` To generate a single executable application directly, the `--build-sea` flag can be used. It takes a path to a configuration file in JSON format. If the path passed to it isn't absolute, Node.js will use the path relative to the current working directory. The configuration currently reads the following top-level fields: ```json { "main": "/path/to/bundled/script.js", "executable": "/path/to/node/binary", // Optional, if not specified, uses the current Node.js binary "output": "/path/to/write/the/generated/executable", "disableExperimentalSEAWarning": true, // Default: false "useSnapshot": false, // Default: false "useCodeCache": true, // Default: false "execArgv": ["--no-warnings", "--max-old-space-size=4096"], // Optional "execArgvExtension": "env", // Default: "env", options: "none", "env", "cli" "assets": { // Optional "a.dat": "/path/to/a.dat", "b.txt": "/path/to/b.txt" } } ``` If the paths are not absolute, Node.js will use the path relative to the current working directory. The version of the Node.js binary used to produce the blob must be the same as the one to which the blob will be injected. Note: When generating cross-platform SEAs (e.g., generating a SEA for `linux-x64` on `darwin-arm64`), `useCodeCache` and `useSnapshot` must be set to false to avoid generating incompatible executables. Since code cache and snapshots can only be loaded on the same platform where they are compiled, the generated executable might crash on startup when trying to load code cache or snapshots built on a different platform. ### Assets Users can include assets by adding a key-path dictionary to the configuration as the `assets` field. At build time, Node.js would read the assets from the specified paths and bundle them into the preparation blob. In the generated executable, users can retrieve the assets using the [`sea.getAsset()`][] and [`sea.getAssetAsBlob()`][] APIs. ```json { "main": "/path/to/bundled/script.js", "output": "/path/to/write/the/generated/executable", "assets": { "a.jpg": "/path/to/a.jpg", "b.txt": "/path/to/b.txt" } } ``` The single-executable application can access the assets as follows: ```cjs const { getAsset, getAssetAsBlob, getRawAsset, getAssetKeys } = require('node:sea'); // Get all asset keys. const
|
https://github.com/nodejs/node/blob/main//doc/api/single-executable-applications.md
|
main
|
nodejs
|
[
-0.026993172243237495,
-0.02932790480554104,
-0.023206351324915886,
0.028200088068842888,
0.07935076951980591,
-0.05633435770869255,
-0.05328667163848877,
0.08898390084505081,
0.03625448793172836,
0.019618840888142586,
-0.05437152087688446,
0.06015211343765259,
0.02363143302500248,
-0.04174721986055374,
0.0643414855003357,
0.0729374885559082,
-0.004055200610309839,
0.001640400500036776,
0.007503772620111704,
-0.013082201592624187,
-0.060546230524778366,
-0.011933857575058937,
0.01238279789686203,
-0.002885338617488742,
-0.06780997663736343,
-0.02221628651022911,
-0.05899903178215027,
-0.02365906350314617,
-0.00371153699234128,
-0.05081331357359886,
0.06383062154054642,
-0.028403032571077347,
-0.0013690019259229302,
0.024388974532485008,
-0.05812215432524681,
0.1328519880771637,
0.03139844909310341,
-0.07428087294101715,
-0.10822177678346634,
-0.0677444115281105,
0.022555379197001457,
0.0730537474155426,
-0.1011085957288742,
-0.03221950680017471,
0.018823063001036644,
-0.08309032768011093,
-0.1086978167295456,
0.009458215907216072,
-0.05959908664226532,
-0.012908585369586945,
0.0621023029088974,
-0.08548154681921005,
0.009462920017540455,
-0.014866390265524387,
-0.031538575887680054,
0.015693802386522293,
-0.07060135900974274,
0.03548743203282356,
0.015887215733528137,
0.10885214060544968,
-0.01846056804060936,
0.05592728406190872,
0.022623389959335327,
0.011084969155490398,
0.14784938097000122,
0.06887419521808624,
-0.0046424283646047115,
-0.05914100259542465,
0.020179934799671173,
-0.025008738040924072,
-0.012149170972406864,
-0.011400621384382248,
-0.07044895738363266,
-0.02156391181051731,
-0.13359583914279938,
-0.06699079275131226,
-0.027297036722302437,
0.00016999746731016785,
-0.059646934270858765,
0.033781468868255615,
-0.049781519919633865,
-0.01515979040414095,
-0.024192048236727715,
0.017279794439673424,
-0.003185846144333482,
0.1386549472808838,
0.009966101497411728,
0.017681630328297615,
0.0748768001794815,
0.05646641552448273,
-0.030153868719935417,
-0.02078530378639698,
0.04363991320133209,
0.01977436989545822,
0.042258381843566895,
-0.007591383997350931,
-0.008988004177808762,
0.060612235218286514,
-0.002888763090595603,
0.00412312475964427,
-0.027874650433659554,
-0.02900124527513981,
0.0483192540705204,
-0.014530736953020096,
0.07940726727247238,
-0.017215091735124588,
0.057086747139692307,
-0.041966624557971954,
0.02895357832312584,
-0.033814527094364166,
-0.04538679122924805,
0.01108325645327568,
0.029712654650211334,
-0.042955562472343445,
-0.059832751750946045,
0.0007418438908644021,
0.08490478992462158,
-0.020203450694680214,
0.026932165026664734,
0.1327260434627533,
0.07273231446743011,
0.05634889006614685,
0.05686282366514206,
-0.038184888660907745,
0.08288035541772842,
-0.06696032732725143,
0.02863975241780281,
3.917641654672441e-33,
-0.015255674719810486,
-0.11236054450273514,
0.05097067356109619,
0.08316582441329956,
0.004677077289670706,
-0.029070362448692322,
0.004255855455994606,
0.03470243141055107,
-0.17225195467472076,
0.016772978007793427,
0.02986554056406021,
0.09839844703674316,
0.04789460077881813,
0.04550105333328247,
0.054543182253837585,
-0.002880156971514225,
0.03763535991311073,
0.011601968668401241,
0.11436145007610321,
-0.002712181769311428,
-0.02471204102039337,
-0.020149461925029755,
-0.08958055078983307,
0.09071580320596695,
0.009187165647745132,
0.01813320256769657,
0.053754307329654694,
0.06502195447683334,
0.009477024897933006,
0.006030327640473843,
-0.022529596462845802,
0.060377754271030426,
-0.12410201877355576,
0.026849694550037384,
-0.009915554895997047,
-0.027281587943434715,
-0.07850327342748642,
0.06271865218877792,
-0.024133825674653053,
0.0026527377776801586,
0.0012145452201366425,
0.04087473079562187,
-0.03464886173605919,
-0.02327030524611473,
0.012416774407029152,
-0.08149724453687668,
-0.10219087451696396,
-0.03208422288298607,
-0.01094181276857853,
-0.021197739988565445,
0.02238517627120018,
0.07726725190877914,
0.0658942461013794,
0.024653643369674683,
0.02329004742205143,
0.03027396649122238,
0.01257825456559658,
-0.11422484368085861,
-0.013493463397026062,
0.04273664951324463,
0.04406101629137993,
-0.013383523561060429,
-0.08099664747714996,
0.00511931674554944,
-0.008301432244479656,
-0.02590370364487171,
0.01176416128873825,
-0.01782859116792679,
-0.020578658208251,
0.08260802924633026,
-0.03226913511753082,
0.01613449864089489,
0.06891641765832901,
-0.05851617455482483,
-0.0002816235355567187,
-0.010959954932332039,
-0.023585332557559013,
-0.027323657646775246,
-0.010746701620519161,
0.037639468908309937,
0.007568743545562029,
-0.04962692782282829,
-0.016076041385531425,
0.04236231744289398,
0.07349208742380142,
0.011510309763252735,
-0.0749986320734024,
-0.013922251760959625,
0.00693408353254199,
0.039895158261060715,
0.11212655901908875,
-0.014140268787741661,
-0.028855571523308754,
-0.05748263746500015,
-0.0035533534828573465,
-4.4220999125400406e-33,
0.015884706750512123,
0.03871377557516098,
-0.10796894878149033,
0.06415177881717682,
-0.057198867201805115,
0.013211489655077457,
-0.048466917127370834,
-0.0612381286919117,
-0.03546605259180069,
0.01851201243698597,
-0.09721261262893677,
0.031851254403591156,
0.04235896095633507,
0.012567454017698765,
-0.012687784619629383,
0.044995106756687164,
-0.05499817430973053,
-0.020937390625476837,
0.06116059795022011,
0.013230509124696255,
-0.03918628767132759,
0.008649191819131374,
0.09028397500514984,
-0.006970763672143221,
0.011779668740928173,
-0.056127481162548065,
-0.08113489300012589,
0.03101765364408493,
-0.07784273475408554,
-0.03889536112546921,
-0.058165330439805984,
0.0076313563622534275,
0.001115212100557983,
-0.03776055946946144,
0.024879366159439087,
-0.05285075306892395,
-0.00784974079579115,
0.01690189354121685,
0.10637417435646057,
-0.11143272370100021,
0.011657243594527245,
-0.0012122580083087087,
-0.01008878368884325,
-0.009004802443087101,
0.03907794877886772,
0.060131121426820755,
-0.05591033026576042,
0.04145202413201332,
-0.019676443189382553,
-0.040459588170051575,
-0.09111935645341873,
0.009815518744289875,
-0.0065363673493266106,
-0.005456280894577503,
0.029340242967009544,
-0.09656831622123718,
-0.016167636960744858,
0.05226452648639679,
-0.013721002265810966,
0.06900936365127563,
0.0802072137594223,
-0.08261220902204514,
0.020669622346758842,
-0.0008939860854297876,
-0.037841323763132095,
-0.029974253848195076,
-0.037003859877586365,
0.0005601796437986195,
-0.01195010356605053,
0.026144471019506454,
0.030442887917160988,
-0.005489532835781574,
0.019400637596845627,
0.02987729199230671,
-0.061199672520160675,
0.05890635401010513,
0.037870489060878754,
-0.19420936703681946,
-0.05503486841917038,
0.027362119406461716,
-0.024360425770282745,
0.10331930965185165,
-0.0016996655613183975,
-0.03396376594901085,
-0.026537422090768814,
-0.014410145580768585,
-0.005596946459263563,
-0.019683143123984337,
0.01444019004702568,
0.01902597025036812,
0.015072538517415524,
0.09085264801979065,
-0.053412072360515594,
-0.0013506177347153425,
-0.037597112357616425,
-5.730468899400876e-8,
-0.008444066159427166,
-0.008482136763632298,
-0.07451871037483215,
-0.001998351654037833,
0.0030406841542571783,
0.01455739140510559,
0.012886635959148407,
0.008298033848404884,
0.08896563947200775,
0.015663446858525276,
0.01702076755464077,
-0.03030720353126526,
-0.06137431412935257,
-0.0009973379783332348,
0.03921893239021301,
0.06966640055179596,
-0.011142787523567677,
0.02072290889918804,
-0.01718200370669365,
0.021771224215626717,
0.025434065610170364,
0.07140840590000153,
0.018536685034632683,
0.08401259034872055,
-0.034805767238140106,
-0.05505440756678581,
0.0314779095351696,
-0.009692225605249405,
-0.03849813714623451,
-0.01373083982616663,
-0.03980592265725136,
0.021638963371515274,
0.04615604132413864,
0.03957827016711235,
-0.0037803619634360075,
0.017113862559199333,
-0.019401894882321358,
0.07014604657888412,
0.046527184545993805,
-0.05058448389172554,
0.04098063334822655,
0.047222159802913666,
-0.03151411935687065,
-0.028928013518452644,
-0.047955289483070374,
0.012390964664518833,
0.0050150263123214245,
-0.05521407350897789,
-0.017785025760531425,
0.023763533681631088,
0.09583519399166107,
0.013116493821144104,
-0.04600660875439644,
0.066167913377285,
0.027368323877453804,
0.054809510707855225,
0.032785627990961075,
-0.11691604554653168,
0.07661381363868713,
0.04166504368185997,
-0.03598722070455551,
-0.02258722111582756,
0.0875859335064888,
-0.013460468500852585
] | 0.18038
|
can retrieve the assets using the [`sea.getAsset()`][] and [`sea.getAssetAsBlob()`][] APIs. ```json { "main": "/path/to/bundled/script.js", "output": "/path/to/write/the/generated/executable", "assets": { "a.jpg": "/path/to/a.jpg", "b.txt": "/path/to/b.txt" } } ``` The single-executable application can access the assets as follows: ```cjs const { getAsset, getAssetAsBlob, getRawAsset, getAssetKeys } = require('node:sea'); // Get all asset keys. const keys = getAssetKeys(); console.log(keys); // ['a.jpg', 'b.txt'] // Returns a copy of the data in an ArrayBuffer. const image = getAsset('a.jpg'); // Returns a string decoded from the asset as UTF8. const text = getAsset('b.txt', 'utf8'); // Returns a Blob containing the asset. const blob = getAssetAsBlob('a.jpg'); // Returns an ArrayBuffer containing the raw asset without copying. const raw = getRawAsset('a.jpg'); ``` See documentation of the [`sea.getAsset()`][], [`sea.getAssetAsBlob()`][], [`sea.getRawAsset()`][] and [`sea.getAssetKeys()`][] APIs for more information. ### Startup snapshot support The `useSnapshot` field can be used to enable startup snapshot support. In this case, the `main` script would not be executed when the final executable is launched. Instead, it would be run when the single executable application preparation blob is generated on the building machine. The generated preparation blob would then include a snapshot capturing the states initialized by the `main` script. The final executable, with the preparation blob injected, would deserialize the snapshot at run time. When `useSnapshot` is true, the main script must invoke the [`v8.startupSnapshot.setDeserializeMainFunction()`][] API to configure code that needs to be run when the final executable is launched by the users. The typical pattern for an application to use snapshot in a single executable application is: 1. At build time, on the building machine, the main script is run to initialize the heap to a state that's ready to take user input. The script should also configure a main function with [`v8.startupSnapshot.setDeserializeMainFunction()`][]. This function will be compiled and serialized into the snapshot, but not invoked at build time. 2. At run time, the main function will be run on top of the deserialized heap on the user machine to process user input and generate output. The general constraints of the startup snapshot scripts also apply to the main script when it's used to build snapshot for the single executable application, and the main script can use the [`v8.startupSnapshot` API][] to adapt to these constraints. See [documentation about startup snapshot support in Node.js][]. ### V8 code cache support When `useCodeCache` is set to `true` in the configuration, during the generation of the single executable preparation blob, Node.js will compile the `main` script to generate the V8 code cache. The generated code cache would be part of the preparation blob and get injected into the final executable. When the single executable application is launched, instead of compiling the `main` script from scratch, Node.js would use the code cache to speed up the compilation, then execute the script, which would improve the startup performance. \*\*Note:\*\* `import()` does not work when `useCodeCache` is `true`. ### Execution arguments The `execArgv` field can be used to specify Node.js-specific arguments that will be automatically applied when the single executable application starts. This allows application developers to configure Node.js runtime options without requiring end users to be aware of these flags. For example, the following configuration: ```json { "main": "/path/to/bundled/script.js", "output": "/path/to/write/the/generated/executable", "execArgv": ["--no-warnings", "--max-old-space-size=2048"] } ``` will instruct the SEA to be launched with the `--no-warnings` and `--max-old-space-size=2048` flags. In the scripts embedded in the executable, these flags can be accessed using the `process.execArgv` property: ```js // If the executable is launched with `sea user-arg1 user-arg2` console.log(process.execArgv); // Prints: ['--no-warnings', '--max-old-space-size=2048'] console.log(process.argv); // Prints ['/path/to/sea', 'path/to/sea', 'user-arg1', 'user-arg2'] ``` The user-provided arguments are in the `process.argv` array starting from index 2, similar to
|
https://github.com/nodejs/node/blob/main//doc/api/single-executable-applications.md
|
main
|
nodejs
|
[
-0.02464170940220356,
0.0519845113158226,
-0.0347602479159832,
0.00775425648316741,
-0.0075059873051941395,
-0.011922698467969894,
0.024438846856355667,
0.0977252945303917,
0.005816696677356958,
-0.039970580488443375,
-0.030396653339266777,
-0.03471456468105316,
-0.02804243005812168,
0.021271031349897385,
0.10195187479257584,
0.008286007679998875,
-0.007047271355986595,
0.032620370388031006,
-0.020831318572163582,
0.0013930900022387505,
-0.004749846179038286,
0.0010862970957532525,
0.06067522242665291,
-0.10318645089864731,
-0.009050952270627022,
-0.003634487511590123,
-0.03249872103333473,
-0.05190490186214447,
-0.02350056730210781,
0.02756979502737522,
0.07910624146461487,
-0.061976294964551926,
-0.07144369184970856,
0.02129056490957737,
0.04051005095243454,
0.164290651679039,
0.021126052364706993,
-0.10665445029735565,
-0.01236901804804802,
-0.02903650514781475,
0.06928792595863342,
0.14330056309700012,
-0.08847802877426147,
0.01681450940668583,
0.05632542818784714,
-0.0900091752409935,
-0.03727265074849129,
-0.009359760209918022,
-0.045282162725925446,
0.06067308783531189,
-0.05522111803293228,
-0.04111518710851669,
-0.023649124428629875,
0.024112461134791374,
-0.021512342616915703,
0.016344349831342697,
-0.07088819146156311,
0.09309201687574387,
0.04325626417994499,
0.0858037993311882,
0.006588651333004236,
-0.06067630648612976,
0.060021910816431046,
-0.025488752871751785,
0.08649030327796936,
0.031001200899481773,
0.053167808800935745,
0.01431002002209425,
-0.01077767089009285,
-0.11608011275529861,
0.013861184008419514,
-0.038106512278318405,
-0.004926440306007862,
-0.044772613793611526,
-0.06609885394573212,
-0.05614876374602318,
0.003560644341632724,
0.022997727617621422,
-0.06490021198987961,
-0.05515109375119209,
-0.07891909033060074,
-0.03765202313661575,
-0.007481465581804514,
0.07426919043064117,
-0.02872246317565441,
0.09957560896873474,
-0.05616268515586853,
0.03298301622271538,
-0.017709506675601006,
0.009602293372154236,
-0.03472927585244179,
-0.12047624588012695,
-0.013641622848808765,
0.0276560690253973,
0.06242188438773155,
0.01033023465424776,
-0.03212190791964531,
0.043043360114097595,
0.0025099951308220625,
-0.0007288104388862848,
-0.05597228556871414,
0.014555981382727623,
0.06149182468652725,
-0.009150522761046886,
0.042096830904483795,
0.010424448177218437,
0.023570189252495766,
0.007055497262626886,
-0.11412061750888824,
-0.021988585591316223,
-0.0866660624742508,
0.10081925243139267,
-0.0003557369054760784,
0.02512448839843273,
0.018991388380527496,
-0.011509942822158337,
-0.03510722890496254,
-0.07050683349370956,
0.03537585586309433,
0.03501150384545326,
0.0738927349448204,
-0.022345518693327904,
0.1206413209438324,
0.06958799064159393,
0.02088787406682968,
-0.04617922753095627,
0.007353323511779308,
-8.009003007297184e-34,
0.005762830376625061,
-0.04989614337682724,
0.15322186052799225,
0.04260381683707237,
-0.033658672124147415,
-0.0907934382557869,
0.052001141011714935,
0.028964905068278313,
-0.0895104929804802,
0.03488119691610336,
-0.08677840977907181,
0.15817220509052277,
-0.03766407445073128,
0.02795339934527874,
0.003939812537282705,
0.013628075830638409,
0.00835929624736309,
-0.04957639053463936,
0.1020851582288742,
0.015689002349972725,
-0.01469412725418806,
0.05763803794980049,
-0.009379060938954353,
0.04221655800938606,
-0.04791126027703285,
-0.05349127948284149,
0.014728007838129997,
0.04320547357201576,
-0.006179027259349823,
0.015436172485351562,
0.032707877457141876,
0.06662266701459885,
-0.007087680045515299,
-0.03597618266940117,
0.052881449460983276,
-0.049430638551712036,
0.0019834525883197784,
0.08449520915746689,
-0.14933839440345764,
0.05109363794326782,
0.06845399737358093,
-0.0024851555936038494,
-0.03592577576637268,
0.014438695274293423,
-0.0909995511174202,
-0.02530314400792122,
-0.0570513978600502,
-0.03896328806877136,
0.03637189790606499,
-0.011206117458641529,
-0.011470377445220947,
0.06361998617649078,
0.031013544648885727,
0.0162334144115448,
0.07475917041301727,
0.0037753782235085964,
0.016632573679089546,
-0.048836175352334976,
-0.047722458839416504,
-0.004336236044764519,
0.01710982620716095,
0.028931986540555954,
0.011642932891845703,
0.02960914559662342,
-0.05859120190143585,
0.054729677736759186,
-0.011420710012316704,
0.00980403646826744,
-0.0236954428255558,
-0.025028837844729424,
-0.03374334052205086,
0.03207514062523842,
0.08485065400600433,
-0.07013330608606339,
0.0676974281668663,
0.028309646993875504,
-0.04870664328336716,
0.02356215938925743,
-0.06398817896842957,
-0.030789431184530258,
0.007311726920306683,
0.0026668389327824116,
0.004007719922810793,
0.038777608424425125,
-0.04807048663496971,
0.098731629550457,
0.00011652631656033918,
-0.09228669106960297,
0.05395850911736488,
-0.00040039076702669263,
0.007384311407804489,
-0.026153337210416794,
-0.013915129005908966,
-0.11816851794719696,
-0.02281702682375908,
-2.239802364420141e-33,
0.12242970615625381,
-0.011313059367239475,
-0.03560643270611763,
-0.02908775396645069,
0.014369452372193336,
-0.024018997326493263,
0.05282677710056305,
0.027055785059928894,
-0.04060249775648117,
0.03448154032230377,
-0.0669817104935646,
0.03144070878624916,
-0.001661935937590897,
-0.03723302483558655,
-0.01591506227850914,
0.03663509339094162,
0.037867676466703415,
-0.0573723204433918,
0.06119973957538605,
-0.06563545763492584,
-0.051949094980955124,
-0.008176272734999657,
0.15140850841999054,
0.014106571674346924,
-0.03856528177857399,
0.05233798176050186,
-0.04425765946507454,
-0.0029035345651209354,
-0.11039705574512482,
-0.06638170778751373,
-0.08000379055738449,
0.019330346956849098,
-0.008103102445602417,
-0.004610457923263311,
-0.010860225185751915,
-0.038156040012836456,
-0.0617511160671711,
0.04249473288655281,
0.012815681286156178,
-0.01993914507329464,
-0.028634294867515564,
-0.07531895488500595,
-0.018389329314231873,
-0.016656819730997086,
0.0331810899078846,
0.014333982020616531,
-0.012582332827150822,
0.0526391826570034,
-0.0050215632654726505,
-0.03277032822370529,
0.052231792360544205,
0.009088209830224514,
-0.011305484920740128,
-0.008560453541576862,
0.08771882951259613,
0.009028082713484764,
0.05766279995441437,
-0.05547603219747543,
0.03885817900300026,
0.05363975092768669,
0.048144590109586716,
-0.11165815591812134,
-0.007648890372365713,
0.002336402889341116,
-0.032708972692489624,
-0.08514364063739777,
-0.04223060607910156,
-0.07624590396881104,
-0.01813252456486225,
0.019690001383423805,
-0.0286685973405838,
-0.04860415682196617,
0.05675341188907623,
0.05541794002056122,
0.033203866332769394,
0.005429137032479048,
-0.08455924689769745,
-0.0789492055773735,
0.01165725663304329,
0.000658477540127933,
0.014125888235867023,
0.08181474357843399,
-0.04559449478983879,
0.04512554407119751,
0.07736290246248245,
-0.01964479871094227,
-0.04259385168552399,
-0.15194930136203766,
0.036260802298784256,
-0.07700534164905548,
-0.022248951718211174,
0.023566557094454765,
-0.04720482602715492,
-0.030656227841973305,
0.015494002029299736,
-5.214309695134034e-8,
0.024973008781671524,
-0.0024830149486660957,
-0.07542446255683899,
0.04150523617863655,
-0.04873346909880638,
-0.050079964101314545,
-0.04327495023608208,
0.028875209391117096,
0.07166438549757004,
-0.014979296363890171,
0.041890569031238556,
-0.06332932412624359,
-0.01000955980271101,
-0.008448345586657524,
-0.09852424263954163,
-0.02522716298699379,
0.08363160490989685,
0.0031417235732078552,
0.012075820937752724,
-0.04115046188235283,
-0.01123772282153368,
-0.005569817963987589,
0.05164525285363197,
0.02718508243560791,
0.00874309241771698,
-0.004291747231036425,
-0.006373488809913397,
-0.019300024956464767,
0.002348644658923149,
-0.002706683473661542,
-0.05196725204586983,
-0.023676486685872078,
0.08605699986219406,
0.0690683051943779,
-0.00594032509252429,
-0.04138313978910446,
-0.010104556567966938,
0.005330376327037811,
-0.0033054377418011427,
0.04752200469374657,
-0.012349273078143597,
0.0002876866783481091,
-0.010946361348032951,
0.02888692356646061,
0.013906019739806652,
0.017733702436089516,
0.003722300985828042,
0.07607301324605942,
0.025625737383961678,
0.04355159029364586,
0.062046363949775696,
-0.03596489503979683,
-0.056493353098630905,
0.07870589196681976,
-0.027805931866168976,
-0.030786652117967606,
-0.02083510346710682,
-0.0638158842921257,
-0.006189906038343906,
0.04570554941892624,
-0.00561367254704237,
-0.013321269303560257,
-0.03352551534771919,
0.005715488456189632
] | -0.010369
|
in the executable, these flags can be accessed using the `process.execArgv` property: ```js // If the executable is launched with `sea user-arg1 user-arg2` console.log(process.execArgv); // Prints: ['--no-warnings', '--max-old-space-size=2048'] console.log(process.argv); // Prints ['/path/to/sea', 'path/to/sea', 'user-arg1', 'user-arg2'] ``` The user-provided arguments are in the `process.argv` array starting from index 2, similar to what would happen if the application is started with: ```console node --no-warnings --max-old-space-size=2048 /path/to/bundled/script.js user-arg1 user-arg2 ``` ### Execution argument extension The `execArgvExtension` field controls how additional execution arguments can be provided beyond those specified in the `execArgv` field. It accepts one of three string values: \* `"none"`: No extension is allowed. Only the arguments specified in `execArgv` will be used, and the `NODE\_OPTIONS` environment variable will be ignored. \* `"env"`: \_(Default)\_ The `NODE\_OPTIONS` environment variable can extend the execution arguments. This is the default behavior to maintain backward compatibility. \* `"cli"`: The executable can be launched with `--node-options="--flag1 --flag2"`, and those flags will be parsed as execution arguments for Node.js instead of being passed to the user script. This allows using arguments that are not supported by the `NODE\_OPTIONS` environment variable. For example, with `"execArgvExtension": "cli"`: ```json { "main": "/path/to/bundled/script.js", "output": "/path/to/write/the/generated/executable", "execArgv": ["--no-warnings"], "execArgvExtension": "cli" } ``` The executable can be launched as: ```console ./my-sea --node-options="--trace-exit" user-arg1 user-arg2 ``` This would be equivalent to running: ```console node --no-warnings --trace-exit /path/to/bundled/script.js user-arg1 user-arg2 ``` ## In the injected main script ### Single-executable application API The `node:sea` builtin allows interaction with the single-executable application from the JavaScript main script embedded into the executable. #### `sea.isSea()` \* Returns: {boolean} Whether this script is running inside a single-executable application. ### `sea.getAsset(key[, encoding])` This method can be used to retrieve the assets configured to be bundled into the single-executable application at build time. An error is thrown when no matching asset can be found. \* `key` {string} the key for the asset in the dictionary specified by the `assets` field in the single-executable application configuration. \* `encoding` {string} If specified, the asset will be decoded as a string. Any encoding supported by the `TextDecoder` is accepted. If unspecified, an `ArrayBuffer` containing a copy of the asset would be returned instead. \* Returns: {string|ArrayBuffer} ### `sea.getAssetAsBlob(key[, options])` Similar to [`sea.getAsset()`][], but returns the result in a {Blob}. An error is thrown when no matching asset can be found. \* `key` {string} the key for the asset in the dictionary specified by the `assets` field in the single-executable application configuration. \* `options` {Object} \* `type` {string} An optional mime type for the blob. \* Returns: {Blob} ### `sea.getRawAsset(key)` This method can be used to retrieve the assets configured to be bundled into the single-executable application at build time. An error is thrown when no matching asset can be found. Unlike `sea.getAsset()` or `sea.getAssetAsBlob()`, this method does not return a copy. Instead, it returns the raw asset bundled inside the executable. For now, users should avoid writing to the returned array buffer. If the injected section is not marked as writable or not aligned properly, writes to the returned array buffer is likely to result in a crash. \* `key` {string} the key for the asset in the dictionary specified by the `assets` field in the single-executable application configuration. \* Returns: {ArrayBuffer} ### `sea.getAssetKeys()` \* Returns {string\[]} An array containing all the keys of the assets embedded in the executable. If no assets are embedded, returns an empty array. This method can be used to retrieve an array of all the keys of assets embedded into the single-executable application. An error is thrown when not running inside a single-executable application. ### `require(id)` in the injected main
|
https://github.com/nodejs/node/blob/main//doc/api/single-executable-applications.md
|
main
|
nodejs
|
[
0.0014001949457451701,
0.019482417032122612,
-0.10886354744434357,
0.010414307937026024,
0.04586004093289375,
-0.06914077699184418,
0.054919589310884476,
0.10191228985786438,
0.016038678586483,
-0.022009870037436485,
-0.0047538564540445805,
0.008289591409265995,
-0.028319669887423515,
0.0012402791762724519,
0.04156576469540596,
0.022149713709950447,
-0.0520034059882164,
-0.029578007757663727,
-0.013521973043680191,
-0.04794696345925331,
0.10123424977064133,
-0.009933494962751865,
-0.013294866308569908,
-0.05745600536465645,
-0.10097698122262955,
-0.034222543239593506,
-0.06423525512218475,
0.008279032073915005,
-0.018885090947151184,
-0.014006482437252998,
0.0771392434835434,
0.0077368952333927155,
-0.017094697803258896,
0.009105652570724487,
0.048211995512247086,
0.16462910175323486,
0.010986789129674435,
-0.05258006229996681,
-0.08034994453191757,
-0.021018218249082565,
0.017941312864422798,
0.08690574020147324,
-0.10802383720874786,
0.03624991327524185,
-0.024691550061106682,
-0.062417834997177124,
-0.09572209417819977,
-0.03607254475355148,
-0.10863068699836731,
0.020472252741456032,
0.0032126836013048887,
-0.00579292606562376,
-0.00614650035277009,
-0.02826310321688652,
0.004041863139718771,
-0.01684246025979519,
-0.09261810034513474,
0.027565808966755867,
0.018132410943508148,
0.04905211552977562,
-0.021779391914606094,
0.01476595550775528,
-0.02767704240977764,
-0.0012057117419317365,
0.023982752114534378,
-0.01723671518266201,
0.06276791542768478,
-0.02405976690351963,
-0.02068432979285717,
0.04622689634561539,
-0.04340162128210068,
0.017254602164030075,
-0.12078452110290527,
-0.02318604104220867,
-0.08530386537313461,
-0.002738856477662921,
-0.045213330537080765,
0.010370677337050438,
-0.08337835222482681,
-0.0891285166144371,
-0.02504526823759079,
-0.03579176962375641,
-0.03667917475104332,
0.009815760888159275,
-0.01948152296245098,
0.13246746361255646,
-0.04022742062807083,
-0.04345441982150078,
0.11510539054870605,
0.10287344455718994,
0.020830903202295303,
-0.12982407212257385,
-0.047977421432733536,
0.06914342939853668,
0.09914392232894897,
0.052106305956840515,
-0.07429062575101852,
0.03682112693786621,
-0.04301005229353905,
0.028379617258906364,
-0.01670300029218197,
0.011855769902467728,
0.04271957650780678,
-0.014708535745739937,
0.12452381104230881,
-0.03242047503590584,
-0.00817346852272749,
-0.01670694164931774,
-0.04994605854153633,
-0.008661753498017788,
-0.031757865101099014,
0.06133918836712837,
0.06205398216843605,
0.018672633916139603,
0.03828328475356102,
0.1077103242278099,
0.08397658169269562,
-0.04820192605257034,
0.02991892211139202,
0.0688772201538086,
0.1323367804288864,
0.04854072630405426,
0.03035818785429001,
0.0561957061290741,
0.020044993609189987,
-0.024129562079906464,
0.07475871592760086,
1.4192978484900802e-33,
0.012079643085598946,
-0.07327967882156372,
0.049421779811382294,
0.048048097640275955,
-0.013915840536355972,
0.026187598705291748,
0.02210487797856331,
0.01870778761804104,
-0.056279800832271576,
0.09353999048471451,
-0.09247410297393799,
0.07859987020492554,
-0.01932300627231598,
-0.022505197674036026,
0.08189775049686432,
0.03816385194659233,
0.007792649324983358,
0.021685676649212837,
-0.004697924479842186,
-0.014461986720561981,
0.04112517833709717,
0.025231948122382164,
-0.08043890446424484,
0.06063610687851906,
-0.02777157351374626,
-0.01218903437256813,
-0.004660363774746656,
-0.010436763055622578,
0.0015400283737108111,
0.010326958261430264,
0.028109073638916016,
0.028557848185300827,
-0.07986439019441605,
0.08795717358589172,
0.04021456092596054,
-0.009399333968758583,
-0.0068989647552371025,
0.027623729780316353,
-0.05172444507479668,
-0.01604551635682583,
0.07660045474767685,
0.008379623293876648,
-0.018634257838129997,
0.049993470311164856,
-0.07123735547065735,
-0.1401883363723755,
-0.03690781816840172,
-0.02163984254002571,
0.05441857874393463,
0.07514937967061996,
0.046970490366220474,
0.08104975521564484,
0.09142880886793137,
-0.025414660573005676,
0.02396697737276554,
-0.004838387947529554,
0.0038090278394520283,
-0.03886060044169426,
-0.03587130084633827,
0.033835187554359436,
-0.0033700575586408377,
0.013738417066633701,
0.010793962515890598,
0.041814014315605164,
0.0006964695639908314,
0.004769445862621069,
0.02883298695087433,
-0.042800042778253555,
0.014984958805143833,
0.04315949231386185,
-0.08905921876430511,
-0.019776437431573868,
0.09587790817022324,
0.008487047627568245,
0.04062953218817711,
-0.05520740896463394,
-0.05794356018304825,
0.00819102767854929,
-0.053812190890312195,
-0.0812462866306305,
-0.01579780876636505,
-0.009342720732092857,
-0.044923245906829834,
0.0779598131775856,
0.02020714059472084,
-0.00561454938724637,
-0.06161143258213997,
-0.00086446717614308,
-0.008934917859733105,
-0.014791970141232014,
0.04165985435247421,
-0.028027476742863655,
-0.06585212051868439,
-0.06571796536445618,
-0.019664963707327843,
-4.3802798642996146e-33,
0.05839477479457855,
-0.010676780715584755,
-0.057817492634058,
0.016558943316340446,
-0.09943302720785141,
-0.010165732353925705,
-0.004584931768476963,
-0.014346701093018055,
-0.03211408108472824,
-0.021384717896580696,
-0.12308183312416077,
0.05147029832005501,
0.12162869423627853,
0.05231865122914314,
0.01647748239338398,
0.03729572147130966,
-0.08930891007184982,
0.003418689826503396,
0.07845501601696014,
-0.029428521171212196,
-0.006949681788682938,
0.0198135394603014,
0.07650283724069595,
0.04579697549343109,
-0.00239802454598248,
-0.03625350072979927,
0.03431955724954605,
-0.016774406656622887,
-0.01630239374935627,
-0.07327666133642197,
-0.04565766453742981,
0.026823094114661217,
-0.04615747556090355,
0.028222456574440002,
-0.046364713460206985,
-0.08523109555244446,
0.010281653143465519,
0.09224328398704529,
0.019253093749284744,
0.018237587064504623,
0.005985043477267027,
0.010457550175487995,
-0.003175870981067419,
0.01811487413942814,
-0.015567637048661709,
0.10836566984653473,
0.028659438714385033,
-0.045722153037786484,
-0.0005596696282736957,
-0.10898561775684357,
-0.027858056128025055,
0.019499342888593674,
0.04766390472650528,
0.05812469869852066,
0.032553888857364655,
-0.07830826938152313,
-0.026805507019162178,
-0.0568012073636055,
-0.020758794620633125,
0.06204354763031006,
0.09036625921726227,
-0.05061595141887665,
0.0019351468654349446,
-0.09544577449560165,
-0.03442268446087837,
-0.038274649530649185,
-0.08794068545103073,
-0.04052647203207016,
-0.034758061170578,
-0.00423290254548192,
0.047099724411964417,
-0.09074948728084564,
-0.047569576650857925,
-0.009344775229692459,
-0.0349387601017952,
-0.0084944823756814,
0.01335449330508709,
-0.14938051998615265,
0.016092337667942047,
-0.0016695511294528842,
-0.00750734843313694,
0.04928160831332207,
-0.03635093942284584,
0.008830374106764793,
-0.03504343330860138,
-0.016821473836898804,
-0.030230548232793808,
0.08395791798830032,
-0.01713370904326439,
0.0020915567874908447,
0.02299993485212326,
0.1032736524939537,
-0.06370246410369873,
-0.07306475937366486,
-0.059761893004179,
-5.229026101005729e-8,
-0.02364511229097843,
-0.019600288942456245,
-0.05133720487356186,
0.0016184647101908922,
0.009459363296627998,
0.003715408267453313,
-0.01593557931482792,
0.12667594850063324,
0.01028651837259531,
-0.015307959169149399,
0.051845062524080276,
0.04727683961391449,
0.021521056070923805,
-0.02626875601708889,
0.009312417358160019,
0.006099626421928406,
-0.0059455507434904575,
0.04091530293226242,
-0.03717341646552086,
0.02850184589624405,
-0.03226938471198082,
0.0494094155728817,
-0.054648663848638535,
0.013765028677880764,
0.015272364020347595,
-0.024855105206370354,
0.07968799769878387,
0.01303156092762947,
0.011701771058142185,
-0.0004479124036151916,
-0.004816962871700525,
0.027633368968963623,
0.06424669921398163,
0.02722860686480999,
-0.08679252862930298,
0.047332871705293655,
-0.05146890506148338,
0.029879961162805557,
0.04882768541574478,
0.00021422449208330363,
-0.050248172134160995,
0.021493377164006233,
-0.06008502468466759,
0.0020901616662740707,
-0.04323815181851387,
0.04106694832444191,
0.0005993549129925668,
-0.004154788795858622,
-0.02529236674308777,
-0.019088728353381157,
0.00879666954278946,
0.014412593096494675,
-0.017805129289627075,
0.0390193872153759,
-0.025817066431045532,
0.038591984659433365,
-0.011500518769025803,
-0.10239673405885696,
0.0410090833902359,
0.04543018341064453,
-0.04338415712118149,
0.019772278144955635,
-0.00277761765755713,
0.038408681750297546
] | 0.124855
|
embedded in the executable. If no assets are embedded, returns an empty array. This method can be used to retrieve an array of all the keys of assets embedded into the single-executable application. An error is thrown when not running inside a single-executable application. ### `require(id)` in the injected main script is not file based `require()` in the injected main script is not the same as the [`require()`][] available to modules that are not injected. It also does not have any of the properties that non-injected [`require()`][] has except [`require.main`][]. It can only be used to load built-in modules. Attempting to load a module that can only be found in the file system will throw an error. Instead of relying on a file based `require()`, users can bundle their application into a standalone JavaScript file to inject into the executable. This also ensures a more deterministic dependency graph. However, if a file based `require()` is still needed, that can also be achieved: ```js const { createRequire } = require('node:module'); require = createRequire(\_\_filename); ``` ### `\_\_filename` and `module.filename` in the injected main script The values of `\_\_filename` and `module.filename` in the injected main script are equal to [`process.execPath`][]. ### `\_\_dirname` in the injected main script The value of `\_\_dirname` in the injected main script is equal to the directory name of [`process.execPath`][]. ### Using native addons in the injected main script Native addons can be bundled as assets into the single-executable application by specifying them in the `assets` field of the configuration file used to generate the single-executable application preparation blob. The addon can then be loaded in the injected main script by writing the asset to a temporary file and loading it with `process.dlopen()`. ```json { "main": "/path/to/bundled/script.js", "output": "/path/to/write/the/generated/executable", "assets": { "myaddon.node": "/path/to/myaddon/build/Release/myaddon.node" } } ``` ```js // script.js const fs = require('node:fs'); const os = require('node:os'); const path = require('node:path'); const { getRawAsset } = require('node:sea'); const addonPath = path.join(os.tmpdir(), 'myaddon.node'); fs.writeFileSync(addonPath, new Uint8Array(getRawAsset('myaddon.node'))); const myaddon = { exports: {} }; process.dlopen(myaddon, addonPath); console.log(myaddon.exports); fs.rmSync(addonPath); ``` Known caveat: if the single-executable application is produced by postject running on a Linux arm64 docker container, [the produced ELF binary does not have the correct hash table to load the addons][postject-linux-arm64-issue] and will crash on `process.dlopen()`. Build the single-executable application on other platforms, or at least on a non-container Linux arm64 environment to work around this issue. ## Notes ### Single executable application creation process The process documented here is subject to change. #### 1. Generating single executable preparation blobs To build a single executable application, Node.js would first generate a blob that contains all the necessary information to run the bundled script. When using `--build-sea`, this step is done internally along with the injection. ##### Dumping the preparation blob to disk Before `--build-sea` was introduced, an older workflow was introduced to write the preparation blob to disk for injection by external tools. This can still be used for verification purposes. To dump the preparation blob to disk for verification, use `--experimental-sea-config`. This writes a file that can be injected into a Node.js binary using tools like [postject][]. The configuration is similar to that of `--build-sea`, except that the `output` field specifies the path to write the generated blob file instead of the final executable. ```json { "main": "/path/to/bundled/script.js", // Instead of the final executable, this is the path to write the blob. "output": "/path/to/write/the/generated/blob.blob" } ``` #### 2. Injecting the preparation blob into the `node` binary To complete the creation of a single executable application, the generated blob needs to be injected into a copy of the `node` binary, as
|
https://github.com/nodejs/node/blob/main//doc/api/single-executable-applications.md
|
main
|
nodejs
|
[
-0.044119250029325485,
0.029898542910814285,
-0.03468972444534302,
0.051304157823324203,
0.07926993072032928,
-0.08161932975053787,
0.024539370089769363,
0.07295795530080795,
0.03496992215514183,
-0.07338421791791916,
0.039943236857652664,
0.05718759074807167,
0.0721999853849411,
-0.016074499115347862,
0.03625110909342766,
0.0402328185737133,
0.052855901420116425,
-0.07704977691173553,
-0.01366728637367487,
0.03247901797294617,
0.009624597616493702,
0.001822638907469809,
0.023998109623789787,
-0.05603959783911705,
-0.04393485188484192,
-0.016692345961928368,
-0.0535820871591568,
-0.015728270635008812,
0.026771411299705505,
-0.010325554758310318,
0.0561906099319458,
0.026445919647812843,
-0.05333898216485977,
-0.023089760914444923,
-0.05393799766898155,
0.1099454015493393,
0.015782294794917107,
-0.07133650779724121,
-0.052477456629276276,
-0.037651676684617996,
0.012934353202581406,
0.10222922265529633,
-0.0591382160782814,
0.034460246562957764,
0.026544732972979546,
-0.04793637618422508,
-0.07906550914049149,
-0.027821969240903854,
-0.09822750836610794,
-0.00863789115101099,
-0.05227997899055481,
-0.011968851089477539,
0.015674060210585594,
0.013475842773914337,
-0.03412807360291481,
-0.04990621656179428,
-0.025342166423797607,
0.004862928297370672,
0.0382368266582489,
0.11696501821279526,
-0.0296076200902462,
0.07258513569831848,
0.0407894067466259,
0.019318385049700737,
0.08221236616373062,
0.006259647198021412,
0.02115870825946331,
-0.06520208716392517,
0.013843449763953686,
-0.04556926339864731,
-0.01078571006655693,
-0.003650011494755745,
-0.03474651277065277,
-0.010539312846958637,
-0.06451316922903061,
-0.06694645434617996,
-0.025039050728082657,
0.03778742253780365,
0.03223133087158203,
-0.10569267719984055,
-0.018952203914523125,
-0.020384768024086952,
0.00894720759242773,
0.03778361529111862,
0.052804410457611084,
0.08129094541072845,
0.02865869738161564,
0.0008122564177028835,
0.02719915844500065,
0.0270664282143116,
0.00035978941014036536,
-0.08959613740444183,
-0.03603662922978401,
0.0921267569065094,
0.12687885761260986,
-0.01028885692358017,
0.00504667405039072,
0.012762237340211868,
-0.09727362543344498,
0.03640462085604668,
-0.06216629222035408,
-0.014376546256244183,
0.07072832435369492,
0.007984264753758907,
0.0009477819548919797,
-0.012007496319711208,
-0.021779116243124008,
-0.060150496661663055,
-0.06825057417154312,
-0.015481900423765182,
-0.03089354932308197,
-0.0023681416641920805,
0.058376114815473557,
-0.059845712035894394,
-0.029385613277554512,
-0.009062401950359344,
0.11043193191289902,
-0.07392135262489319,
0.06170979514718056,
0.1056550145149231,
0.01443566009402275,
0.02724529430270195,
0.09144967049360275,
-0.007230620365589857,
0.06295518577098846,
-0.038377128541469574,
0.0172661691904068,
3.589143513521414e-33,
-0.01300502847880125,
-0.07812820374965668,
0.0016038772882893682,
0.10942428559064865,
-0.06354444473981857,
-0.046858303248882294,
0.046191636472940445,
0.06093284487724304,
-0.08964969217777252,
0.024889403954148293,
-0.03820597752928734,
0.13312704861164093,
0.017795898020267487,
0.1160065308213234,
0.06594450771808624,
0.029989786446094513,
0.04344899579882622,
-0.011847108602523804,
0.11787693947553635,
-0.015668272972106934,
-0.06442801654338837,
0.05233727768063545,
-0.05333699285984039,
0.02136881835758686,
0.009660817682743073,
0.07252160459756851,
0.010387405753135681,
0.032956257462501526,
-0.035020310431718826,
0.011456949636340141,
0.02616572380065918,
0.04264984652400017,
-0.050781942903995514,
-0.007168845739215612,
0.04590337723493576,
-0.02803332731127739,
-0.019158676266670227,
0.021794676780700684,
-0.12163525074720383,
-0.03477736935019493,
0.07674195617437363,
0.06619218736886978,
-0.0352884940803051,
-0.0014420109800994396,
-0.024409731850028038,
-0.10227173566818237,
-0.025243012234568596,
0.014157645404338837,
0.02380768209695816,
0.001108675030991435,
-0.018612448126077652,
0.09694134443998337,
0.07753795385360718,
0.01345991250127554,
0.02265247143805027,
-0.01721940189599991,
-0.016646314412355423,
-0.05154656246304512,
0.04146163538098335,
-0.028629589825868607,
-0.02344328537583351,
-0.04726039990782738,
-0.07082168757915497,
0.13095030188560486,
0.005823107901960611,
0.02100902423262596,
-0.02034885063767433,
-0.006647525355219841,
-0.03954578563570976,
0.049382057040929794,
0.0069765355437994,
-0.023973185569047928,
-0.006727476604282856,
-0.0038804097566753626,
0.03320778161287308,
-0.020974023267626762,
-0.05223851278424263,
-0.041118647903203964,
-0.055463094264268875,
0.006967714987695217,
0.04722758010029793,
-0.010582123883068562,
-0.018379610031843185,
0.023530567064881325,
-0.04729130119085312,
0.015001509338617325,
-0.00481585506349802,
-0.03750051185488701,
0.04507819190621376,
-0.015124437399208546,
0.0874633863568306,
-0.03967590257525444,
-0.10687863081693649,
-0.08602433651685715,
0.013834669254720211,
-4.548138988229099e-33,
0.06715521216392517,
0.040947627276182175,
-0.0222804956138134,
0.038130179047584534,
0.03375355526804924,
-0.010219504125416279,
0.007518835831433535,
-0.03315746411681175,
0.0458800233900547,
0.03467079624533653,
-0.05998581275343895,
-0.012031027115881443,
0.08104883879423141,
-0.011290029622614384,
0.004443428013473749,
0.08601870387792587,
-0.17827582359313965,
-0.06571293622255325,
0.02358568273484707,
-0.02356380596756935,
0.024304475635290146,
0.065221406519413,
0.1416184902191162,
-0.018729083240032196,
0.020197181031107903,
0.053226079791784286,
-0.11884868144989014,
0.06532855331897736,
-0.09558654576539993,
-0.03131040930747986,
-0.05497776344418526,
-0.003710106946527958,
-0.06386847794055939,
-0.0030690289568156004,
-0.08228699862957001,
-0.023856382817029953,
-0.025517569854855537,
0.06920943409204483,
-0.03333408758044243,
-0.09035620093345642,
0.013215095736086369,
0.05080440267920494,
-0.05322198569774628,
0.05259745940566063,
-0.023256907239556313,
-0.04922132194042206,
0.00489157997071743,
0.01227816753089428,
0.07374268770217896,
-0.10343658924102783,
-0.04928460344672203,
-0.01661265268921852,
0.031061632558703423,
0.019389446824789047,
0.02348978817462921,
-0.06373831629753113,
0.04572499170899391,
0.05376555025577545,
0.0344376266002655,
0.053779274225234985,
0.07938171923160553,
-0.0667617991566658,
0.0020763184875249863,
-0.06981747597455978,
-0.066398024559021,
-0.06394748389720917,
-0.02221991866827011,
-0.015803907066583633,
0.041480179876089096,
-0.0002536194515414536,
0.004922732710838318,
-0.007239740341901779,
0.07331953197717667,
-0.027135901153087616,
-0.03326621279120445,
0.12058409303426743,
0.03532187640666962,
-0.05666501075029373,
-0.00990005861967802,
-0.030635859817266464,
0.03314884379506111,
-0.00899357721209526,
-0.030107613652944565,
-0.009075667709112167,
0.004969755653291941,
-0.0036602639593183994,
-0.019790714606642723,
-0.08499117940664291,
-0.0000688962172716856,
-0.005439251195639372,
0.014022334478795528,
0.057000741362571716,
-0.0271824449300766,
0.029355786740779877,
0.02002754993736744,
-5.7659221397443616e-8,
0.01364692859351635,
0.025066116824746132,
-0.07077503949403763,
-0.08615600317716599,
-0.017939195036888123,
-0.042784906923770905,
0.043400902301073074,
-0.0016113067977130413,
0.010906512849032879,
0.02159726619720459,
0.09461990743875504,
0.020216945558786392,
-0.0011772168800234795,
0.03875618800520897,
-0.07353188842535019,
0.06747445464134216,
0.009584645740687847,
-0.008875261060893536,
-0.0612156055867672,
-0.029103005304932594,
-0.015509274788200855,
0.02329314686357975,
0.013563324697315693,
0.05690022557973862,
0.007431732956320047,
-0.011765487492084503,
0.02951253578066826,
-0.02617868036031723,
-0.01787039078772068,
0.0455840602517128,
-0.09482413530349731,
0.03365156054496765,
0.06323841214179993,
-0.03900645673274994,
-0.10430349409580231,
0.10381504893302917,
0.0071357800625264645,
0.011473131366074085,
-0.02857610397040844,
-0.07311465591192245,
0.0011653646361082792,
-0.013791355304419994,
-0.03669821098446846,
-0.03783488646149635,
-0.03500626981258392,
-0.0009132369887083769,
-0.09686918556690216,
0.0024191548582166433,
-0.047261759638786316,
0.03572018817067146,
0.011058575473725796,
-0.039911992847919464,
-0.05512774735689163,
0.04553121328353882,
-0.019260674715042114,
0.002090748865157366,
0.029289739206433296,
-0.0041529037989676,
0.028640493750572205,
-0.04981322959065437,
0.003822151804342866,
-0.0022412172984331846,
0.09993471205234528,
-0.03853008896112442
] | 0.14891
|
of the final executable, this is the path to write the blob. "output": "/path/to/write/the/generated/blob.blob" } ``` #### 2. Injecting the preparation blob into the `node` binary To complete the creation of a single executable application, the generated blob needs to be injected into a copy of the `node` binary, as documented below. When using `--build-sea`, this step is done internally along with the blob generation. \* If the `node` binary is a [PE][] file, the blob should be injected as a resource named `NODE\_SEA\_BLOB`. \* If the `node` binary is a [Mach-O][] file, the blob should be injected as a section named `NODE\_SEA\_BLOB` in the `NODE\_SEA` segment. \* If the `node` binary is an [ELF][] file, the blob should be injected as a note named `NODE\_SEA\_BLOB`. Then, the SEA building process searches the binary for the `NODE\_SEA\_FUSE\_fce680ab2cc467b6e072b8b5df1996b2:0` [fuse][] string and flip the last character to `1` to indicate that a resource has been injected. ##### Injecting the preparation blob manually Before `--build-sea` was introduced, an older workflow was introduced to allow external tools to inject the generated blob into a copy of the `node` binary. For example, with [postject][]: 1. Create a copy of the `node` executable and name it according to your needs: \* On systems other than Windows: ```bash cp $(command -v node) hello ``` \* On Windows: ```text node -e "require('fs').copyFileSync(process.execPath, 'hello.exe')" ``` The `.exe` extension is necessary. 2. Remove the signature of the binary (macOS and Windows only): \* On macOS: ```bash codesign --remove-signature hello ``` \* On Windows (optional): [signtool][] can be used from the installed [Windows SDK][]. If this step is skipped, ignore any signature-related warning from postject. ```powershell signtool remove /s hello.exe ``` 3. Inject the blob into the copied binary by running `postject` with the following options: \* `hello` / `hello.exe` - The name of the copy of the `node` executable created in step 4. \* `NODE\_SEA\_BLOB` - The name of the resource / note / section in the binary where the contents of the blob will be stored. \* `sea-prep.blob` - The name of the blob created in step 1. \* `--sentinel-fuse NODE\_SEA\_FUSE\_fce680ab2cc467b6e072b8b5df1996b2` - The [fuse][] used by the Node.js project to detect if a file has been injected. \* `--macho-segment-name NODE\_SEA` (only needed on macOS) - The name of the segment in the binary where the contents of the blob will be stored. To summarize, here is the required command for each platform: \* On Linux: ```bash npx postject hello NODE\_SEA\_BLOB sea-prep.blob \ --sentinel-fuse NODE\_SEA\_FUSE\_fce680ab2cc467b6e072b8b5df1996b2 ``` \* On Windows - PowerShell: ```powershell npx postject hello.exe NODE\_SEA\_BLOB sea-prep.blob ` --sentinel-fuse NODE\_SEA\_FUSE\_fce680ab2cc467b6e072b8b5df1996b2 ``` \* On Windows - Command Prompt: ```text npx postject hello.exe NODE\_SEA\_BLOB sea-prep.blob ^ --sentinel-fuse NODE\_SEA\_FUSE\_fce680ab2cc467b6e072b8b5df1996b2 ``` \* On macOS: ```bash npx postject hello NODE\_SEA\_BLOB sea-prep.blob \ --sentinel-fuse NODE\_SEA\_FUSE\_fce680ab2cc467b6e072b8b5df1996b2 \ --macho-segment-name NODE\_SEA ``` ### Platform support Single-executable support is tested regularly on CI only on the following platforms: \* Windows \* macOS \* Linux (all distributions [supported by Node.js][] except Alpine and all architectures [supported by Node.js][] except s390x) This is due to a lack of better tools to generate single-executables that can be used to test this feature on other platforms. Suggestions for other resource injection tools/workflows are welcomed. Please start a discussion at to help us document them. [CommonJS]: modules.md#modules-commonjs-modules [ELF]: https://en.wikipedia.org/wiki/Executable\_and\_Linkable\_Format [Generating single executable preparation blobs]: #1-generating-single-executable-preparation-blobs [Mach-O]: https://en.wikipedia.org/wiki/Mach-O [PE]: https://en.wikipedia.org/wiki/Portable\_Executable [Windows SDK]: https://developer.microsoft.com/en-us/windows/downloads/windows-sdk/ [`process.execPath`]: process.md#processexecpath [`require()`]: modules.md#requireid [`require.main`]: modules.md#accessing-the-main-module [`sea.getAsset()`]: #seagetassetkey-encoding [`sea.getAssetAsBlob()`]: #seagetassetasblobkey-options [`sea.getAssetKeys()`]: #seagetassetkeys [`sea.getRawAsset()`]: #seagetrawassetkey [`v8.startupSnapshot.setDeserializeMainFunction()`]: v8.md#v8startupsnapshotsetdeserializemainfunctioncallback-data [`v8.startupSnapshot` API]: v8.md#startup-snapshot-api [documentation about startup snapshot support in Node.js]: cli.md#--build-snapshot [fuse]: https://www.electronjs.org/docs/latest/tutorial/fuses [postject]: https://github.com/nodejs/postject [postject-linux-arm64-issue]: https://github.com/nodejs/postject/issues/105 [signtool]: https://learn.microsoft.com/en-us/windows/win32/seccrypto/signtool [single executable applications]: https://github.com/nodejs/single-executable [supported by Node.js]: https://github.com/nodejs/node/blob/main/BUILDING.md#platform-list
|
https://github.com/nodejs/node/blob/main//doc/api/single-executable-applications.md
|
main
|
nodejs
|
[
-0.020672954618930817,
0.043144822120666504,
-0.009649710729718208,
0.0010595211060717702,
-0.012902049347758293,
-0.08073132485151291,
0.02864057384431362,
-0.01507060881704092,
-0.05988352373242378,
-0.00981304980814457,
0.001063599600456655,
-0.11739849299192429,
0.016942696645855904,
-0.054925158619880676,
0.03684990108013153,
0.05305829271674156,
-0.04955989494919777,
-0.0004150116292294115,
0.010756268166005611,
-0.00006625263631576672,
0.019775375723838806,
0.08568472415208817,
0.008924509398639202,
0.03358420729637146,
-0.021002769470214844,
-0.019368495792150497,
-0.018068023025989532,
-0.02883925288915634,
0.03288838267326355,
-0.01287110336124897,
0.040747929364442825,
0.08354704082012177,
0.11423563957214355,
0.009262165986001492,
0.08238879591226578,
0.14909064769744873,
0.03847777470946312,
-0.07871393859386444,
-0.13582190871238708,
0.006140296813100576,
0.019689049571752548,
0.014532002620398998,
-0.01780598610639572,
0.050193410366773605,
-0.056333400309085846,
0.021438058465719223,
0.018877865746617317,
0.018956705927848816,
-0.08410509675741196,
-0.040188610553741455,
-0.03990158811211586,
-0.14143559336662292,
-0.063718780875206,
0.011244600638747215,
0.013993006199598312,
0.02153453417122364,
-0.05832778662443161,
0.05465616285800934,
0.05502382665872574,
0.02894238941371441,
0.022107839584350586,
0.08128921687602997,
-0.003745967522263527,
-0.04024893417954445,
0.0700472891330719,
-0.009339378215372562,
0.011989916674792767,
-0.06276427954435349,
-0.02341783419251442,
-0.007169658318161964,
0.05120719224214554,
-0.03522319719195366,
-0.07359839230775833,
0.03829541429877281,
-0.044340964406728745,
0.058326929807662964,
0.019479569047689438,
0.04669826105237007,
-0.10015662759542465,
-0.07757795602083206,
-0.050986722111701965,
-0.03854900225996971,
-0.026493554934859276,
0.0011977151734754443,
-0.0012571752304211259,
0.05552385747432709,
0.04870039224624634,
-0.06802758574485779,
0.002507205121219158,
0.036364369094371796,
0.021316006779670715,
-0.08020289987325668,
-0.049294233322143555,
0.008930202573537827,
0.05490037426352501,
0.04096543416380882,
-0.024207349866628647,
0.05926317349076271,
0.025708522647619247,
-0.003152526682242751,
-0.06754766404628754,
-0.03259872645139694,
0.004990162793546915,
-0.021256547421216965,
0.023717712610960007,
-0.034278370440006256,
-0.011147399432957172,
0.021015597507357597,
-0.022924693301320076,
-0.0012724888511002064,
-0.03194085881114006,
0.0250242967158556,
-0.010540510527789593,
-0.03175176680088043,
-0.015471774153411388,
0.08173626661300659,
-0.001168530434370041,
-0.021393032744526863,
-0.014086107723414898,
0.0745568573474884,
0.01859164424240589,
-0.019156794995069504,
0.015460600145161152,
0.09091705828905106,
-0.06813044846057892,
-0.06384959816932678,
-0.01525234617292881,
6.157688026005874e-34,
0.07560226321220398,
-0.08603565394878387,
0.013387232087552547,
0.06456038355827332,
0.006370039656758308,
-0.05969011411070824,
0.06172315031290054,
-0.007919122464954853,
-0.09627341479063034,
0.017805984243750572,
-0.10768065601587296,
0.0305019523948431,
-0.04261351376771927,
0.13297288119792938,
0.029837138950824738,
-0.06848438084125519,
0.0004679617122747004,
-0.07371403276920319,
0.0016841781325638294,
0.012839751318097115,
0.09645779430866241,
0.07718347012996674,
-0.07530445605516434,
-0.032088566571474075,
-0.047645073384046555,
-0.010903539136052132,
0.05081461742520332,
-0.13196520507335663,
0.025609921663999557,
0.033130403608083725,
-0.049712736159563065,
-0.017315346747636795,
-0.007827994413673878,
0.020141638815402985,
-0.02974223904311657,
-0.034973543137311935,
-0.004553648643195629,
0.02026692032814026,
-0.1245884895324707,
0.022550631314516068,
0.08191875368356705,
0.05985617637634277,
-0.05018229782581329,
0.01402023620903492,
0.05234163999557495,
-0.05968599393963814,
-0.016043873503804207,
-0.051430635154247284,
0.06037825345993042,
-0.003164698136970401,
0.07902033627033234,
0.047924913465976715,
0.04820649325847626,
0.004324889741837978,
0.016357125714421272,
0.04137479141354561,
0.025456314906477928,
-0.05560818314552307,
-0.01601034589111805,
0.06789868324995041,
0.06285364925861359,
0.09661082923412323,
-0.008070018142461777,
0.08338850736618042,
0.017701661214232445,
0.06265642493963242,
0.06046978756785393,
0.0028363552410155535,
0.04897048696875572,
-0.004139214288443327,
-0.08963838219642639,
-0.0059055546298623085,
0.040371786803007126,
-0.018432188779115677,
-0.07268232852220535,
0.02701818197965622,
-0.053394000977277756,
-0.049877021461725235,
-0.05336417630314827,
-0.02039775624871254,
-0.02328079380095005,
0.04401565343141556,
-0.015789177268743515,
0.0031441969331353903,
-0.004408462438732386,
-0.0036504212766885757,
-0.023440653458237648,
-0.043733175843954086,
-0.009745435789227486,
-0.06862346827983856,
0.06900966167449951,
-0.0870571956038475,
-0.006068742834031582,
-0.09477003663778305,
-0.05252445861697197,
-3.513232292397218e-33,
0.056048955768346786,
-0.007529684342443943,
-0.06260019540786743,
0.02438189834356308,
-0.08516449481248856,
-0.05392882972955704,
0.031935010105371475,
-0.08301790803670883,
-0.022260405123233795,
0.06024450808763504,
-0.13493852317333221,
0.023596612736582756,
0.092735156416893,
-0.0844479501247406,
-0.02161123976111412,
-0.0817142203450203,
-0.012293967418372631,
-0.02715987153351307,
0.021100034937262535,
0.03095429576933384,
-0.011744915507733822,
0.0252500232309103,
0.1670284867286682,
0.023844001814723015,
0.04711081460118294,
-0.03814910724759102,
0.008458198979496956,
0.034846965223550797,
0.01796220801770687,
-0.05601324513554573,
-0.029621193185448647,
0.08463465422391891,
-0.01828293688595295,
-0.0450165793299675,
-0.07519955188035965,
0.028095170855522156,
-0.06917604058980942,
0.051807988435029984,
0.055377136915922165,
-0.059120021760463715,
0.02776130475103855,
-0.01446090079843998,
-0.07708484679460526,
-0.034660711884498596,
-0.04565338045358658,
0.07551582902669907,
0.019055670127272606,
0.04815809428691864,
0.022540314123034477,
-0.07976795732975006,
0.038766633719205856,
0.02781394124031067,
0.035027120262384415,
0.02959185466170311,
0.045535214245319366,
-0.029517408460378647,
0.0014351503923535347,
0.04677613824605942,
0.012767326086759567,
0.015465693548321724,
0.029053401201963425,
-0.07013437151908875,
0.047929756343364716,
-0.07471543550491333,
-0.0601339191198349,
0.006734937429428101,
-0.035784825682640076,
-0.02161656692624092,
-0.012024703435599804,
0.019744809716939926,
-0.009068833664059639,
0.002993061440065503,
-0.012835383415222168,
0.032003775238990784,
-0.07482130825519562,
-0.0045149861834943295,
-0.06678126007318497,
-0.017074327915906906,
-0.04248681664466858,
0.0482800230383873,
-0.061849161982536316,
0.1381494551897049,
-0.0583796389400959,
0.06283676624298096,
0.04300946742296219,
-0.07890753448009491,
-0.005849861074239016,
-0.001717178151011467,
0.023264572024345398,
-0.0063728997483849525,
0.05735742673277855,
0.005673019215464592,
-0.07254866510629654,
0.055226802825927734,
0.020303970202803612,
-5.057164287336491e-8,
0.06048261746764183,
-0.024674829095602036,
-0.08822131901979446,
0.09520052373409271,
0.026623370125889778,
0.007767554838210344,
0.005182910710573196,
0.020000353455543518,
0.03321096673607826,
-0.07756465673446655,
0.0015353194903582335,
-0.028245756402611732,
-0.04542602226138115,
-0.014496475458145142,
-0.041569218039512634,
0.016281817108392715,
0.053046759217977524,
-0.05200333148241043,
0.005721393972635269,
-0.03188591077923775,
0.04238945245742798,
-0.020698878914117813,
-0.06788820028305054,
0.08268187940120697,
-0.041876714676618576,
0.01531896460801363,
0.026985827833414078,
-0.018343672156333923,
-0.01946168579161167,
0.013678236864507198,
0.09652656316757202,
-0.01462942361831665,
-0.03928321227431297,
0.06321960687637329,
0.010841788724064827,
0.02550126425921917,
-0.054238904267549515,
0.06868615001440048,
0.037315353751182556,
0.026445256546139717,
-0.04602257162332535,
0.03909975290298462,
0.00664799939841032,
-0.02495235949754715,
0.012357315048575401,
0.014859671704471111,
-0.11096403002738953,
0.028626712039113045,
-0.03927231952548027,
0.04461297020316124,
0.09524936974048615,
0.0006962303887121379,
-0.04680238664150238,
0.04849940165877342,
0.07169993221759796,
0.059270646423101425,
-0.05588814988732338,
-0.06706296652555466,
-0.003348920028656721,
0.033485084772109985,
-0.03669481724500656,
0.007652971427887678,
0.06520862877368927,
-0.018932906910777092
] | 0.112169
|
[Mach-O]: https://en.wikipedia.org/wiki/Mach-O [PE]: https://en.wikipedia.org/wiki/Portable\_Executable [Windows SDK]: https://developer.microsoft.com/en-us/windows/downloads/windows-sdk/ [`process.execPath`]: process.md#processexecpath [`require()`]: modules.md#requireid [`require.main`]: modules.md#accessing-the-main-module [`sea.getAsset()`]: #seagetassetkey-encoding [`sea.getAssetAsBlob()`]: #seagetassetasblobkey-options [`sea.getAssetKeys()`]: #seagetassetkeys [`sea.getRawAsset()`]: #seagetrawassetkey [`v8.startupSnapshot.setDeserializeMainFunction()`]: v8.md#v8startupsnapshotsetdeserializemainfunctioncallback-data [`v8.startupSnapshot` API]: v8.md#startup-snapshot-api [documentation about startup snapshot support in Node.js]: cli.md#--build-snapshot [fuse]: https://www.electronjs.org/docs/latest/tutorial/fuses [postject]: https://github.com/nodejs/postject [postject-linux-arm64-issue]: https://github.com/nodejs/postject/issues/105 [signtool]: https://learn.microsoft.com/en-us/windows/win32/seccrypto/signtool [single executable applications]: https://github.com/nodejs/single-executable [supported by Node.js]: https://github.com/nodejs/node/blob/main/BUILDING.md#platform-list
|
https://github.com/nodejs/node/blob/main//doc/api/single-executable-applications.md
|
main
|
nodejs
|
[
-0.05760299414396286,
0.020684555172920227,
-0.08183228969573975,
-0.010216675698757172,
-0.002006782218813896,
-0.05399109423160553,
0.003774874610826373,
0.0674741342663765,
-0.034735243767499924,
0.002177414484322071,
0.039316900074481964,
-0.08429256826639175,
-0.0448448471724987,
-0.011350653134286404,
0.030432121828198433,
0.04790984466671944,
-0.0038095677737146616,
-0.0485960878431797,
0.01803320273756981,
0.037334561347961426,
0.024314383044838905,
0.04885822534561157,
-0.005612112581729889,
-0.03357769176363945,
-0.05896035209298134,
-0.051854170858860016,
0.003993367776274681,
0.024447482079267502,
-0.025786470621824265,
0.04211301729083061,
0.028209678828716278,
0.011115331202745438,
0.07114607095718384,
0.012064949609339237,
0.15376606583595276,
0.08928772062063217,
0.07036973536014557,
-0.0728716254234314,
-0.13600490987300873,
-0.07203415036201477,
0.03290078788995743,
0.03143361583352089,
-0.032046638429164886,
0.04700133576989174,
-0.005967273842543364,
-0.0362032875418663,
0.0026745435316115618,
-0.06805670261383057,
-0.06051390990614891,
0.023568715900182724,
-0.08369598537683487,
-0.034003958106040955,
0.004379658494144678,
-0.018786314874887466,
0.044035766273736954,
0.038726259022951126,
-0.01750999689102173,
0.06294258683919907,
0.03813423961400986,
0.015649991109967232,
-0.0036192520055919886,
0.0005023914272896945,
-0.053921669721603394,
-0.05416954681277275,
0.010496025905013084,
0.05180666968226433,
-0.003104045055806637,
-0.04384755343198776,
0.04053165763616562,
-0.08707268536090851,
-0.062322333455085754,
-0.0340421162545681,
-0.02127985842525959,
0.058932989835739136,
-0.10174330323934555,
-0.06322436034679413,
0.026241643354296684,
0.022242123261094093,
-0.060406994074583054,
-0.1220874935388565,
-0.08027908951044083,
-0.06369827687740326,
-0.08235511928796768,
0.061025429517030716,
0.057348139584064484,
0.0667153000831604,
-0.04626570641994476,
-0.05446494370698929,
0.08131080120801926,
0.06778736412525177,
-0.0689065158367157,
-0.10853048413991928,
-0.017310332506895065,
-0.03161550685763359,
0.08362656831741333,
0.030881723389029503,
-0.05180246755480766,
0.054021719843149185,
-0.038616616278886795,
-0.00391024723649025,
-0.06816999614238739,
-0.01579151302576065,
-0.04782070592045784,
-0.058529213070869446,
0.03853725641965866,
-0.022354668006300926,
0.033107608556747437,
0.04807118698954582,
-0.038872573524713516,
-0.07973949611186981,
-0.055955223739147186,
0.04535948112607002,
-0.01793615333735943,
0.004367119632661343,
0.048592500388622284,
0.05151977017521858,
-0.017959177494049072,
0.020949291065335274,
-0.016934312880039215,
0.05868660658597946,
0.001353527302853763,
-0.07427599281072617,
0.022936087101697922,
0.011929639615118504,
-0.05450676381587982,
-0.022800154983997345,
0.09439311921596527,
5.0544188949984885e-33,
0.06109607592225075,
-0.09840298444032669,
0.02935195155441761,
0.009143705479800701,
0.05867153778672218,
-0.08161862194538116,
0.09130598604679108,
-0.034099217504262924,
-0.030729761347174644,
0.01997220516204834,
-0.1109841912984848,
0.07286384701728821,
-0.09130161255598068,
0.01355451438575983,
0.047567255795001984,
-0.08713842183351517,
0.009698907844722271,
0.0010709817288443446,
-0.034153006970882416,
-0.005665064789354801,
0.13549041748046875,
0.06284519284963608,
-0.052957482635974884,
-0.04740249738097191,
-0.011681491509079933,
0.04891398921608925,
0.0011066957376897335,
-0.046424318104982376,
0.09494130313396454,
0.06533993035554886,
-0.026583578437566757,
0.0614294558763504,
-0.10307984054088593,
0.03648287057876587,
-0.004683391191065311,
-0.05535516142845154,
-0.037054382264614105,
0.05999486520886421,
-0.056723371148109436,
0.033793456852436066,
0.05661243200302124,
-0.040087971836328506,
-0.019973600283265114,
-0.026261234655976295,
-0.017816035076975822,
-0.08897107094526291,
-0.046016763895750046,
0.017766432836651802,
0.11436653137207031,
0.028273962438106537,
0.05211782082915306,
0.018016062676906586,
0.036918383091688156,
0.03723686933517456,
-0.011514735408127308,
-0.06061166152358055,
-0.025773542001843452,
0.03046179562807083,
0.011604143306612968,
-0.010355999693274498,
-0.024731941521167755,
0.06255155056715012,
0.03011029027402401,
0.07685589045286179,
0.06102391704916954,
-0.01544222328811884,
0.045501869171857834,
-0.06918980181217194,
0.002104255137965083,
0.01284019835293293,
-0.05644925683736801,
0.0007436965825036168,
0.053667906671762466,
-0.018053097650408745,
0.0028389086946845055,
-0.016715403646230698,
-0.030778471380472183,
-0.06105770543217659,
-0.11828567832708359,
0.029135078191757202,
-0.06478558480739594,
0.06243373826146126,
-0.03471413254737854,
-0.04493613913655281,
0.023688318207859993,
0.019013425335288048,
-0.024317823350429535,
0.000790877325925976,
0.042998895049095154,
-0.01559685729444027,
-0.005467327777296305,
-0.07660296559333801,
0.002948115346953273,
-0.050157178193330765,
-0.10426304489374161,
-7.382640842461528e-33,
0.09924168139696121,
-0.025917617604136467,
-0.01292768120765686,
-0.01462794840335846,
-0.05626073107123375,
0.0064419107511639595,
-0.02845657244324684,
0.007663636934012175,
-0.01850416325032711,
0.014388934709131718,
-0.06500347703695297,
0.03965374454855919,
0.10409002006053925,
0.007076452951878309,
0.06644722819328308,
0.07561962306499481,
-0.03722842037677765,
0.06728417426347733,
0.0723644495010376,
-0.01374596357345581,
-0.02249159850180149,
0.017162151634693146,
0.05638808012008667,
0.051941629499197006,
-0.023462411016225815,
-0.030379125848412514,
0.025418024510145187,
0.03731318935751915,
-0.006884166970849037,
-0.05021798238158226,
-0.016092514619231224,
0.15534499287605286,
-0.058997370302677155,
-0.004191601183265448,
-0.04010826349258423,
0.049429915845394135,
-0.021807782351970673,
0.027964256703853607,
-0.03626498952507973,
0.03881505876779556,
0.030607981607317924,
-0.08102484047412872,
-0.021868130192160606,
-0.03111066110432148,
0.021658651530742645,
0.08062553405761719,
0.04362102970480919,
-0.007831494323909283,
-0.06016765162348747,
-0.02317817509174347,
0.12482599169015884,
-0.009402824565768242,
0.014996868558228016,
0.004985086619853973,
0.05479574203491211,
0.025872861966490746,
0.06691992282867432,
-0.0332162044942379,
-0.06613422930240631,
-0.00587829202413559,
0.09584610164165497,
-0.09458661824464798,
-0.03173387423157692,
-0.0543099045753479,
-0.011134665459394455,
0.03431978449225426,
0.01875128038227558,
0.03076610527932644,
-0.09207116812467575,
-0.00425944197922945,
0.023687314242124557,
-0.03128277137875557,
0.0009780348045751452,
0.03707968071103096,
-0.010993413627147675,
0.018557656556367874,
-0.06869779527187347,
-0.003308372339233756,
-0.027088714763522148,
0.07614722102880478,
0.04063070937991142,
0.08042185753583908,
0.0196645837277174,
-0.018621092662215233,
-0.05603379011154175,
-0.05307483300566673,
-0.026987731456756592,
0.026220856234431267,
-0.025971537455916405,
-0.02523117884993553,
-0.035623304545879364,
-0.01777581125497818,
0.0015964885242283344,
0.07493093609809875,
-0.005923643708229065,
-5.357351540169475e-8,
0.009891966357827187,
-0.03581765294075012,
-0.04645461589097977,
0.08385913819074631,
-0.00195519533008337,
0.03748391196131706,
0.0032475022599101067,
0.06898187845945358,
-0.007051612716168165,
-0.09494631737470627,
0.02390853501856327,
-0.04397264122962952,
0.004610962700098753,
-0.0033579813316464424,
-0.05552304908633232,
-0.009381839074194431,
0.03063998371362686,
0.07653744518756866,
0.029761891812086105,
-0.058848876506090164,
0.07962215691804886,
-0.03142905980348587,
-0.01288275234401226,
0.049024298787117004,
-0.02592582069337368,
0.04351097345352173,
-0.0034163810778409243,
0.035856448113918304,
-0.023616822436451912,
-0.01999962143599987,
0.02687772735953331,
-0.015455990098416805,
0.02399471402168274,
0.07343532890081406,
-0.05926131084561348,
0.08037514239549637,
-0.03102269396185875,
0.054654207080602646,
0.05733112245798111,
0.03445645794272423,
-0.03653465956449509,
0.060572996735572815,
-0.08221612125635147,
-0.01254984363913536,
0.0030787112191319466,
0.04542899504303932,
-0.056966524571180344,
0.02616587094962597,
-0.05853196606040001,
0.002089699264615774,
-0.039673592895269394,
0.011528869159519672,
-0.02373996190726757,
0.04459918290376663,
-0.023801608011126518,
0.1336616426706314,
-0.04939454793930054,
-0.09611856192350388,
-0.04128486290574074,
0.05736535042524338,
-0.006735291797667742,
0.0453750416636467,
-0.012845364399254322,
0.04544031620025635
] | 0.074105
|
# Net > Stability: 2 - Stable The `node:net` module provides an asynchronous network API for creating stream-based TCP or [IPC][] servers ([`net.createServer()`][]) and clients ([`net.createConnection()`][]). It can be accessed using: ```mjs import net from 'node:net'; ``` ```cjs const net = require('node:net'); ``` ## IPC support The `node:net` module supports IPC with named pipes on Windows, and Unix domain sockets on other operating systems. ### Identifying paths for IPC connections [`net.connect()`][], [`net.createConnection()`][], [`server.listen()`][], and [`socket.connect()`][] take a `path` parameter to identify IPC endpoints. On Unix, the local domain is also known as the Unix domain. The path is a file system pathname. It will throw an error when the length of pathname is greater than the length of `sizeof(sockaddr\_un.sun\_path)`. Typical values are 107 bytes on Linux and 103 bytes on macOS. If a Node.js API abstraction creates the Unix domain socket, it will unlink the Unix domain socket as well. For example, [`net.createServer()`][] may create a Unix domain socket and [`server.close()`][] will unlink it. But if a user creates the Unix domain socket outside of these abstractions, the user will need to remove it. The same applies when a Node.js API creates a Unix domain socket but the program then crashes. In short, a Unix domain socket will be visible in the file system and will persist until unlinked. On Linux, You can use Unix abstract socket by adding `\0` to the beginning of the path, such as `\0abstract`. The path to the Unix abstract socket is not visible in the file system and it will disappear automatically when all open references to the socket are closed. On Windows, the local domain is implemented using a named pipe. The path \_must\_ refer to an entry in `\\?\pipe\` or `\\.\pipe\`. Any characters are permitted, but the latter may do some processing of pipe names, such as resolving `..` sequences. Despite how it might look, the pipe namespace is flat. Pipes will \_not persist\_. They are removed when the last reference to them is closed. Unlike Unix domain sockets, Windows will close and remove the pipe when the owning process exits. JavaScript string escaping requires paths to be specified with extra backslash escaping such as: ```js net.createServer().listen( path.join('\\\\?\\pipe', process.cwd(), 'myctl')); ``` ## Class: `net.BlockList` The `BlockList` object can be used with some network APIs to specify rules for disabling inbound or outbound access to specific IP addresses, IP ranges, or IP subnets. ### `blockList.addAddress(address[, type])` \* `address` {string|net.SocketAddress} An IPv4 or IPv6 address. \* `type` {string} Either `'ipv4'` or `'ipv6'`. \*\*Default:\*\* `'ipv4'`. Adds a rule to block the given IP address. ### `blockList.addRange(start, end[, type])` \* `start` {string|net.SocketAddress} The starting IPv4 or IPv6 address in the range. \* `end` {string|net.SocketAddress} The ending IPv4 or IPv6 address in the range. \* `type` {string} Either `'ipv4'` or `'ipv6'`. \*\*Default:\*\* `'ipv4'`. Adds a rule to block a range of IP addresses from `start` (inclusive) to `end` (inclusive). ### `blockList.addSubnet(net, prefix[, type])` \* `net` {string|net.SocketAddress} The network IPv4 or IPv6 address. \* `prefix` {number} The number of CIDR prefix bits. For IPv4, this must be a value between `0` and `32`. For IPv6, this must be between `0` and `128`. \* `type` {string} Either `'ipv4'` or `'ipv6'`. \*\*Default:\*\* `'ipv4'`. Adds a rule to block a range of IP addresses specified as a subnet mask. ### `blockList.check(address[, type])` \* `address` {string|net.SocketAddress} The IP address to check \* `type` {string} Either `'ipv4'` or `'ipv6'`. \*\*Default:\*\* `'ipv4'`. \* Returns: {boolean} Returns `true` if the given IP address matches any of the rules added to the `BlockList`. ```js const blockList = new net.BlockList(); blockList.addAddress('123.123.123.123'); blockList.addRange('10.0.0.1', '10.0.0.10'); blockList.addSubnet('8592:757c:efae:4e45::', 64, 'ipv6'); console.log(blockList.check('123.123.123.123'));
|
https://github.com/nodejs/node/blob/main//doc/api/net.md
|
main
|
nodejs
|
[
-0.09857505559921265,
-0.022219229489564896,
-0.07258561998605728,
0.006602015346288681,
-0.013304315507411957,
-0.09553398936986923,
-0.036402154713869095,
0.08036878705024719,
0.0319441482424736,
0.0202056672424078,
-0.07426782697439194,
0.026576371863484383,
-0.002384565304964781,
-0.04304327815771103,
-0.011326262727379799,
-0.005477517377585173,
0.03163820505142212,
0.019917242228984833,
0.06847930699586868,
-0.08021373301744461,
-0.04932573437690735,
-0.004332601558417082,
0.03132980689406395,
-0.06664206832647324,
-0.03790024667978287,
-0.005229361820966005,
-0.006467663217335939,
0.015009842813014984,
0.03154714033007622,
0.03461239114403725,
-0.001171823008917272,
0.002137556904926896,
-0.12061986327171326,
0.06425296515226364,
-0.03339027240872383,
0.06944173574447632,
0.058900386095047,
-0.035815250128507614,
-0.118477463722229,
-0.04746472090482712,
0.13185174763202667,
0.032730113714933395,
0.0056992280296981335,
-0.0217733234167099,
-0.041907213628292084,
0.0032360991463065147,
-0.04320692643523216,
0.009663848206400871,
-0.06105677783489227,
-0.005413374397903681,
-0.06465628743171692,
-0.007332989946007729,
-0.03708341345191002,
0.0556037463247776,
0.02680102176964283,
-0.029933232814073563,
-0.06357996165752411,
0.0044336989521980286,
-0.007635604590177536,
0.07726705074310303,
-0.007925133220851421,
-0.010668549686670303,
-0.01661176234483719,
0.023144418373703957,
0.05481657013297081,
0.010426285676658154,
-0.05271472781896591,
0.06439075618982315,
0.04924679175019264,
-0.009581672959029675,
-0.067322738468647,
0.018893614411354065,
-0.14925704896450043,
0.045069482177495956,
-0.09218832850456238,
0.0006245386903174222,
0.03652098774909973,
0.019676506519317627,
-0.06902600079774857,
0.010728521272540092,
-0.0007939524366520345,
-0.00014990354247856885,
-0.03131236881017685,
0.006832091137766838,
-0.06602314114570618,
0.08330290764570236,
-0.0325116366147995,
0.017991680651903152,
0.0040828208439052105,
0.04244266450405121,
-0.059492871165275574,
0.002243383787572384,
-0.02874801680445671,
0.027300622314214706,
0.0438547357916832,
0.043432075530290604,
0.033473845571279526,
0.05093706026673317,
-0.05554550886154175,
-0.0003935849526897073,
-0.0046930694952607155,
-0.01089368388056755,
0.0016861618496477604,
-0.026708416640758514,
0.05234324932098389,
-0.010201307944953442,
0.03076557070016861,
-0.00004336066558607854,
0.07625172287225723,
-0.018208013847470284,
-0.09129753708839417,
-0.00640443991869688,
-0.03834996744990349,
-0.024605441838502884,
-0.012183031998574734,
-0.03823445737361908,
0.049645647406578064,
0.0123536866158247,
0.03632371500134468,
0.05545741692185402,
-0.03255004063248634,
-0.04606732353568077,
-0.06971530616283417,
-0.060867536813020706,
0.06205623969435692,
-0.02357758767902851,
0.06862982362508774,
7.6276345281595285e-34,
-0.062198102474212646,
-0.04421846941113472,
0.05513569712638855,
0.059518083930015564,
0.08307916671037674,
0.009376924484968185,
0.1177944540977478,
-0.014663544483482838,
-0.1171121820807457,
0.0179192665964365,
-0.09029198437929153,
-0.011863135732710361,
0.0538148432970047,
-0.06869101524353027,
0.016465701162815094,
-0.01709812320768833,
0.0669824630022049,
-0.03459400311112404,
0.11020012944936752,
0.055105097591876984,
0.0007127518183551729,
-0.005465320777148008,
0.04346079006791115,
-0.00796124804764986,
0.020709490403532982,
-0.1063229888677597,
-0.028135741129517555,
-0.0029090659227222204,
0.050024233758449554,
-0.0036323973909020424,
0.002268727868795395,
0.07401767373085022,
-0.01220028381794691,
-0.026710493490099907,
0.05401857942342758,
-0.05496892333030701,
0.012666122987866402,
0.0028060374315828085,
-0.04290797933936119,
-0.026469802483916283,
-0.02160894311964512,
-0.04564389958977699,
-0.08765003830194473,
0.05378107726573944,
-0.06412550061941147,
-0.06621503829956055,
-0.12037172168493271,
-0.023985395208001137,
-0.02792287990450859,
-0.010566516779363155,
0.013505827635526657,
0.047353390604257584,
0.014819623902440071,
0.023545296862721443,
0.0571259930729866,
-0.0057640112936496735,
0.013840969651937485,
0.01034822128713131,
-0.05118526145815849,
0.07744837552309036,
0.04113885015249252,
0.025631945580244064,
-0.0760674700140953,
0.0019845704082399607,
0.07438144087791443,
-0.01609131693840027,
-0.043459098786115646,
0.03595041111111641,
-0.00044274600804783404,
0.059720683842897415,
0.001919073169119656,
0.015498034656047821,
-0.030679456889629364,
0.07561618834733963,
-0.0070792874321341515,
0.06579037010669708,
-0.08918050676584244,
-0.03876156732439995,
0.05235068127512932,
-0.003668825142085552,
0.016763119027018547,
0.01569756120443344,
-0.039445824921131134,
0.03211665153503418,
0.023898348212242126,
-0.046293459832668304,
-0.06151484325528145,
-0.029233118519186974,
0.05113017559051514,
-0.036889247596263885,
0.039751142263412476,
0.02006242796778679,
0.07837111502885818,
0.018346620723605156,
-0.09303479641675949,
-4.091218089250737e-33,
-0.023378826677799225,
0.017359189689159393,
-0.11455250531435013,
0.06092292442917824,
-0.05506280064582825,
-0.03060460090637207,
0.023441869765520096,
-0.026037082076072693,
-0.047330982983112335,
-0.021079188212752342,
-0.004378696903586388,
0.010213580913841724,
0.03972754627466202,
0.0016230654437094927,
0.07248914986848831,
-0.07235604524612427,
-0.060190651565790176,
-0.05488632246851921,
0.005445383954793215,
-0.016653863713145256,
-0.0979192778468132,
0.022797221317887306,
0.023580247536301613,
-0.028355533257126808,
-0.07327690720558167,
0.029158052057027817,
-0.03835457190871239,
0.010898349806666374,
-0.10762662440538406,
-0.02874794229865074,
-0.0191096980124712,
0.053460992872714996,
-0.053581222891807556,
-0.03006601706147194,
0.012900282628834248,
0.025637401267886162,
0.044249631464481354,
0.055244918912649155,
0.11238770186901093,
-0.027734870091080666,
0.10297496616840363,
0.009456131607294083,
-0.05108056217432022,
0.009935962036252022,
0.054035406559705734,
-0.004841206129640341,
-0.06470701098442078,
0.10264246165752411,
-0.05364622920751572,
0.011744252406060696,
0.015153375454246998,
-0.04277382791042328,
0.05863625928759575,
0.04944010451436043,
0.05597735196352005,
0.05794892460107803,
0.035943739116191864,
-0.016453498974442482,
0.10346358269453049,
-0.0027144046034663916,
0.04500775784254074,
-0.1451820731163025,
-0.05248174071311951,
0.08503387123346329,
0.013314406387507915,
0.023361938074231148,
-0.05938686802983284,
0.028573866933584213,
0.01625317521393299,
-0.07068517059087753,
0.01131470501422882,
0.029040345922112465,
-0.024088464677333832,
0.04672494903206825,
-0.033978454768657684,
-0.022304320707917213,
0.07250252366065979,
-0.012228413484990597,
-0.05799673870205879,
0.11203429847955704,
-0.04766586050391197,
0.15050208568572998,
-0.08078514784574509,
0.00010655526421032846,
0.026287352666258812,
-0.014681164175271988,
0.027879228815436363,
-0.01098017767071724,
0.020492974668741226,
-0.03584465757012367,
0.01037207804620266,
0.06712315231561661,
-0.11116879433393478,
0.039839234203100204,
0.010724594816565514,
-4.832564215462298e-8,
-0.051714446395635605,
0.0009416615939699113,
-0.10167428106069565,
-0.0008418566430918872,
-0.005262857768684626,
0.07855258882045746,
-0.02776479907333851,
-0.07778843492269516,
0.0972026064991951,
0.08561847358942032,
0.006130227353423834,
-0.05397707596421242,
-0.010452618822455406,
-0.03717542439699173,
-0.008324751630425453,
0.05917949602007866,
0.016241736710071564,
-0.0022605229169130325,
0.029960788786411285,
-0.0435488224029541,
0.02658333070576191,
-0.03441579267382622,
0.019923344254493713,
0.12259471416473389,
-0.0679151713848114,
-0.07727787643671036,
0.08673589676618576,
0.03346063196659088,
-0.10944788157939911,
0.008386279456317425,
-0.06996893137693405,
0.0072947838343679905,
0.07216078788042068,
0.03412138298153877,
0.014293049462139606,
0.03962550312280655,
-0.06299065798521042,
0.015395054593682289,
0.04134594276547432,
0.02871512807905674,
-0.013582310639321804,
0.044487498700618744,
-0.024242065846920013,
0.00046705349814146757,
0.04531031847000122,
0.022724436596035957,
0.011939016170799732,
0.08225927501916885,
-0.03082301840186119,
-0.028166383504867554,
0.013659344054758549,
0.0008241456234827638,
-0.0148110780864954,
0.005570647306740284,
0.044961828738451004,
-0.009768461808562279,
-0.08605891466140747,
-0.09063686430454254,
-0.03103785589337349,
0.021358445286750793,
-0.03722892701625824,
0.10327596962451935,
0.01873025670647621,
0.0012233894085511565
] | 0.124121
|
type])` \* `address` {string|net.SocketAddress} The IP address to check \* `type` {string} Either `'ipv4'` or `'ipv6'`. \*\*Default:\*\* `'ipv4'`. \* Returns: {boolean} Returns `true` if the given IP address matches any of the rules added to the `BlockList`. ```js const blockList = new net.BlockList(); blockList.addAddress('123.123.123.123'); blockList.addRange('10.0.0.1', '10.0.0.10'); blockList.addSubnet('8592:757c:efae:4e45::', 64, 'ipv6'); console.log(blockList.check('123.123.123.123')); // Prints: true console.log(blockList.check('10.0.0.3')); // Prints: true console.log(blockList.check('222.111.111.222')); // Prints: false // IPv6 notation for IPv4 addresses works: console.log(blockList.check('::ffff:7b7b:7b7b', 'ipv6')); // Prints: true console.log(blockList.check('::ffff:123.123.123.123', 'ipv6')); // Prints: true ``` ### `blockList.rules` \* Type: {string\[]} The list of rules added to the blocklist. ### `BlockList.isBlockList(value)` \* `value` {any} Any JS value \* Returns `true` if the `value` is a `net.BlockList`. ### `blockList.fromJSON(value)` > Stability: 1 - Experimental ```js const blockList = new net.BlockList(); const data = [ 'Subnet: IPv4 192.168.1.0/24', 'Address: IPv4 10.0.0.5', 'Range: IPv4 192.168.2.1-192.168.2.10', 'Range: IPv4 10.0.0.1-10.0.0.10', ]; blockList.fromJSON(data); blockList.fromJSON(JSON.stringify(data)); ``` \* `value` Blocklist.rules ### `blockList.toJSON()` > Stability: 1 - Experimental \* Returns Blocklist.rules ## Class: `net.SocketAddress` ### `new net.SocketAddress([options])` \* `options` {Object} \* `address` {string} The network address as either an IPv4 or IPv6 string. \*\*Default\*\*: `'127.0.0.1'` if `family` is `'ipv4'`; `'::'` if `family` is `'ipv6'`. \* `family` {string} One of either `'ipv4'` or `'ipv6'`. \*\*Default\*\*: `'ipv4'`. \* `flowlabel` {number} An IPv6 flow-label used only if `family` is `'ipv6'`. \* `port` {number} An IP port. ### `socketaddress.address` \* Type: {string} ### `socketaddress.family` \* Type: {string} Either `'ipv4'` or `'ipv6'`. ### `socketaddress.flowlabel` \* Type: {number} ### `socketaddress.port` \* Type: {number} ### `SocketAddress.parse(input)` \* `input` {string} An input string containing an IP address and optional port, e.g. `123.1.2.3:1234` or `[1::1]:1234`. \* Returns: {net.SocketAddress} Returns a `SocketAddress` if parsing was successful. Otherwise returns `undefined`. ## Class: `net.Server` \* Extends: {EventEmitter} This class is used to create a TCP or [IPC][] server. ### `new net.Server([options][, connectionListener])` \* `options` {Object} See [`net.createServer([options][, connectionListener])`][`net.createServer()`]. \* `connectionListener` {Function} Automatically set as a listener for the [`'connection'`][] event. \* Returns: {net.Server} `net.Server` is an [`EventEmitter`][] with the following events: ### Event: `'close'` Emitted when the server closes. If connections exist, this event is not emitted until all connections are ended. ### Event: `'connection'` \* Type: {net.Socket} The connection object Emitted when a new connection is made. `socket` is an instance of `net.Socket`. ### Event: `'error'` \* Type: {Error} Emitted when an error occurs. Unlike [`net.Socket`][], the [`'close'`][] event will \*\*not\*\* be emitted directly following this event unless [`server.close()`][] is manually called. See the example in discussion of [`server.listen()`][]. ### Event: `'listening'` Emitted when the server has been bound after calling [`server.listen()`][]. ### Event: `'drop'` When the number of connections reaches the threshold of `server.maxConnections`, the server will drop new connections and emit `'drop'` event instead. If it is a TCP server, the argument is as follows, otherwise the argument is `undefined`. \* `data` {Object} The argument passed to event listener. \* `localAddress` {string} Local address. \* `localPort` {number} Local port. \* `localFamily` {string} Local family. \* `remoteAddress` {string} Remote address. \* `remotePort` {number} Remote port. \* `remoteFamily` {string} Remote IP family. `'IPv4'` or `'IPv6'`. ### `server.address()` \* Returns: {Object|string|null} Returns the bound `address`, the address `family` name, and `port` of the server as reported by the operating system if listening on an IP socket (useful to find which port was assigned when getting an OS-assigned address): `{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`. For a server listening on a pipe or Unix domain socket, the name is returned as a string. ```js const server = net.createServer((socket) => { socket.end('goodbye\n'); }).on('error', (err) => { // Handle errors here. throw err; }); // Grab an arbitrary unused port. server.listen(() => { console.log('opened server on', server.address()); }); ```
|
https://github.com/nodejs/node/blob/main//doc/api/net.md
|
main
|
nodejs
|
[
-0.01840278133749962,
0.016821498051285744,
0.0024402253329753876,
-0.02201233245432377,
0.027108684182167053,
0.0025582348462194204,
0.03916768729686737,
-0.028786087408661842,
0.014739799313247204,
-0.020713642239570618,
-0.008270030841231346,
0.01001015305519104,
-0.06297484040260315,
0.0077742221765220165,
0.048185210675001144,
-0.014663074165582657,
-0.0618482269346714,
-0.04017074406147003,
0.029948407784104347,
-0.0940547063946724,
0.041184231638908386,
-0.007913656532764435,
-0.040285125374794006,
-0.07370538264513016,
-0.021830635145306587,
0.011244305409491062,
0.020029054954648018,
-0.020894691348075867,
0.054683003574609756,
0.00616189232096076,
-0.009514260105788708,
-0.023519253358244896,
-0.05585802346467972,
0.05751954764127731,
0.01013330090790987,
-0.018992431461811066,
0.010748765431344509,
0.03354232758283615,
-0.04080158472061157,
0.001250831875950098,
0.05366518720984459,
-0.002684603212401271,
0.07711846381425858,
-0.07489006221294403,
0.03834015130996704,
0.04552192986011505,
-0.07427777349948883,
0.05248104780912399,
0.007564592640846968,
-0.06684379279613495,
0.008673840202391148,
0.009169056080281734,
-0.017188843339681625,
-0.06941866129636765,
0.137892484664917,
-0.03153402730822563,
-0.030496975407004356,
-0.00900923740118742,
0.015006974339485168,
0.019112199544906616,
0.05304998159408569,
-0.06158556416630745,
-0.014233469031751156,
0.0023279376327991486,
0.007872632704675198,
-0.0163528174161911,
-0.07316361367702484,
0.039125241339206696,
-0.009718378074467182,
-0.0067781503312289715,
-0.0653674453496933,
0.06407485157251358,
-0.023113779723644257,
0.10125792771577835,
-0.021866338327527046,
0.040233951061964035,
0.002148384926840663,
-0.016837285831570625,
-0.009426405653357506,
0.029552731662988663,
-0.06659037619829178,
-0.12358079105615616,
-0.045572299510240555,
0.06054488942027092,
-0.01651216484606266,
0.04147815331816673,
-0.05511435493826866,
-0.028191829100251198,
0.001721944659948349,
0.0889802873134613,
0.00797845795750618,
-0.007908012717962265,
0.01250232383608818,
0.005543829407542944,
0.05714349076151848,
0.07786048203706741,
-0.003306919476017356,
-0.022609561681747437,
-0.06890241801738739,
0.06170814484357834,
0.005844864062964916,
-0.07765122503042221,
-0.08100441843271255,
-0.013493956066668034,
0.13215361535549164,
0.014940614812076092,
0.034129757434129715,
-0.04708493500947952,
-0.021053636446595192,
0.013383799232542515,
-0.05846954137086868,
0.0025553146842867136,
0.058351997286081314,
-0.029609952121973038,
-0.029216565191745758,
-0.03396277129650116,
0.10041435062885284,
0.03775261715054512,
-0.03455887734889984,
0.042359184473752975,
-0.006676154676824808,
-0.0017766302917152643,
0.028147442266345024,
-0.046215932816267014,
-0.029909882694482803,
-0.06456563621759415,
0.0795360580086708,
4.2963561798066267e-33,
0.008986611850559711,
-0.006538233254104853,
0.01378751453012228,
-0.038233108818531036,
-0.04488484188914299,
-0.01887952908873558,
-0.020523114129900932,
0.07472553104162216,
-0.036858100444078445,
0.09523048996925354,
0.015487819910049438,
-0.07756355404853821,
0.05483832582831383,
0.010269401594996452,
-0.003909482154995203,
0.044061996042728424,
0.11374945938587189,
0.006754531059414148,
0.05990908294916153,
0.04473528265953064,
-0.01633622497320175,
-0.018504107370972633,
0.04764527454972267,
-0.004529780708253384,
-0.018937546759843826,
-0.03364316374063492,
-0.06213188171386719,
0.02105177752673626,
-0.015363652259111404,
-0.023784445598721504,
0.012456799857318401,
-0.030794555321335793,
0.005714537110179663,
0.03878290578722954,
0.0655965581536293,
0.036211851984262466,
0.017777035012841225,
-0.02680816501379013,
-0.0134109016507864,
-0.06240364536643028,
-0.024652455002069473,
-0.06634552776813507,
-0.1387503445148468,
0.0016169792506843805,
0.02664978988468647,
-0.004941603634506464,
-0.09881454706192017,
-0.08114435523748398,
0.03244581073522568,
-0.001716451602987945,
-0.007404579780995846,
0.11718326807022095,
-0.03549998253583908,
-0.03543535992503166,
0.04523670673370361,
-0.049316562712192535,
0.04577837139368057,
0.08776436746120453,
0.05064264312386513,
0.05340210720896721,
0.027038784697651863,
0.03323512524366379,
-0.07340486347675323,
-0.01718662865459919,
0.03509429469704628,
0.0316108837723732,
0.023277124390006065,
-0.06498310714960098,
-0.041250377893447876,
-0.014511670917272568,
0.011282267048954964,
-0.020591242238879204,
0.011765015311539173,
0.11457812041044235,
-0.028726045042276382,
0.005138154607266188,
-0.04493283852934837,
0.022812549024820328,
-0.016999535262584686,
-0.12133949249982834,
0.029605088755488396,
0.06650537252426147,
-0.014803971163928509,
0.05514540150761604,
-0.05272434651851654,
0.02697768807411194,
-0.04164738208055496,
-0.015212065540254116,
0.11442427337169647,
0.02437276765704155,
-0.0009440125431865454,
-0.06486151367425919,
-0.051023103296756744,
-0.0075933486223220825,
-0.0420524887740612,
-5.56718459184854e-33,
-0.0073997764848172665,
0.07251396775245667,
-0.11175347864627838,
-0.06433902680873871,
-0.09750091284513474,
-0.038604725152254105,
0.09019695222377777,
0.010757857002317905,
0.016575681045651436,
-0.0067533222027122974,
0.06839702278375626,
0.0341552309691906,
0.06437693536281586,
0.015383828431367874,
0.02928529679775238,
0.026859069243073463,
-0.1269146203994751,
-0.019695337861776352,
-0.005295583978295326,
-0.019136536866426468,
-0.04423118382692337,
0.05047902464866638,
0.03353170305490494,
0.0031372015364468098,
-0.06176397576928139,
0.044588908553123474,
0.009336786344647408,
0.0357942208647728,
-0.11283178627490997,
-0.032712433487176895,
0.014313814230263233,
0.062469325959682465,
-0.01246992964297533,
0.059097107499837875,
0.0023967402521520853,
-0.049233198165893555,
0.05262335389852524,
0.12388099730014801,
0.06722749769687653,
-0.026637433096766472,
0.04232281073927879,
0.025788649916648865,
-0.04180637374520302,
-0.012361393310129642,
-0.02618069387972355,
-0.02688031643629074,
0.04142506793141365,
0.07657180726528168,
0.0016396855935454369,
-0.021551096811890602,
0.04369289055466652,
-0.05297364667057991,
0.055075060576200485,
0.08260925859212875,
0.0611162967979908,
0.05153706297278404,
-0.036591216921806335,
-0.07559333741664886,
0.07287285476922989,
0.05551902577280998,
-0.0449368990957737,
-0.16999836266040802,
0.0031442116014659405,
0.07051626592874527,
0.03947555273771286,
-0.04186846315860748,
-0.09539777040481567,
0.019152561202645302,
0.039391037076711655,
-0.09777604043483734,
0.02414703741669655,
0.03669629991054535,
-0.02958196960389614,
-0.002373587107285857,
-0.01816859282553196,
0.002155626192688942,
0.0849359780550003,
0.029121341183781624,
-0.019208526238799095,
0.13913604617118835,
-0.0901225209236145,
0.06686436384916306,
-0.11088072508573532,
-0.03466952219605446,
0.06389476358890533,
0.025034882128238678,
-0.009098557755351067,
0.028495408594608307,
0.0028188989963382483,
-0.017119770869612694,
-0.04493847116827965,
0.10047239065170288,
-0.06978359818458557,
-0.052770692855119705,
-0.010310808196663857,
-5.21130552044724e-8,
-0.04276407137513161,
-0.021552838385105133,
-0.009672565385699272,
-0.00894609559327364,
-0.014677926898002625,
0.0240214541554451,
-0.0007270014612004161,
-0.13475044071674347,
0.003857712959870696,
-0.01512458547949791,
-0.022976301610469818,
0.05203680321574211,
-0.008902067318558693,
-0.061071768403053284,
0.03398502245545387,
-0.012784620746970177,
-0.06726463884115219,
-0.039825279265642166,
0.011157194152474403,
0.08792226761579514,
0.03096587024629116,
-0.0722353383898735,
-0.03457755595445633,
0.044067151844501495,
-0.020714009180665016,
-0.053108155727386475,
0.036480437964200974,
-0.019508076831698418,
-0.05193215236067772,
0.147269606590271,
-0.00033524257014505565,
0.06265226006507874,
0.04098976403474808,
-0.07095403224229813,
-0.02134142629802227,
0.09441559761762619,
-0.031179476529359818,
0.02346230298280716,
0.032952409237623215,
0.06972777843475342,
0.02699694223701954,
0.006364250089973211,
-0.06544990837574005,
0.0026477116625756025,
-0.004836743697524071,
-0.01749352365732193,
0.03778925538063049,
0.027449151501059532,
0.030819838866591454,
-0.12275727838277817,
-0.06562620401382446,
0.041430626064538956,
0.020886823534965515,
-0.005015392322093248,
-0.025372635573148727,
-0.046893976628780365,
-0.07481671869754791,
-0.025453999638557434,
-0.003420115914195776,
0.09520894289016724,
0.05628139525651932,
-0.0003494941920507699,
0.03922826796770096,
-0.03433642536401749
] | 0.059832
|
server listening on a pipe or Unix domain socket, the name is returned as a string. ```js const server = net.createServer((socket) => { socket.end('goodbye\n'); }).on('error', (err) => { // Handle errors here. throw err; }); // Grab an arbitrary unused port. server.listen(() => { console.log('opened server on', server.address()); }); ``` `server.address()` returns `null` before the `'listening'` event has been emitted or after calling `server.close()`. ### `server.close([callback])` \* `callback` {Function} Called when the server is closed. \* Returns: {net.Server} Stops the server from accepting new connections and keeps existing connections. This function is asynchronous, the server is finally closed when all connections are ended and the server emits a [`'close'`][] event. The optional `callback` will be called once the `'close'` event occurs. Unlike that event, it will be called with an `Error` as its only argument if the server was not open when it was closed. ### `server[Symbol.asyncDispose]()` Calls [`server.close()`][] and returns a promise that fulfills when the server has closed. ### `server.getConnections(callback)` \* `callback` {Function} \* Returns: {net.Server} Asynchronously get the number of concurrent connections on the server. Works when sockets were sent to forks. Callback should take two arguments `err` and `count`. ### `server.listen()` Start a server listening for connections. A `net.Server` can be a TCP or an [IPC][] server depending on what it listens to. Possible signatures: \* [`server.listen(handle[, backlog][, callback])`][`server.listen(handle)`] \* [`server.listen(options[, callback])`][`server.listen(options)`] \* [`server.listen(path[, backlog][, callback])`][`server.listen(path)`] for [IPC][] servers \* [`server.listen([port[, host[, backlog]]][, callback])`][`server.listen(port)`] for TCP servers This function is asynchronous. When the server starts listening, the [`'listening'`][] event will be emitted. The last parameter `callback` will be added as a listener for the [`'listening'`][] event. All `listen()` methods can take a `backlog` parameter to specify the maximum length of the queue of pending connections. The actual length will be determined by the OS through sysctl settings such as `tcp\_max\_syn\_backlog` and `somaxconn` on Linux. The default value of this parameter is 511 (not 512). All [`net.Socket`][] are set to `SO\_REUSEADDR` (see [`socket(7)`][] for details). The `server.listen()` method can be called again if and only if there was an error during the first `server.listen()` call or `server.close()` has been called. Otherwise, an `ERR\_SERVER\_ALREADY\_LISTEN` error will be thrown. One of the most common errors raised when listening is `EADDRINUSE`. This happens when another server is already listening on the requested `port`/`path`/`handle`. One way to handle this would be to retry after a certain amount of time: ```js server.on('error', (e) => { if (e.code === 'EADDRINUSE') { console.error('Address in use, retrying...'); setTimeout(() => { server.close(); server.listen(PORT, HOST); }, 1000); } }); ``` #### `server.listen(handle[, backlog][, callback])` \* `handle` {Object} \* `backlog` {number} Common parameter of [`server.listen()`][] functions \* `callback` {Function} \* Returns: {net.Server} Start a server listening for connections on a given `handle` that has already been bound to a port, a Unix domain socket, or a Windows named pipe. The `handle` object can be either a server, a socket (anything with an underlying `\_handle` member), or an object with an `fd` member that is a valid file descriptor. Listening on a file descriptor is not supported on Windows. #### `server.listen(options[, callback])` \* `options` {Object} Required. Supports the following properties: \* `backlog` {number} Common parameter of [`server.listen()`][] functions. \* `exclusive` {boolean} \*\*Default:\*\* `false` \* `host` {string} \* `ipv6Only` {boolean} For TCP servers, setting `ipv6Only` to `true` will disable dual-stack support, i.e., binding to host `::` won't make `0.0.0.0` be bound. \*\*Default:\*\* `false`. \* `reusePort` {boolean} For TCP servers, setting `reusePort` to `true` allows multiple sockets on the same host to bind to the same port. Incoming connections are distributed by the operating system to listening sockets. This option is
|
https://github.com/nodejs/node/blob/main//doc/api/net.md
|
main
|
nodejs
|
[
-0.0886877104640007,
-0.018753016367554665,
-0.007588574197143316,
0.023211903870105743,
-0.02050251141190529,
-0.098064124584198,
0.015924008563160896,
0.01728910394012928,
0.13075724244117737,
-0.026311706751585007,
-0.05984760820865631,
0.07118268311023712,
-0.06832277029752731,
-0.019964007660746574,
-0.01514329295605421,
0.034601375460624695,
-0.011939599178731441,
-0.026180488988757133,
0.027434734627604485,
-0.09217415750026703,
-0.025065908208489418,
0.01273374818265438,
-0.011765670962631702,
-0.053907815366983414,
-0.028610294684767723,
-0.014195430092513561,
0.03425968810915947,
-0.05619480088353157,
0.03350704908370972,
0.05663955211639404,
0.02518223598599434,
-0.06496834009885788,
-0.14459919929504395,
-0.012463840655982494,
-0.07712846249341965,
0.10950323939323425,
-0.011672696098685265,
0.013210838660597801,
-0.054271236062049866,
-0.007310834247618914,
0.09783517569303513,
0.005369958933442831,
0.006975905038416386,
-0.0012662791414186358,
-0.03006678633391857,
0.0039023030549287796,
-0.09804453700780869,
-0.07688140869140625,
-0.07360275834798813,
-0.002730627078562975,
-0.0447324700653553,
-0.005078799556940794,
-0.02063128538429737,
0.0786583200097084,
0.05094493553042412,
-0.04107045382261276,
-0.07013828307390213,
-0.03186967223882675,
-0.019900687038898468,
0.059672947973012924,
0.017289288341999054,
-0.041215211153030396,
-0.029664650559425354,
0.04040593281388283,
0.08129393309354782,
-0.03479587286710739,
-0.029932722449302673,
-0.010235486552119255,
0.02082022652029991,
0.03426679968833923,
-0.0328579843044281,
0.03773109242320061,
-0.08931498974561691,
0.008688019588589668,
-0.018801461905241013,
-0.018383149057626724,
0.017490867525339127,
-0.01786775514483452,
-0.07770241796970367,
0.08259553462266922,
-0.014354090206325054,
-0.07054498791694641,
-0.07808279246091843,
0.0015083920443430543,
-0.06923070549964905,
0.1191074550151825,
-0.03173916041851044,
-0.01695951260626316,
0.026599416509270668,
-0.0004351982206571847,
-0.12134547531604767,
-0.015643130987882614,
-0.032472334802150726,
0.09029659628868103,
-0.02045888639986515,
0.043088849633932114,
0.03235432505607605,
0.055330004543066025,
-0.03535671904683113,
0.008102629333734512,
0.03053309954702854,
0.02557642199099064,
-0.001886120531708002,
-0.04667036235332489,
-0.026840250939130783,
-0.038893476128578186,
-0.050602737814188004,
0.002401266945526004,
0.02707149088382721,
0.019979773089289665,
-0.058592360466718674,
0.01643364503979683,
0.025100985541939735,
0.05202297866344452,
-0.08470487594604492,
0.05956704914569855,
0.05484617501497269,
-0.028210997581481934,
0.041510503739118576,
0.07732222974300385,
0.08250746130943298,
0.03460589051246643,
-0.05159911885857582,
-0.029473522678017616,
0.021341752260923386,
0.020664818584918976,
0.059448737651109695,
-1.4072391590783148e-34,
-0.047055989503860474,
-0.062221866101026535,
-0.038569238036870956,
0.03656311705708504,
0.08334717154502869,
-0.0006243198877200484,
0.00276840734295547,
-0.004459236282855272,
-0.051345739513635635,
0.10107225924730301,
-0.028838442638516426,
0.006803255993872881,
0.0729789137840271,
-0.08469503372907639,
0.00831577181816101,
-0.010377730242908001,
0.11271511763334274,
0.013248204253613949,
0.06001335754990578,
0.014865218661725521,
-0.027219168841838837,
-0.0045475889928638935,
0.02202841080725193,
0.06426942348480225,
0.04010344669222832,
-0.05208165571093559,
-0.031750842928886414,
0.025892890989780426,
-0.03739498555660248,
-0.019448168575763702,
0.021445617079734802,
-0.02190924435853958,
0.02085062675178051,
0.02844730205833912,
0.07248659431934357,
-0.02846369333565235,
0.05796043202280998,
0.008229575119912624,
-0.06983769685029984,
-0.04336126521229744,
0.031426142901182175,
-0.02406233176589012,
-0.193625345826149,
0.09293201565742493,
0.022191548720002174,
-0.09665489196777344,
-0.09387172758579254,
-0.06703822314739227,
0.0725359171628952,
-0.009003889746963978,
0.006735514383763075,
0.0007891904097050428,
0.05212555080652237,
0.08035892248153687,
0.021235201507806778,
0.04928571358323097,
-0.004233967047184706,
0.026423918083310127,
-0.07844788581132889,
0.028320543467998505,
0.059158604592084885,
-0.009706786833703518,
-0.02472602389752865,
-0.047885674983263016,
0.04890873655676842,
-0.025620263069868088,
0.012034163810312748,
-0.007109574507921934,
-0.01661366969347,
-0.017036983743309975,
-0.00976626668125391,
0.024723077192902565,
-0.03532658889889717,
0.04620269313454628,
0.02098017930984497,
0.08097244054079056,
-0.0908568724989891,
0.027180925011634827,
0.0731007531285286,
-0.030801137909293175,
0.060879260301589966,
0.00492469035089016,
-0.03941900283098221,
0.09574389457702637,
0.03204875439405441,
0.03752628713846207,
-0.07486934959888458,
-0.040757276117801666,
-0.006593108177185059,
0.0018188131507486105,
-0.04916331171989441,
0.0018366932636126876,
0.0584268644452095,
-0.02637559361755848,
-0.023171834647655487,
-4.529623850177694e-33,
-0.0404064767062664,
0.025949671864509583,
-0.0982331782579422,
0.0420595221221447,
-0.030899951234459877,
-0.05789768323302269,
0.011306574568152428,
0.0061712139286100864,
-0.06809194386005402,
-0.04133687540888786,
0.045148175209760666,
0.04456739500164986,
0.04897700250148773,
0.07871469110250473,
-0.022562671452760696,
0.024851001799106598,
-0.021601084619760513,
-0.04461253806948662,
-0.00012144204811193049,
-0.0043311333283782005,
-0.001803846564143896,
0.037431422621011734,
0.06890822947025299,
-0.016617534682154655,
-0.11651226878166199,
0.03666927292943001,
-0.006799560505896807,
-0.05418933928012848,
-0.10736669600009918,
-0.043360527604818344,
-0.007054096087813377,
0.01830434985458851,
0.023043660447001457,
0.04280051961541176,
0.009476163424551487,
0.03039155900478363,
0.06824816763401031,
0.015196701511740685,
0.08924134820699692,
-0.03945348039269447,
0.10367760062217712,
-0.011334509588778019,
0.004092362709343433,
-0.040904030203819275,
-0.04662182554602623,
0.023407891392707825,
-0.06700348109006882,
0.03518232703208923,
-0.014718801714479923,
-0.01548835914582014,
-0.050509121268987656,
-0.02356584556400776,
0.04975520074367523,
0.029313193634152412,
-0.0016147919232025743,
0.0458989143371582,
0.02898821234703064,
-0.027909884229302406,
0.06472107768058777,
0.020737547427415848,
0.06940293312072754,
-0.10691113770008087,
-0.03017617017030716,
0.05291680991649628,
-0.017458897083997726,
0.031187262386083603,
-0.10851307213306427,
0.022580087184906006,
0.11200214922428131,
-0.03845987096428871,
-0.009871311485767365,
0.0632801502943039,
-0.08725704252719879,
0.02801918424665928,
-0.03624816611409187,
0.03616306930780411,
-0.00483333645388484,
-0.10862655192613602,
0.008908592164516449,
0.10537998378276825,
-0.062180157750844955,
0.11033683270215988,
-0.08848612010478973,
-0.001295519876293838,
0.07652005553245544,
0.0046531022526323795,
-0.010846378281712532,
-0.021061981096863747,
-0.009764411486685276,
-0.04547881707549095,
0.006188672035932541,
0.06054528057575226,
-0.1098044216632843,
-0.00139590201433748,
-0.05502915009856224,
-4.92625389370005e-8,
-0.014694717712700367,
0.02372833900153637,
0.014299608767032623,
-0.033506929874420166,
0.006859663408249617,
-0.03387966752052307,
0.009558264166116714,
-0.07276912033557892,
0.013555116951465607,
0.061325885355472565,
-0.06874518096446991,
-0.02466973103582859,
0.026049554347991943,
0.014401854947209358,
0.03973637521266937,
0.012979267165064812,
0.04083950072526932,
0.0388287790119648,
0.002275444334372878,
-0.05242586508393288,
0.0608164444565773,
-0.04385191202163696,
0.020079921931028366,
0.05389523506164551,
-0.05061298981308937,
-0.08912444859743118,
0.0752401202917099,
0.03322478383779526,
-0.09712395817041397,
-0.03397664055228233,
-0.031825676560401917,
0.07160995900630951,
0.0534505657851696,
0.030974477529525757,
-0.055795468389987946,
0.058126483112573624,
-0.06210434436798096,
-0.055737387388944626,
0.04024164006114006,
0.05467977002263069,
0.025158841162919998,
0.009835291653871536,
-0.04524996504187584,
0.047727279365062714,
0.00002206354110967368,
0.06312120705842972,
0.07512447237968445,
0.036777008324861526,
-0.017080694437026978,
-0.043638527393341064,
-0.030703973025083542,
-0.016462983563542366,
0.0006959859165363014,
-0.04304814338684082,
0.05396348983049393,
-0.019394874572753906,
-0.04807530716061592,
-0.0442868173122406,
-0.0483422614634037,
-0.03453448414802551,
-0.024521611630916595,
0.11477731913328171,
-0.028348233550786972,
-0.03436071053147316
] | 0.120872
|
support, i.e., binding to host `::` won't make `0.0.0.0` be bound. \*\*Default:\*\* `false`. \* `reusePort` {boolean} For TCP servers, setting `reusePort` to `true` allows multiple sockets on the same host to bind to the same port. Incoming connections are distributed by the operating system to listening sockets. This option is available only on some platforms, such as Linux 3.9+, DragonFlyBSD 3.6+, FreeBSD 12.0+, Solaris 11.4, and AIX 7.2.5+. On unsupported platforms, this option raises an error. \*\*Default:\*\* `false`. \* `path` {string} Will be ignored if `port` is specified. See [Identifying paths for IPC connections][]. \* `port` {number} \* `readableAll` {boolean} For IPC servers makes the pipe readable for all users. \*\*Default:\*\* `false`. \* `signal` {AbortSignal} An AbortSignal that may be used to close a listening server. \* `writableAll` {boolean} For IPC servers makes the pipe writable for all users. \*\*Default:\*\* `false`. \* `callback` {Function} functions. \* Returns: {net.Server} If `port` is specified, it behaves the same as [`server.listen([port[, host[, backlog]]][, callback])`][`server.listen(port)`]. Otherwise, if `path` is specified, it behaves the same as [`server.listen(path[, backlog][, callback])`][`server.listen(path)`]. If none of them is specified, an error will be thrown. If `exclusive` is `false` (default), then cluster workers will use the same underlying handle, allowing connection handling duties to be shared. When `exclusive` is `true`, the handle is not shared, and attempted port sharing results in an error. An example which listens on an exclusive port is shown below. ```js server.listen({ host: 'localhost', port: 80, exclusive: true, }); ``` When `exclusive` is `true` and the underlying handle is shared, it is possible that several workers query a handle with different backlogs. In this case, the first `backlog` passed to the master process will be used. Starting an IPC server as root may cause the server path to be inaccessible for unprivileged users. Using `readableAll` and `writableAll` will make the server accessible for all users. If the `signal` option is enabled, calling `.abort()` on the corresponding `AbortController` is similar to calling `.close()` on the server: ```js const controller = new AbortController(); server.listen({ host: 'localhost', port: 80, signal: controller.signal, }); // Later, when you want to close the server. controller.abort(); ``` #### `server.listen(path[, backlog][, callback])` \* `path` {string} Path the server should listen to. See [Identifying paths for IPC connections][]. \* `backlog` {number} Common parameter of [`server.listen()`][] functions. \* `callback` {Function}. \* Returns: {net.Server} Start an [IPC][] server listening for connections on the given `path`. #### `server.listen([port[, host[, backlog]]][, callback])` \* `port` {number} \* `host` {string} \* `backlog` {number} Common parameter of [`server.listen()`][] functions. \* `callback` {Function}. \* Returns: {net.Server} Start a TCP server listening for connections on the given `port` and `host`. If `port` is omitted or is 0, the operating system will assign an arbitrary unused port, which can be retrieved by using `server.address().port` after the [`'listening'`][] event has been emitted. If `host` is omitted, the server will accept connections on the [unspecified IPv6 address][] (`::`) when IPv6 is available, or the [unspecified IPv4 address][] (`0.0.0.0`) otherwise. In most operating systems, listening to the [unspecified IPv6 address][] (`::`) may cause the `net.Server` to also listen on the [unspecified IPv4 address][] (`0.0.0.0`). ### `server.listening` \* Type: {boolean} Indicates whether or not the server is listening for connections. ### `server.maxConnections` \* Type: {integer} When the number of connections reaches the `server.maxConnections` threshold: 1. If the process is not running in cluster mode, Node.js will close the connection. 2. If the process is running in cluster mode, Node.js will, by default, route the connection to another worker process. To close the connection instead, set \[`server.dropMaxConnection`]\[] to `true`. It is not recommended to use this option once a socket
|
https://github.com/nodejs/node/blob/main//doc/api/net.md
|
main
|
nodejs
|
[
-0.01739218458533287,
0.007805952336639166,
-0.05625748634338379,
-0.045896824449300766,
-0.05803341418504715,
-0.0013024797663092613,
0.026160184293985367,
0.01004226878285408,
0.04409290850162506,
0.0003995338047388941,
0.006522211711853743,
-0.010959845967590809,
0.011962736025452614,
-0.052773598581552505,
0.07150211185216904,
0.02202865481376648,
0.049201879650354385,
-0.043883953243494034,
0.019045453518629074,
0.029785573482513428,
-0.05268874764442444,
-0.015217769891023636,
-0.016197701916098595,
-0.08564348518848419,
-0.07723710685968399,
-0.04460536688566208,
-0.0223101619631052,
-0.026420651003718376,
0.032108258455991745,
0.026369722560048103,
-0.07055164873600006,
0.07872544974088669,
-0.09249471873044968,
0.04124646261334419,
0.005685701500624418,
0.09587747603654861,
0.13249820470809937,
-0.10494319349527359,
-0.139003723859787,
0.11022981256246567,
0.08586860448122025,
-0.023609314113855362,
-0.02440098114311695,
-0.07343413680791855,
-0.08659470826387405,
-0.018749147653579712,
-0.03154086694121361,
-0.034849148243665695,
-0.05518808960914612,
-0.03488439321517944,
-0.04050484299659729,
0.04430132731795311,
0.03670066222548485,
0.00396614708006382,
0.030500590801239014,
-0.030886707827448845,
-0.021561414003372192,
0.06280043721199036,
-0.020827874541282654,
0.004841533489525318,
-0.011083164252340794,
0.01645636186003685,
-0.008401726372539997,
0.0308696161955595,
-0.04025983437895775,
-0.010472121648490429,
-0.0244499109685421,
-0.02687659300863743,
-0.04802727326750755,
0.09995060414075851,
-0.1415012776851654,
-0.043900296092033386,
-0.09002311527729034,
0.03502182289958,
0.0638793557882309,
0.05592629685997963,
0.007123775780200958,
-0.08159269392490387,
0.007860561832785606,
-0.10468465834856033,
-0.05810048058629036,
-0.020379817113280296,
-0.1286465972661972,
-0.019856533035635948,
-0.04396510124206543,
0.04115881398320198,
-0.048520926386117935,
-0.044233039021492004,
0.11377983540296555,
0.058091405779123306,
-0.022245194762945175,
-0.059158891439437866,
-0.01226041465997696,
0.030615484341979027,
-0.022370897233486176,
0.026909684762358665,
-0.020646121352910995,
0.06318154186010361,
-0.052720677107572556,
0.0037470560055226088,
-0.029966240748763084,
0.05114451423287392,
0.02049541473388672,
0.05737028270959854,
-0.02431785874068737,
-0.0034572710283100605,
-0.001611658139154315,
-0.07014141976833344,
-0.01923300512135029,
-0.06463060528039932,
-0.019280845299363136,
-0.02396477200090885,
0.047838304191827774,
-0.1339869350194931,
-0.05641424283385277,
0.05112556740641594,
0.027932126075029373,
-0.007844300009310246,
-0.061231035739183426,
0.027231093496084213,
-0.04120557755231857,
-0.1103016659617424,
-0.03309379890561104,
0.08369213342666626,
0.025979282334446907,
-0.01195023488253355,
0.01847781427204609,
3.409982746092743e-33,
-0.010104510001838207,
-0.04951630160212517,
0.03547775372862816,
0.011762989684939384,
0.03204290196299553,
0.018322404474020004,
-0.019065776839852333,
0.037686627358198166,
-0.10147275030612946,
0.08271081745624542,
0.011759287677705288,
-0.03823072835803032,
0.030679747462272644,
-0.007845323532819748,
-0.006251523736864328,
0.030338335782289505,
0.0675511360168457,
0.04207859933376312,
0.08954539149999619,
0.012467187829315662,
0.03518949821591377,
-0.033832669258117676,
-0.006544454023241997,
-0.11994358897209167,
0.049641646444797516,
-0.004815427120774984,
-0.040024347603321075,
0.011349759064614773,
0.05227619782090187,
-0.004286385606974363,
0.05522006005048752,
0.0034165873657912016,
0.07168794423341751,
0.00376929366029799,
-0.032613448798656464,
0.009082603268325329,
-0.018354060128331184,
0.053422246128320694,
-0.06569956243038177,
-0.007303822319954634,
-0.012552772648632526,
-0.03091387264430523,
-0.07332590222358704,
0.03488865867257118,
0.05421927571296692,
-0.08809683471918106,
-0.07033345103263855,
0.016158245503902435,
0.03052264265716076,
-0.08169013261795044,
0.03529846668243408,
0.04646369442343712,
0.02908569760620594,
0.06214289739727974,
0.059628020972013474,
-0.029619907960295677,
-0.07164109498262405,
0.03024536371231079,
-0.04260896146297455,
0.036480862647295,
-0.005805544089525938,
0.04489629715681076,
-0.034182358533144,
0.03468617424368858,
0.125702902674675,
0.05450001358985901,
0.043236009776592255,
0.024261973798274994,
-0.02610616572201252,
-0.015533212572336197,
-0.026161935180425644,
-0.008146893233060837,
-0.05199432745575905,
0.09529677778482437,
-0.013672761619091034,
0.002067424589768052,
-0.0024342434480786324,
-0.033813800662755966,
0.08350477367639542,
0.025228450074791908,
-0.04250276833772659,
0.005894067231565714,
-0.03930206596851349,
0.05543278530240059,
-0.021795671433210373,
-0.05500888451933861,
-0.005924779921770096,
-0.018462417647242546,
-0.00648037763312459,
-0.0879792869091034,
0.05073061212897301,
0.012384450063109398,
0.10980933159589767,
-0.008171922527253628,
-0.07193329185247421,
-6.1188033157291456e-33,
0.003846760606393218,
0.022454477846622467,
-0.12784747779369354,
-0.03704916685819626,
-0.0313262864947319,
-0.02608131617307663,
0.060546085238456726,
-0.030879691243171692,
-0.038126274943351746,
-0.04609245806932449,
0.030749566853046417,
-0.01640092395246029,
0.04604540020227432,
-0.06677824258804321,
-0.014316456392407417,
0.0018136396538466215,
-0.10366243869066238,
-0.03729142248630524,
-0.0918237715959549,
0.02120536006987095,
-0.03277182951569557,
-0.005670457612723112,
0.12064260244369507,
0.04041777178645134,
-0.07644069194793701,
-0.01368706114590168,
0.01605413854122162,
0.03133056312799454,
-0.14146344363689423,
-0.01119491457939148,
0.03506140783429146,
0.06877546012401581,
-0.04325046017765999,
0.026465333998203278,
-0.019353095442056656,
-0.005228853318840265,
-0.0012630963465198874,
0.08052970468997955,
0.10680434107780457,
0.019663924351334572,
0.0427214689552784,
0.019626587629318237,
-0.07743176817893982,
0.03598933666944504,
-0.017685094848275185,
0.05736926943063736,
-0.0022697499953210354,
-0.028901785612106323,
0.019587522372603416,
-0.014112502336502075,
-0.031466640532016754,
-0.05879095569252968,
0.010207504965364933,
0.07180570065975189,
0.042500097304582596,
0.11048068851232529,
-0.02184230089187622,
0.03102264367043972,
0.03484852984547615,
0.028920842334628105,
0.041287120431661606,
-0.05557016283273697,
-0.021943140774965286,
0.07561949640512466,
0.051879774779081345,
0.02117861807346344,
-0.024178454652428627,
0.0614396370947361,
0.02731097862124443,
-0.06969305872917175,
0.024162262678146362,
-0.006131648551672697,
-0.03997379168868065,
0.05098710209131241,
-0.023792516440153122,
0.03479751944541931,
0.030875155702233315,
0.011040461249649525,
-0.008264515548944473,
0.14789098501205444,
-0.059337373822927475,
0.029590368270874023,
-0.11249329894781113,
0.03075387515127659,
0.02834012173116207,
-0.021946869790554047,
-0.002532810438424349,
0.007010427303612232,
0.0076371789909899235,
-0.026665812358260155,
0.0005748214898630977,
0.027068736031651497,
-0.04989377409219742,
0.028016377240419388,
0.018595293164253235,
-5.955788751066393e-8,
0.04528558999300003,
-0.03657861053943634,
-0.048728685826063156,
-0.03696426749229431,
0.01693899556994438,
-0.00182249303907156,
-0.04150997847318649,
-0.085638128221035,
-0.03688152879476547,
0.0744677186012268,
-0.05723852664232254,
0.044215209782123566,
-0.036309681832790375,
-0.01591210998594761,
0.06071595847606659,
-0.05860867723822594,
-0.01724538393318653,
-0.07447514683008194,
-0.03266679123044014,
-0.08985273540019989,
0.0542818047106266,
-0.030950667336583138,
0.006626870948821306,
0.03768786042928696,
-0.033597931265830994,
-0.09639634937047958,
0.005988303571939468,
0.0026529263705015182,
-0.03367929905653,
0.01874110847711563,
0.02775338850915432,
-0.014162322506308556,
-0.011553402990102768,
0.020838437601923943,
0.003626961959525943,
0.06981220841407776,
-0.03623056039214134,
0.04297569766640663,
0.02271956577897072,
0.060314979404211044,
-0.040368277579545975,
0.0031388644129037857,
-0.027481313794851303,
0.00668190186843276,
0.0020968569442629814,
0.0750974789261818,
0.024341687560081482,
0.08007169514894485,
0.02439918927848339,
0.053677935153245926,
0.008025177754461765,
0.03939083218574524,
0.08483153581619263,
-0.03359703719615936,
0.07372027635574341,
0.043523434549570084,
-0.09460346400737762,
0.08324335515499115,
0.0030848714523017406,
0.05551566183567047,
-0.03713392838835716,
0.08344145119190216,
0.002948220819234848,
-0.002035114448517561
] | 0.059387
|
not running in cluster mode, Node.js will close the connection. 2. If the process is running in cluster mode, Node.js will, by default, route the connection to another worker process. To close the connection instead, set \[`server.dropMaxConnection`]\[] to `true`. It is not recommended to use this option once a socket has been sent to a child with [`child\_process.fork()`][]. ### `server.dropMaxConnection` \* Type: {boolean} Set this property to `true` to begin closing connections once the number of connections reaches the \[`server.maxConnections`]\[] threshold. This setting is only effective in cluster mode. ### `server.ref()` \* Returns: {net.Server} Opposite of `unref()`, calling `ref()` on a previously `unref`ed server will \_not\_ let the program exit if it's the only server left (the default behavior). If the server is `ref`ed calling `ref()` again will have no effect. ### `server.unref()` \* Returns: {net.Server} Calling `unref()` on a server will allow the program to exit if this is the only active server in the event system. If the server is already `unref`ed calling `unref()` again will have no effect. ## Class: `net.Socket` \* Extends: {stream.Duplex} This class is an abstraction of a TCP socket or a streaming [IPC][] endpoint (uses named pipes on Windows, and Unix domain sockets otherwise). It is also an [`EventEmitter`][]. A `net.Socket` can be created by the user and used directly to interact with a server. For example, it is returned by [`net.createConnection()`][], so the user can use it to talk to the server. It can also be created by Node.js and passed to the user when a connection is received. For example, it is passed to the listeners of a [`'connection'`][] event emitted on a [`net.Server`][], so the user can use it to interact with the client. ### `new net.Socket([options])` \* `options` {Object} Available options are: \* `allowHalfOpen` {boolean} If set to `false`, then the socket will automatically end the writable side when the readable side ends. See [`net.createServer()`][] and the [`'end'`][] event for details. \*\*Default:\*\* `false`. \* `blockList` {net.BlockList} `blockList` can be used for disabling outbound access to specific IP addresses, IP ranges, or IP subnets. \* `fd` {number} If specified, wrap around an existing socket with the given file descriptor, otherwise a new socket will be created. \* `keepAlive` {boolean} If set to `true`, it enables keep-alive functionality on the socket immediately after the connection is established, similarly on what is done in [`socket.setKeepAlive()`][]. \*\*Default:\*\* `false`. \* `keepAliveInitialDelay` {number} If set to a positive number, it sets the initial delay before the first keepalive probe is sent on an idle socket. \*\*Default:\*\* `0`. \* `noDelay` {boolean} If set to `true`, it disables the use of Nagle's algorithm immediately after the socket is established. \*\*Default:\*\* `false`. \* `onread` {Object} If specified, incoming data is stored in a single `buffer` and passed to the supplied `callback` when data arrives on the socket. This will cause the streaming functionality to not provide any data. The socket will emit events like `'error'`, `'end'`, and `'close'` as usual. Methods like `pause()` and `resume()` will also behave as expected. \* `buffer` {Buffer|Uint8Array|Function} Either a reusable chunk of memory to use for storing incoming data or a function that returns such. \* `callback` {Function} This function is called for every chunk of incoming data. Two arguments are passed to it: the number of bytes written to `buffer` and a reference to `buffer`. Return `false` from this function to implicitly `pause()` the socket. This function will be executed in the global context. \* `readable` {boolean} Allow reads on the socket when an `fd` is passed, otherwise ignored. \*\*Default:\*\* `false`. \* `signal` {AbortSignal} An Abort signal that may be used
|
https://github.com/nodejs/node/blob/main//doc/api/net.md
|
main
|
nodejs
|
[
-0.05650927871465683,
-0.0472991056740284,
-0.0109292296692729,
0.04758472368121147,
0.028881261125206947,
-0.053663622587919235,
0.015295460820198059,
0.003324291203171015,
-0.0054885270074009895,
0.033878155052661896,
-0.03673586994409561,
0.05773322284221649,
-0.018649796023964882,
-0.03677142411470413,
-0.030472805723547935,
0.03950176760554314,
0.053947534412145615,
-0.02750055491924286,
-0.0007106114062480628,
-0.07063906639814377,
-0.01579987071454525,
-0.05125562474131584,
0.031228721141815186,
-0.007954181171953678,
-0.040032390505075455,
-0.0008915495709516108,
-0.026504622772336006,
-0.07573280483484268,
0.028787115588784218,
0.009529688395559788,
-0.03685146942734718,
0.014188982546329498,
-0.11631196737289429,
0.004349124152213335,
0.04673076793551445,
0.15323473513126373,
0.003407713957130909,
-0.026348019018769264,
-0.0654197558760643,
0.0075478460639715195,
0.10362813621759415,
0.05509847775101662,
-0.07396428287029266,
-0.051401201635599136,
-0.020259743556380272,
0.023224065080285072,
-0.11785141378641129,
-0.04837287217378616,
-0.03910675644874573,
-0.047724246978759766,
-0.007126459386199713,
0.05870442092418671,
0.03229726850986481,
0.06906773149967194,
0.03728936240077019,
0.004561384208500385,
0.022756610065698624,
-0.0353311151266098,
-0.00879989005625248,
0.05607267841696739,
0.0035645950119942427,
-0.02888689562678337,
-0.01589004509150982,
-0.03548559173941612,
0.03337564691901207,
0.04028802737593651,
0.02484748698771,
-0.026532039046287537,
-0.006352969445288181,
0.04784846305847168,
0.03143993765115738,
0.033962324261665344,
-0.05804382637143135,
-0.00451565021649003,
0.0036972418893128633,
-0.0306693185120821,
0.006160827819257975,
-0.05802347511053085,
-0.05599939078092575,
0.06364335864782333,
-0.06639271229505539,
-0.0373946875333786,
-0.0034161354415118694,
-0.004268352407962084,
-0.10464219748973846,
0.025252556428313255,
-0.03606438264250755,
-0.0820235013961792,
0.08117423206567764,
0.005786107853055,
-0.054281339049339294,
0.1261303573846817,
-0.012061327695846558,
0.08042851835489273,
0.00813327357172966,
0.04153060168027878,
-0.020455829799175262,
-0.005302209872752428,
-0.0347965769469738,
0.008517161943018436,
0.030563419684767723,
-0.04785826802253723,
-0.00021984880731906742,
-0.0153250303119421,
0.009974392130970955,
-0.04607781395316124,
-0.026199622079730034,
-0.024885041639208794,
0.012825524434447289,
0.007996145635843277,
0.018547799438238144,
0.04457502067089081,
0.03654380515217781,
0.07544425129890442,
-0.06695608794689178,
0.08534069359302521,
0.11295347660779953,
0.004257016349583864,
-0.013765141367912292,
0.10177111625671387,
0.06447755545377731,
0.05244170129299164,
-0.03218672797083855,
0.015196266584098339,
-0.01695021614432335,
-0.02580227516591549,
-0.014111136086285114,
1.6765120836618244e-33,
-0.04836137965321541,
-0.14009033143520355,
-0.014065496623516083,
-0.02382657304406166,
0.10546382516622543,
-0.02231956459581852,
-0.03365052118897438,
0.02785973623394966,
-0.0525328628718853,
0.0035538377705961466,
-0.0747041255235672,
-0.043999575078487396,
0.052477750927209854,
-0.04685588181018829,
0.008142665959894657,
-0.05811687931418419,
0.12120850384235382,
0.03469512239098549,
0.0795445442199707,
-0.006904250476509333,
0.04126156494021416,
-0.056224651634693146,
-0.051173899322748184,
0.07836004346609116,
-0.008784506469964981,
-0.019352884963154793,
-0.03524884954094887,
-0.007684668060392141,
0.030333921313285828,
0.0018572020344436169,
-0.039405327290296555,
0.02925097942352295,
-0.013242053799331188,
0.008502352051436901,
-0.044110193848609924,
0.029921788722276688,
-0.010534624569118023,
0.00039444834692403674,
-0.04416907578706741,
-0.05793563276529312,
-0.049424368888139725,
0.03642991557717323,
-0.09083005785942078,
0.037078019231557846,
0.016958314925432205,
-0.0858607366681099,
-0.018132120370864868,
-0.051746565848588943,
-0.011840001679956913,
-0.0008879941306076944,
0.026186903938651085,
-0.05009881407022476,
0.05572355166077614,
-0.012305771932005882,
-0.03187381848692894,
0.05518019571900368,
-0.0009588343091309071,
0.03931395336985588,
-0.025217007845640182,
0.03194586560130119,
0.05279168486595154,
-0.08918529748916626,
-0.04692916199564934,
-0.01449325680732727,
0.066986583173275,
0.010139222256839275,
-0.006936157587915659,
0.044559452682733536,
-0.015407092869281769,
0.020100053399801254,
-0.08989998698234558,
0.0898723378777504,
-0.020013611763715744,
-0.004724507220089436,
-0.0008177655399776995,
-0.013738315552473068,
0.012136925011873245,
0.009006407111883163,
-0.02271854318678379,
-0.024102697148919106,
0.08480963855981827,
0.03796044737100601,
-0.05632108077406883,
-0.0210501067340374,
0.02328237146139145,
-0.022277409210801125,
-0.0018684385577216744,
0.0019445914076641202,
-0.010232233442366123,
0.019580431282520294,
-0.014491687528789043,
-0.040650516748428345,
0.07511556893587112,
0.017805039882659912,
-0.04179747402667999,
-3.455972860542711e-33,
-0.026148807257413864,
-0.005491999909281731,
-0.07823333144187927,
0.033171359449625015,
0.011670955456793308,
-0.024930009618401527,
0.01680584065616131,
-0.0026780141051858664,
-0.036299966275691986,
-0.012834333814680576,
0.07462608814239502,
0.0003965478972531855,
0.01974664442241192,
0.04576169699430466,
-0.08242970705032349,
0.0005766561371274292,
0.03341944143176079,
-0.004727583844214678,
0.03963509574532509,
0.026412606239318848,
-0.0373881533741951,
-0.042551565915346146,
0.01950911246240139,
-0.030709100887179375,
-0.042685624212026596,
-0.029433758929371834,
-0.09615140408277512,
-0.03243564814329147,
-0.0742582157254219,
-0.0056619830429553986,
0.005374170374125242,
-0.016184382140636444,
0.002016955055296421,
0.09127482771873474,
0.03145408257842064,
-0.002324281493201852,
-0.06187731400132179,
0.03634187951683998,
0.06614811718463898,
0.0029845288954675198,
0.11565066128969193,
-0.0004322333843447268,
-0.0503314808011055,
0.022165166214108467,
0.05527501925826073,
0.017773332074284554,
-0.02211299166083336,
-0.03861263394355774,
-0.117378830909729,
0.01638769917190075,
-0.049775298684835434,
-0.012883933261036873,
0.05882978439331055,
0.10190756618976593,
-0.028549090027809143,
0.01115566585212946,
0.06630338728427887,
0.025921933352947235,
0.018630720674991608,
-0.02810027077794075,
0.14841100573539734,
-0.14307239651679993,
-0.07612309604883194,
0.07807140797376633,
0.032686665654182434,
-0.05807117000222206,
-0.06677602231502533,
0.03567861393094063,
0.034860383719205856,
0.0007339590229094028,
-0.007917995564639568,
0.17493118345737457,
0.004166529513895512,
0.04980338364839554,
-0.09916944056749344,
-0.00042236875742673874,
0.007919888012111187,
-0.06787753105163574,
-0.022185754030942917,
0.08405182510614395,
-0.12397344410419464,
0.09866133332252502,
-0.08993227034807205,
0.034874364733695984,
0.02725697122514248,
-0.0025300527922809124,
0.02201557718217373,
0.03328731283545494,
0.02264500968158245,
0.03764205053448677,
-0.06656831502914429,
-0.06200699135661125,
-0.0015585795044898987,
-0.0552901066839695,
-0.09506652504205704,
-4.807901987646801e-8,
0.0486680306494236,
0.010646951384842396,
-0.037554893642663956,
0.02144484780728817,
0.07170245051383972,
0.025215139612555504,
-0.02436346933245659,
-0.005439504981040955,
-0.013408346101641655,
0.09003464132547379,
-0.004733044654130936,
0.009932233951985836,
0.008430990390479565,
0.014342088252305984,
0.09168601036071777,
0.0007645434816367924,
0.07926952093839645,
-0.03073146753013134,
0.04463670775294304,
-0.044433899223804474,
-0.0043160319328308105,
-0.037297721952199936,
-0.032560642808675766,
0.1183992475271225,
-0.06586233526468277,
-0.04994955286383629,
0.1319744735956192,
0.036802466958761215,
-0.11571792513132095,
-0.05258379131555557,
-0.11932145804166794,
-0.01868409290909767,
0.022809011861681938,
0.04710998758673668,
-0.07825665175914764,
0.0965726375579834,
-0.08282690495252609,
0.047300294041633606,
0.029758334159851074,
0.0847339779138565,
0.007942316122353077,
0.055843427777290344,
-0.05610089376568794,
0.016369719058275223,
0.04147147759795189,
0.053487811237573624,
0.05665786564350128,
0.09398932754993439,
0.02857034094631672,
0.04275524616241455,
0.014500248245894909,
-0.027135465294122696,
-0.033424776047468185,
0.007893910631537437,
0.01386710163205862,
-0.025178708136081696,
-0.007364850491285324,
-0.01748555526137352,
-0.047507140785455704,
0.0011600116267800331,
0.015612962655723095,
0.06004190444946289,
-0.03897257149219513,
-0.07553602010011673
] | 0.099807
|
a reference to `buffer`. Return `false` from this function to implicitly `pause()` the socket. This function will be executed in the global context. \* `readable` {boolean} Allow reads on the socket when an `fd` is passed, otherwise ignored. \*\*Default:\*\* `false`. \* `signal` {AbortSignal} An Abort signal that may be used to destroy the socket. \* `writable` {boolean} Allow writes on the socket when an `fd` is passed, otherwise ignored. \*\*Default:\*\* `false`. \* Returns: {net.Socket} Creates a new socket object. The newly created socket can be either a TCP socket or a streaming [IPC][] endpoint, depending on what it [`connect()`][`socket.connect()`] to. ### Event: `'close'` \* `hadError` {boolean} `true` if the socket had a transmission error. Emitted once the socket is fully closed. The argument `hadError` is a boolean which says if the socket was closed due to a transmission error. ### Event: `'connect'` Emitted when a socket connection is successfully established. See [`net.createConnection()`][]. ### Event: `'connectionAttempt'` \* `ip` {string} The IP which the socket is attempting to connect to. \* `port` {number} The port which the socket is attempting to connect to. \* `family` {number} The family of the IP. It can be `6` for IPv6 or `4` for IPv4. Emitted when a new connection attempt is started. This may be emitted multiple times if the family autoselection algorithm is enabled in [`socket.connect(options)`][]. ### Event: `'connectionAttemptFailed'` \* `ip` {string} The IP which the socket attempted to connect to. \* `port` {number} The port which the socket attempted to connect to. \* `family` {number} The family of the IP. It can be `6` for IPv6 or `4` for IPv4. \* `error` {Error} The error associated with the failure. Emitted when a connection attempt failed. This may be emitted multiple times if the family autoselection algorithm is enabled in [`socket.connect(options)`][]. ### Event: `'connectionAttemptTimeout'` \* `ip` {string} The IP which the socket attempted to connect to. \* `port` {number} The port which the socket attempted to connect to. \* `family` {number} The family of the IP. It can be `6` for IPv6 or `4` for IPv4. Emitted when a connection attempt timed out. This is only emitted (and may be emitted multiple times) if the family autoselection algorithm is enabled in [`socket.connect(options)`][]. ### Event: `'data'` \* Type: {Buffer|string} Emitted when data is received. The argument `data` will be a `Buffer` or `String`. Encoding of data is set by [`socket.setEncoding()`][]. The data will be lost if there is no listener when a `Socket` emits a `'data'` event. ### Event: `'drain'` Emitted when the write buffer becomes empty. Can be used to throttle uploads. See also: the return values of `socket.write()`. ### Event: `'end'` Emitted when the other end of the socket signals the end of transmission, thus ending the readable side of the socket. By default (`allowHalfOpen` is `false`) the socket will send an end of transmission packet back and destroy its file descriptor once it has written out its pending write queue. However, if `allowHalfOpen` is set to `true`, the socket will not automatically [`end()`][`socket.end()`] its writable side, allowing the user to write arbitrary amounts of data. The user must call [`end()`][`socket.end()`] explicitly to close the connection (i.e. sending a FIN packet back). ### Event: `'error'` \* Type: {Error} Emitted when an error occurs. The `'close'` event will be called directly following this event. ### Event: `'lookup'` Emitted after resolving the host name but before connecting. Not applicable to Unix sockets. \* `err` {Error|null} The error object. See [`dns.lookup()`][]. \* `address` {string} The IP address. \* `family` {number|null} The address type. See [`dns.lookup()`][]. \* `host` {string} The host name. ### Event: `'ready'` Emitted when
|
https://github.com/nodejs/node/blob/main//doc/api/net.md
|
main
|
nodejs
|
[
-0.04400864988565445,
0.0075232540257275105,
-0.07286310940980911,
0.06316094845533371,
0.028457945212721825,
-0.03188776224851608,
0.04257421940565109,
0.0017287521623075008,
0.03680441901087761,
0.02763749286532402,
0.016491085290908813,
0.08494078367948532,
-0.04042983800172806,
-0.008763440884649754,
-0.06076539307832718,
-0.05044214800000191,
0.05940187722444534,
-0.020752672106027603,
-0.0033368521835654974,
-0.037956129759550095,
0.035470087081193924,
0.04506351426243782,
0.0037960042245686054,
-0.016155507415533066,
-0.0737052857875824,
-0.04841628670692444,
0.003159055020660162,
-0.04416641220450401,
0.01877083256840706,
0.031049562618136406,
-0.0461263470351696,
0.0028568601701408625,
-0.07543615996837616,
0.03577534109354019,
-0.013873724266886711,
0.04793638736009598,
0.05307940021157265,
-0.044293586164712906,
-0.1022656187415123,
-0.018137125298380852,
0.07559692859649658,
-0.023970527574419975,
-0.0888114869594574,
-0.05302085727453232,
-0.024135839194059372,
0.008209994994103909,
-0.04893718287348747,
-0.008303187787532806,
-0.054842498153448105,
-0.035315532237291336,
-0.03743519261479378,
0.08783215284347534,
-0.052280493080616,
0.05105043202638626,
0.1469341367483139,
-0.07001049816608429,
0.011900829151272774,
-0.006741504184901714,
-0.07723736017942429,
0.020044442266225815,
-0.044173650443553925,
-0.0211534034460783,
-0.033615995198488235,
0.04914861172437668,
0.049547549337148666,
0.058798983693122864,
-0.030493557453155518,
-0.00452808104455471,
0.04627995565533638,
0.025156375020742416,
-0.06596534699201584,
0.024632304906845093,
-0.11009076982736588,
0.03696289658546448,
0.039200980216264725,
-0.016886329278349876,
0.06097474321722984,
-0.02705935575067997,
-0.0471450611948967,
-0.009574164636433125,
-0.011865640990436077,
-0.09619411081075668,
-0.018210764974355698,
0.0002502832794561982,
0.012437543831765652,
0.04698764532804489,
-0.017534593120217323,
-0.004086203873157501,
0.032939136028289795,
0.04716062918305397,
-0.03156218305230141,
0.05379709601402283,
0.0039002345874905586,
0.1057676300406456,
0.043180931359529495,
0.0029750834219157696,
0.05546963959932327,
-0.01825110614299774,
-0.03562682121992111,
0.005213189870119095,
0.021547876298427582,
-0.004438287112861872,
-0.014106625691056252,
-0.027415020391345024,
0.04396709427237511,
-0.053041134029626846,
-0.0008208037470467389,
-0.025421466678380966,
-0.02207346260547638,
-0.061818093061447144,
-0.04582158476114273,
-0.019789062440395355,
0.038467902690172195,
0.008311532437801361,
-0.04249148815870285,
0.047982167452573776,
0.003827318549156189,
0.03884664922952652,
0.03171911835670471,
0.029683437198400497,
0.06558966636657715,
0.0009649002458900213,
-0.04335184022784233,
0.027874363586306572,
0.03595611825585365,
-0.04285750538110733,
0.0022263857536017895,
2.4931228663902826e-33,
-0.025018660351634026,
-0.07465679198503494,
-0.10194572061300278,
0.034100279211997986,
0.03918074816465378,
-0.015978176146745682,
0.03582706302404404,
0.04861754924058914,
-0.055942635983228683,
0.06565455347299576,
-0.0375465527176857,
-0.05025585740804672,
0.026296347379684448,
-0.008377819322049618,
0.05728283151984215,
-0.011174419894814491,
0.06453857570886612,
0.010577864944934845,
0.08231472223997116,
0.013651501387357712,
0.09522682428359985,
-0.0517980195581913,
-0.0009173764265142381,
-0.011351709254086018,
-0.016454417258501053,
-0.004639309365302324,
-0.09650140255689621,
-0.011289778165519238,
0.0314902663230896,
0.025129878893494606,
-0.11118394881486893,
-0.019786527380347252,
0.06621415913105011,
-0.008431186899542809,
0.021982673555612564,
-0.05499885603785515,
-0.04574567824602127,
-0.06310825049877167,
-0.05176879093050957,
-0.05478178337216377,
-0.01940448023378849,
-0.0418364480137825,
-0.16677361726760864,
0.04858192801475525,
-0.009003551676869392,
-0.14144790172576904,
-0.13321352005004883,
0.0448409765958786,
0.030683256685733795,
0.07188418507575989,
0.06539242714643478,
0.07874320447444916,
0.05653619393706322,
0.009110507555305958,
0.03446705639362335,
-0.0454157218337059,
0.025775006040930748,
0.06456556916236877,
-0.009576607495546341,
0.08652611821889877,
0.041507501155138016,
0.013917174190282822,
-0.023785579949617386,
-0.01847037300467491,
0.012526017613708973,
0.04400215670466423,
0.012666731141507626,
-0.02858828566968441,
-0.020689666271209717,
-0.02052590809762478,
-0.09339335560798645,
0.015535109676420689,
-0.03748658299446106,
0.018011098727583885,
-0.027704894542694092,
0.03723585605621338,
-0.04209354147315025,
-0.02474801428616047,
0.036868222057819366,
-0.05720703676342964,
0.08157946169376373,
-0.0019717381801456213,
-0.06578239798545837,
-0.018606074154376984,
-0.05661669373512268,
0.006719160825014114,
-0.015413843095302582,
-0.050532858818769455,
-0.027068572118878365,
-0.06888452172279358,
-0.02736201137304306,
-0.021447204053401947,
0.08167372643947601,
-0.0127309150993824,
-0.01935029774904251,
-4.82853369649257e-33,
-0.0232196357101202,
-0.011487085372209549,
-0.12390805780887604,
0.04091082140803337,
-0.07079256325960159,
-0.08250033855438232,
0.0019870575051754713,
-0.02672804333269596,
0.00048384949332103133,
-0.06963754445314407,
0.047722313553094864,
-0.0039006765000522137,
0.06432788819074631,
0.0344519168138504,
-0.011430645361542702,
-0.02591903693974018,
-0.014466535300016403,
-0.09633364528417587,
-0.0480499304831028,
0.051729634404182434,
-0.05072769522666931,
-0.0619564987719059,
0.08513160049915314,
-0.028044870123267174,
-0.09314197301864624,
0.06864409893751144,
-0.03033359721302986,
-0.03236072510480881,
-0.05860007926821709,
0.0013996270718052983,
0.03215670585632324,
0.03928903117775917,
-0.052402183413505554,
-0.0010355467675253749,
0.006410054862499237,
0.026608776301145554,
0.06812644004821777,
0.026912512257695198,
0.006850824691355228,
0.01988588273525238,
0.20839980244636536,
0.09918981045484543,
-0.00066622399026528,
-0.00041272418457083404,
0.03315625712275505,
0.07091014087200165,
-0.02838514931499958,
0.0027316201012581587,
-0.02262062393128872,
-0.020057689398527145,
0.042097900062799454,
0.0043766088783741,
0.0827917605638504,
0.09801927953958511,
-0.0055503943003714085,
0.029335560277104378,
0.11641250550746918,
-0.03903384134173393,
0.021965187042951584,
-0.03123885579407215,
0.07500376552343369,
-0.13307800889015198,
-0.053145766258239746,
0.03135021775960922,
0.020929424092173576,
0.0027497103437781334,
0.0035271078813821077,
0.003332301275804639,
0.05926380679011345,
-0.03067280910909176,
0.08403538167476654,
0.039046719670295715,
-0.030312901362776756,
0.04448539391160011,
-0.036649417132139206,
0.09249748289585114,
0.01018712017685175,
-0.04293033480644226,
-0.053678929805755615,
0.15612651407718658,
-0.07308647036552429,
0.07003729790449142,
-0.027875907719135284,
0.06836292892694473,
0.0028418609872460365,
-0.04543612524867058,
-0.0473753958940506,
-0.006915046367794275,
-0.0014896438224241138,
-0.045904528349637985,
-0.03124389424920082,
0.04360241815447807,
-0.06689082831144333,
0.008701255545020103,
-0.01028092298656702,
-5.651105183801519e-8,
-0.056485049426555634,
-0.04676944017410278,
-0.047400202602148056,
0.021006718277931213,
0.01754186861217022,
-0.02880551852285862,
-0.023253755643963814,
-0.11972983926534653,
0.04094775766134262,
0.042736299335956573,
-0.029427163302898407,
0.010267335921525955,
0.017460482195019722,
-0.048558734357357025,
0.05308302119374275,
0.04146115109324455,
-0.006966099608689547,
-0.03627869859337807,
0.016644956544041634,
-0.05918719246983528,
0.05466793105006218,
-0.04976733773946762,
-0.062197256833314896,
0.04462382569909096,
-0.013029104098677635,
-0.030693212524056435,
0.10108822584152222,
0.038502249866724014,
-0.08771435916423798,
-0.05279665067791939,
-0.0363379530608654,
-0.0032392588909715414,
0.08489794284105301,
0.07137604802846909,
-0.033662907779216766,
0.12602055072784424,
-0.010000763460993767,
0.042563363909721375,
0.01835501752793789,
0.09001785516738892,
0.0005539253470487893,
-0.024577131494879723,
-0.04542221128940582,
0.04256494715809822,
0.007654445245862007,
-0.0019126307452097535,
0.04300091415643692,
0.06328331679105759,
-0.03735531121492386,
0.03255569189786911,
-0.016111649572849274,
0.02161037176847458,
-0.008936204016208649,
0.02145828865468502,
0.00139354239217937,
-0.014476744458079338,
-0.015256823971867561,
-0.04342307895421982,
-0.04232606291770935,
0.01916927844285965,
0.03151927515864372,
0.12153307348489761,
0.0010240282863378525,
-0.03590782731771469
] | 0.181191
|
### Event: `'lookup'` Emitted after resolving the host name but before connecting. Not applicable to Unix sockets. \* `err` {Error|null} The error object. See [`dns.lookup()`][]. \* `address` {string} The IP address. \* `family` {number|null} The address type. See [`dns.lookup()`][]. \* `host` {string} The host name. ### Event: `'ready'` Emitted when a socket is ready to be used. Triggered immediately after `'connect'`. ### Event: `'timeout'` Emitted if the socket times out from inactivity. This is only to notify that the socket has been idle. The user must manually close the connection. See also: [`socket.setTimeout()`][]. ### `socket.address()` \* Returns: {Object} Returns the bound `address`, the address `family` name and `port` of the socket as reported by the operating system: `{ port: 12346, family: 'IPv4', address: '127.0.0.1' }` ### `socket.autoSelectFamilyAttemptedAddresses` \* Type: {string\[]} This property is only present if the family autoselection algorithm is enabled in [`socket.connect(options)`][] and it is an array of the addresses that have been attempted. Each address is a string in the form of `$IP:$PORT`. If the connection was successful, then the last address is the one that the socket is currently connected to. ### `socket.bufferSize` > Stability: 0 - Deprecated: Use [`writable.writableLength`][] instead. \* Type: {integer} This property shows the number of characters buffered for writing. The buffer may contain strings whose length after encoding is not yet known. So this number is only an approximation of the number of bytes in the buffer. `net.Socket` has the property that `socket.write()` always works. This is to help users get up and running quickly. The computer cannot always keep up with the amount of data that is written to a socket. The network connection simply might be too slow. Node.js will internally queue up the data written to a socket and send it out over the wire when it is possible. The consequence of this internal buffering is that memory may grow. Users who experience large or growing `bufferSize` should attempt to "throttle" the data flows in their program with [`socket.pause()`][] and [`socket.resume()`][]. ### `socket.bytesRead` \* Type: {integer} The amount of received bytes. ### `socket.bytesWritten` \* Type: {integer} The amount of bytes sent. ### `socket.connect()` Initiate a connection on a given socket. Possible signatures: \* [`socket.connect(options[, connectListener])`][`socket.connect(options)`] \* [`socket.connect(path[, connectListener])`][`socket.connect(path)`] for [IPC][] connections. \* [`socket.connect(port[, host][, connectListener])`][`socket.connect(port)`] for TCP connections. \* Returns: {net.Socket} The socket itself. This function is asynchronous. When the connection is established, the [`'connect'`][] event will be emitted. If there is a problem connecting, instead of a [`'connect'`][] event, an [`'error'`][] event will be emitted with the error passed to the [`'error'`][] listener. The last parameter `connectListener`, if supplied, will be added as a listener for the [`'connect'`][] event \*\*once\*\*. This function should only be used for reconnecting a socket after `'close'` has been emitted or otherwise it may lead to undefined behavior. #### `socket.connect(options[, connectListener])` \* `options` {Object} \* `connectListener` {Function} Common parameter of [`socket.connect()`][] methods. Will be added as a listener for the [`'connect'`][] event once. \* Returns: {net.Socket} The socket itself. Initiate a connection on a given socket. Normally this method is not needed, the socket should be created and opened with [`net.createConnection()`][]. Use this only when implementing a custom Socket. For TCP connections, available `options` are: \* `autoSelectFamily` {boolean}: If set to `true`, it enables a family autodetection algorithm that loosely implements section 5 of [RFC 8305][]. The `all` option passed to lookup is set to `true` and the sockets attempts to connect to all obtained IPv6 and IPv4 addresses, in sequence, until a connection is established. The first returned AAAA address is tried first, then the first returned A address, then the
|
https://github.com/nodejs/node/blob/main//doc/api/net.md
|
main
|
nodejs
|
[
-0.1095583364367485,
0.01485124509781599,
-0.053188808262348175,
0.034626275300979614,
-0.04198075458407402,
-0.07729443907737732,
-0.03617118299007416,
-0.023049553856253624,
0.060760483145713806,
0.02043331228196621,
-0.022330543026328087,
0.06309857964515686,
-0.05169960856437683,
-0.017867786809802055,
-0.012008733116090298,
0.004792790859937668,
-0.002040764782577753,
-0.04071469604969025,
0.03448944911360741,
-0.06190807372331619,
-0.011667872779071331,
0.010531477630138397,
0.02438334748148918,
-0.032906122505664825,
-0.040238991379737854,
-0.06690554320812225,
0.047265857458114624,
0.02137722074985504,
0.023495076224207878,
0.09917495399713516,
-0.008103691972792149,
-0.009345147758722305,
-0.045859310775995255,
0.017959050834178925,
-0.009079773910343647,
0.05913400277495384,
0.03973560407757759,
0.05834579840302467,
-0.14118944108486176,
0.008133530616760254,
0.09971385449171066,
-0.01694616861641407,
0.032711829990148544,
-0.06905772536993027,
0.012217029929161072,
0.04294614866375923,
-0.00962697435170412,
0.0065511614084243774,
-0.004476774483919144,
-0.06452932208776474,
-0.046059753745794296,
0.03803955391049385,
-0.013566074892878532,
0.037173785269260406,
0.08881495147943497,
0.023542283102869987,
-0.044729217886924744,
-0.004539891611784697,
-0.0058889384381473064,
-0.0074272495694458485,
-0.016634080559015274,
0.0070739309303462505,
0.005822382867336273,
-0.021682066842913628,
-0.006843584589660168,
0.029408125206828117,
0.033828623592853546,
-0.02110867202281952,
0.002928262809291482,
0.0905357226729393,
0.0077550471760332584,
0.08827220648527145,
-0.07362852245569229,
-0.02600477635860443,
-0.01538044773042202,
-0.02513054758310318,
0.03914429992437363,
-0.06757260113954544,
-0.03765864670276642,
0.026295939460396767,
-0.01932724379003048,
-0.020568083971738815,
-0.0934801995754242,
0.058574430644512177,
-0.08058841526508331,
0.016476942226290703,
-0.004818592686206102,
0.00459298025816679,
-0.043495893478393555,
0.01640058122575283,
-0.05529884994029999,
-0.016521651297807693,
-0.02679225243628025,
0.012267823331058025,
0.007756971754133701,
0.05166911333799362,
0.08548212051391602,
0.0570220984518528,
-0.06653302907943726,
-0.004838824272155762,
0.02250881865620613,
-0.015740100294351578,
-0.030525432899594307,
-0.05058286339044571,
0.0032393774017691612,
0.013534629717469215,
-0.03157711774110794,
0.0054400586523115635,
0.0684913843870163,
0.009310508146882057,
-0.0091630220413208,
-0.04423481971025467,
0.038565684109926224,
0.049236468970775604,
-0.08939943462610245,
0.05382372811436653,
-0.005515762139111757,
0.03613903746008873,
0.013941649347543716,
0.015915630385279655,
0.1169683188199997,
-0.021745167672634125,
-0.06808875501155853,
-0.08426745235919952,
0.006571165286004543,
-0.001117192441597581,
0.056149497628211975,
1.3318225180186781e-33,
0.014377787709236145,
-0.03933645784854889,
-0.056194741278886795,
0.03137313574552536,
0.01324826292693615,
-0.04214402660727501,
0.009824348613619804,
0.05780624970793724,
-0.07686374336481094,
0.07115989923477173,
-0.04131670668721199,
-0.014468969777226448,
0.05533697456121445,
-0.06623867154121399,
-0.04501890391111374,
0.03802357241511345,
0.10226660966873169,
0.03717862442135811,
0.09792782366275787,
0.10048194229602814,
0.008056102320551872,
-0.11635299772024155,
-0.00006127222877694294,
0.035737305879592896,
0.015821680426597595,
0.058749932795763016,
-0.07043374329805374,
-0.016933398321270943,
-0.02729928120970726,
-0.027692116796970367,
0.010892960242927074,
-0.003228184999898076,
-0.02684953436255455,
-0.021125569939613342,
0.018795641139149666,
-0.11272069811820984,
0.04169206693768501,
0.010075327008962631,
-0.08998440951108932,
-0.08252350240945816,
0.017155319452285767,
-0.013402245007455349,
-0.16865387558937073,
0.10030234605073929,
0.024281157180666924,
-0.02449248731136322,
-0.07434210926294327,
-0.03873743116855621,
0.06718698889017105,
0.0742257684469223,
0.014156184159219265,
-0.011960083618760109,
0.039638374000787735,
0.013958849012851715,
0.03787938877940178,
0.0297068003565073,
-0.004673692863434553,
0.07010438293218613,
-0.03733889386057854,
-0.0026725721545517445,
-0.0009714735206216574,
-0.06167776510119438,
-0.026704642921686172,
-0.01367961149662733,
0.08600249886512756,
-0.016265615820884705,
0.010895416140556335,
-0.007959989830851555,
-0.05916872248053551,
0.021514303982257843,
-0.007704327814280987,
0.0787430927157402,
-0.07031741738319397,
0.06508833169937134,
-0.04538564011454582,
0.02908996120095253,
-0.0036529768258333206,
-0.03477490320801735,
-0.023110635578632355,
0.012218080461025238,
0.07044174522161484,
0.00300134951248765,
-0.0017092761117964983,
-0.01975320465862751,
-0.04294828698039055,
0.05874619260430336,
-0.016141217201948166,
-0.0008563942974433303,
-0.07106167823076248,
-0.011732522398233414,
-0.02851806953549385,
0.023112451657652855,
0.09432785958051682,
-0.02209126017987728,
-0.0654006078839302,
-4.144641368759733e-33,
-0.015724508091807365,
-0.04503319039940834,
-0.10974562168121338,
-0.012622220441699028,
0.019166013225913048,
-0.08227072656154633,
-0.003356297267600894,
0.03428215906023979,
-0.024323828518390656,
-0.07906486839056015,
0.04966997355222702,
-0.02572460286319256,
0.07390745729207993,
-0.04111402854323387,
0.006712006404995918,
0.05952725559473038,
-0.015336863696575165,
-0.014480759389698505,
-0.032680146396160126,
0.02130776457488537,
-0.06091693043708801,
0.029621940106153488,
0.024535896256566048,
-0.07411166280508041,
-0.11476162075996399,
0.021549079567193985,
0.049954693764448166,
-0.019978635013103485,
-0.1275915950536728,
-0.012442074716091156,
0.050746675580739975,
0.0032044779509305954,
-0.056872714310884476,
0.0877009853720665,
-0.015774095430970192,
0.11122746765613556,
0.02435322292149067,
-0.015561649575829506,
0.07270822674036026,
0.015316465869545937,
0.15884383022785187,
0.06320922076702118,
-0.07009332627058029,
0.008607465773820877,
-0.029433488845825195,
0.043539758771657944,
-0.043785661458969116,
0.05133533477783203,
-0.05304819718003273,
0.0731506273150444,
0.043784916400909424,
-0.02854752354323864,
0.046111978590488434,
0.05737357214093208,
0.05500180274248123,
0.052346158772706985,
0.05978967249393463,
-0.007975716143846512,
0.030675895512104034,
0.032821495085954666,
0.06169627234339714,
-0.1649482399225235,
-0.04184636473655701,
0.14800021052360535,
-0.02551514096558094,
0.04037578031420708,
-0.05142669379711151,
0.04729747772216797,
0.1221417710185051,
-0.03796854242682457,
0.06274120509624481,
-0.014416222460567951,
-0.06911512464284897,
0.05420524999499321,
-0.03679614141583443,
0.08544207364320755,
0.011112568899989128,
0.005132114514708519,
-0.0091727739199996,
0.08943792432546616,
-0.09684445708990097,
0.07120460271835327,
-0.060328830033540726,
-0.0030431009363383055,
0.014796830713748932,
0.030301542952656746,
0.005177694838494062,
0.1190415620803833,
0.023828601464629173,
-0.008595523424446583,
-0.0247688889503479,
-0.000459052505902946,
-0.04888138175010681,
-0.03144412860274315,
-0.06356961280107498,
-4.82716941974104e-8,
0.010239698924124241,
0.002621234627440572,
-0.019666027277708054,
-0.012094405479729176,
0.0021941757295280695,
0.035030364990234375,
0.028037557378411293,
-0.08043783903121948,
0.0034334573429077864,
0.09385301172733307,
-0.05572497099637985,
-0.024509094655513763,
-0.0015305629931390285,
0.016377538442611694,
0.08550473302602768,
-0.003029170446097851,
0.004251196049153805,
0.010902763344347477,
-0.035818178206682205,
-0.058333899825811386,
0.04752615466713905,
-0.057678937911987305,
-0.05142122134566307,
-0.006232928019016981,
-0.08465847373008728,
-0.09623554348945618,
0.08656714111566544,
0.010855329222977161,
-0.08936874568462372,
-0.04045403376221657,
-0.0679149180650711,
0.030409453436732292,
0.009664767421782017,
-0.01155921258032322,
0.0020498905796557665,
0.05475112050771713,
-0.03546705096960068,
-0.00630916329100728,
0.03993941843509674,
0.023761199787259102,
-0.03722267225384712,
-0.04417407512664795,
-0.07512692362070084,
-0.004840134177356958,
-0.002229399047791958,
0.024844156578183174,
0.05711914598941803,
0.07361223548650742,
0.009875789284706116,
0.018616976216435432,
-0.014031903818249702,
-0.04921048507094383,
-0.017089255154132843,
-0.07187537103891373,
0.0215639416128397,
-0.03690342232584953,
-0.013565306551754475,
0.007024685386568308,
-0.022066526114940643,
-0.04165344685316086,
-0.014882676303386688,
0.08542611449956894,
-0.056891631335020065,
-0.008621473796665668
] | 0.099027
|
5 of [RFC 8305][]. The `all` option passed to lookup is set to `true` and the sockets attempts to connect to all obtained IPv6 and IPv4 addresses, in sequence, until a connection is established. The first returned AAAA address is tried first, then the first returned A address, then the second returned AAAA address and so on. Each connection attempt (but the last one) is given the amount of time specified by the `autoSelectFamilyAttemptTimeout` option before timing out and trying the next address. Ignored if the `family` option is not `0` or if `localAddress` is set. Connection errors are not emitted if at least one connection succeeds. If all connections attempts fails, a single `AggregateError` with all failed attempts is emitted. \*\*Default:\*\* [`net.getDefaultAutoSelectFamily()`][]. \* `autoSelectFamilyAttemptTimeout` {number}: The amount of time in milliseconds to wait for a connection attempt to finish before trying the next address when using the `autoSelectFamily` option. If set to a positive integer less than `10`, then the value `10` will be used instead. \*\*Default:\*\* [`net.getDefaultAutoSelectFamilyAttemptTimeout()`][]. \* `family` {number}: Version of IP stack. Must be `4`, `6`, or `0`. The value `0` indicates that both IPv4 and IPv6 addresses are allowed. \*\*Default:\*\* `0`. \* `hints` {number} Optional [`dns.lookup()` hints][]. \* `host` {string} Host the socket should connect to. \*\*Default:\*\* `'localhost'`. \* `localAddress` {string} Local address the socket should connect from. \* `localPort` {number} Local port the socket should connect from. \* `lookup` {Function} Custom lookup function. \*\*Default:\*\* [`dns.lookup()`][]. \* `port` {number} Required. Port the socket should connect to. For [IPC][] connections, available `options` are: \* `path` {string} Required. Path the client should connect to. See [Identifying paths for IPC connections][]. If provided, the TCP-specific options above are ignored. #### `socket.connect(path[, connectListener])` \* `path` {string} Path the client should connect to. See [Identifying paths for IPC connections][]. \* `connectListener` {Function} Common parameter of [`socket.connect()`][] methods. Will be added as a listener for the [`'connect'`][] event once. \* Returns: {net.Socket} The socket itself. Initiate an [IPC][] connection on the given socket. Alias to [`socket.connect(options[, connectListener])`][`socket.connect(options)`] called with `{ path: path }` as `options`. #### `socket.connect(port[, host][, connectListener])` \* `port` {number} Port the client should connect to. \* `host` {string} Host the client should connect to. \* `connectListener` {Function} Common parameter of [`socket.connect()`][] methods. Will be added as a listener for the [`'connect'`][] event once. \* Returns: {net.Socket} The socket itself. Initiate a TCP connection on the given socket. Alias to [`socket.connect(options[, connectListener])`][`socket.connect(options)`] called with `{port: port, host: host}` as `options`. ### `socket.connecting` \* Type: {boolean} If `true`, [`socket.connect(options[, connectListener])`][`socket.connect(options)`] was called and has not yet finished. It will stay `true` until the socket becomes connected, then it is set to `false` and the `'connect'` event is emitted. Note that the [`socket.connect(options[, connectListener])`][`socket.connect(options)`] callback is a listener for the `'connect'` event. ### `socket.destroy([error])` \* `error` {Object} \* Returns: {net.Socket} Ensures that no more I/O activity happens on this socket. Destroys the stream and closes the connection. See [`writable.destroy()`][] for further details. ### `socket.destroyed` \* Type: {boolean} Indicates if the connection is destroyed or not. Once a connection is destroyed no further data can be transferred using it. See [`writable.destroyed`][] for further details. ### `socket.destroySoon()` Destroys the socket after all data is written. If the `'finish'` event was already emitted the socket is destroyed immediately. If the socket is still writable it implicitly calls `socket.end()`. ### `socket.end([data[, encoding]][, callback])` \* `data` {string|Buffer|Uint8Array} \* `encoding` {string} Only used when data is `string`. \*\*Default:\*\* `'utf8'`. \* `callback` {Function} Optional callback for when the socket is finished. \* Returns: {net.Socket} The socket itself. Half-closes the socket. i.e., it sends a FIN packet. It is
|
https://github.com/nodejs/node/blob/main//doc/api/net.md
|
main
|
nodejs
|
[
-0.05408543720841408,
0.007791957817971706,
-0.005531516391783953,
0.03019201010465622,
-0.05308767035603523,
-0.00554471043869853,
-0.053792860358953476,
-0.07197354733943939,
0.05334501713514328,
-0.000567154202144593,
-0.014003820717334747,
0.011165305972099304,
-0.04353142902255058,
-0.046680182218551636,
-0.04001803696155548,
0.012303530238568783,
-0.00977399293333292,
-0.06792477518320084,
-0.031187724322080612,
-0.0295712947845459,
-0.03426656126976013,
0.02036803960800171,
-0.0019742820877581835,
-0.062006235122680664,
-0.0018073538085445762,
-0.04604298993945122,
-0.035876840353012085,
0.014354903250932693,
0.0436151959002018,
0.06347834318876266,
-0.047285206615924835,
0.0006627127295359969,
-0.10156983882188797,
0.04125048592686653,
0.006624539382755756,
0.0005874708876945078,
0.023455699905753136,
0.09383254498243332,
-0.05506487190723419,
-0.0009803046705201268,
0.0857749804854393,
-0.029751822352409363,
0.019485143944621086,
-0.021229445934295654,
0.020439380779862404,
0.03356221690773964,
-0.025442054495215416,
0.011502775363624096,
0.03849274292588234,
-0.06548887491226196,
-0.028775380924344063,
0.08308985829353333,
0.009162281639873981,
0.018951047211885452,
0.0888887271285057,
0.04265642911195755,
-0.07513627409934998,
0.02699279598891735,
0.003979545086622238,
0.08383852243423462,
0.013571393676102161,
-0.02444295398890972,
-0.04987771436572075,
0.03888619318604469,
0.04460175335407257,
0.009952794760465622,
0.04816417396068573,
-0.030935337767004967,
-0.01220011431723833,
0.058468688279390335,
-0.07776682078838348,
0.06590060889720917,
-0.14110705256462097,
0.09911075979471207,
0.031635917723178864,
0.0848250687122345,
-0.024514853954315186,
-0.11262080818414688,
0.035348329693078995,
-0.06949497759342194,
-0.034058574587106705,
-0.0035428456030786037,
-0.0334513895213604,
0.06355207413434982,
0.02180292457342148,
-0.027234114706516266,
0.01153765618801117,
-0.01897958293557167,
0.019369004294276237,
0.027375541627407074,
0.002889072522521019,
-0.0039248038083314896,
-0.003706349292770028,
0.02357938513159752,
0.12193010747432709,
0.09980379790067673,
0.07323749363422394,
-0.06467516720294952,
-0.016489703208208084,
-0.008531947620213032,
0.03641906753182411,
-0.05385806784033775,
-0.05116031691431999,
-0.033600013703107834,
0.029751522466540337,
-0.06511948257684708,
-0.035637639462947845,
0.015232394449412823,
0.02328485995531082,
0.04925374314188957,
-0.05021926388144493,
-0.04292605072259903,
0.04698644205927849,
-0.03359435871243477,
-0.04509355500340462,
0.04655179753899574,
0.023896079510450363,
0.001453686272725463,
0.03195568919181824,
0.013015061616897583,
-0.04540842026472092,
0.011475657112896442,
0.03451377898454666,
-0.09938299655914307,
0.0021091161761432886,
-0.0498947836458683,
0.05472276732325554,
8.505957203102722e-33,
-0.030415399000048637,
-0.03317448869347572,
-0.04395526275038719,
-0.012100825086236,
-0.05783523991703987,
-0.027321230620145798,
0.004916290752589703,
0.05760260298848152,
-0.052027639001607895,
0.041909392923116684,
-0.06548275053501129,
-0.041954513639211655,
0.07234233617782593,
-0.026721028611063957,
0.031805913895368576,
0.07238772511482239,
0.11405330151319504,
0.055818550288677216,
0.04865400493144989,
0.10685040056705475,
0.017499171197414398,
-0.10918878018856049,
0.0905747339129448,
-0.019964549690485,
0.018904980272054672,
0.032143253833055496,
-0.04200070723891258,
0.06251506507396698,
-0.01197489071637392,
-0.002637963043525815,
-0.013827609829604626,
0.031233705580234528,
-0.06340038031339645,
-0.06029484048485756,
0.06915038079023361,
-0.044341087341308594,
0.009167145937681198,
-0.044552650302648544,
-0.07557026296854019,
-0.05139802768826485,
-0.08007515966892242,
0.013140798546373844,
-0.1523306667804718,
0.04966743290424347,
-0.008381529711186886,
-0.060885846614837646,
-0.111212819814682,
-0.048739176243543625,
0.006989466492086649,
0.10909764468669891,
0.01556326076388359,
0.06270505487918854,
0.00817702803760767,
0.022281093522906303,
0.014977552928030491,
-0.0015160569455474615,
0.00177573983091861,
0.10224143415689468,
-0.008427714928984642,
0.06707996129989624,
0.0422450415790081,
-0.04554487019777298,
-0.09046491235494614,
-0.03958246856927872,
0.08799563348293304,
0.037650518119335175,
0.044718485325574875,
-0.013997393660247326,
-0.08170441538095474,
0.017037417739629745,
0.03372618183493614,
0.03457115590572357,
-0.01453824620693922,
0.00030500744469463825,
-0.028175733983516693,
-0.026887264102697372,
0.001106930198147893,
-0.02759021520614624,
-0.003472816664725542,
-0.024562636390328407,
0.024379100650548935,
0.03752755746245384,
0.01974259875714779,
0.0018322254763916135,
-0.06354407966136932,
0.03861689195036888,
0.013899440877139568,
-0.04466312751173973,
-0.06195265054702759,
0.009655473753809929,
0.03578491136431694,
0.013640716671943665,
0.031069893389940262,
0.005029021762311459,
-0.03165467455983162,
-8.71438631049893e-33,
0.012353197671473026,
-0.013548924587666988,
-0.02604963257908821,
-0.018548808991909027,
-0.004330733325332403,
-0.07767545431852341,
0.030826730653643608,
0.0579814575612545,
0.03653465211391449,
-0.06926650553941727,
0.07956843823194504,
0.0018911673687398434,
0.09064027667045593,
-0.0117490878328681,
-0.015097386203706264,
-0.02155754156410694,
-0.005672373343259096,
-0.04036736860871315,
0.05619698017835617,
0.07218340784311295,
0.05992863327264786,
-0.014506333507597446,
-0.005510539282113314,
-0.07140706479549408,
-0.05387253686785698,
0.024505602195858955,
0.006399280391633511,
-0.00700848363339901,
-0.12374336272478104,
-0.08241894096136093,
0.0839613601565361,
0.05271366983652115,
-0.05324359983205795,
0.06658618152141571,
-0.001981554552912712,
0.07394788414239883,
0.004540808033198118,
0.05076238512992859,
0.05438696965575218,
0.06849592179059982,
0.11432970315217972,
0.05846402794122696,
-0.06713128834962845,
-0.02381320111453533,
0.022213881835341454,
-0.0022313890513032675,
-0.03398270159959793,
0.06835000962018967,
-0.07431105524301529,
0.039434146136045456,
0.0342341810464859,
-0.029891664162278175,
0.011988172307610512,
0.12323316931724548,
0.05355547368526459,
0.06756139546632767,
0.0531611442565918,
-0.062014445662498474,
0.03651804476976395,
0.026653695851564407,
-0.007831333205103874,
-0.12582476437091827,
0.021968720480799675,
0.1256016194820404,
0.03446827083826065,
0.09013389050960541,
0.03451182693243027,
-0.033962637186050415,
0.038581233471632004,
-0.028211962431669235,
0.06543193012475967,
0.00046454757102765143,
-0.041722189635038376,
-0.024167491123080254,
-0.01809849962592125,
0.039759714156389236,
0.00923581700772047,
-0.010257202200591564,
-0.02409011870622635,
0.04450632631778717,
-0.13829809427261353,
0.13669578731060028,
-0.08063177764415741,
0.019323665648698807,
0.012106060981750488,
0.021052919328212738,
0.012899189256131649,
0.07737289369106293,
0.049100298434495926,
0.023077508434653282,
-0.009964562952518463,
0.0019172244938090444,
-0.015736212953925133,
0.021802471950650215,
-0.05936216562986374,
-5.7628366079143234e-8,
-0.011457900516688824,
-0.00850629061460495,
-0.03418191894888878,
-0.025353070348501205,
0.030382297933101654,
0.05534352362155914,
-0.03738877922296524,
-0.05671878159046173,
-0.007941577583551407,
-0.0030513941310346127,
0.035775262862443924,
0.0072979093529284,
-0.01622273027896881,
-0.0323316752910614,
0.04292726144194603,
-0.021147212013602257,
0.0026616384275257587,
-0.05947442352771759,
-0.05485118553042412,
-0.07627223432064056,
0.0004171369655523449,
-0.060899510979652405,
-0.010318697430193424,
0.01777433045208454,
-0.06578506529331207,
-0.05391048640012741,
0.07383884489536285,
0.07784416526556015,
-0.10166479647159576,
-0.04273323342204094,
-0.11088534444570541,
0.017530230805277824,
-0.0013783116592094302,
-0.03552140295505524,
-0.057349707931280136,
0.1239098608493805,
-0.049002453684806824,
-0.04046916589140892,
-0.05000102519989014,
-0.023380829021334648,
0.008026150986552238,
-0.0973954126238823,
-0.03900096192955971,
0.01534807588905096,
0.04431668296456337,
0.05563817918300629,
-0.03686968609690666,
0.06424601376056671,
0.030803481116890907,
-0.06145004555583,
-0.05634090676903725,
-0.03427780419588089,
-0.034908924251794815,
0.010801403783261776,
0.022700509056448936,
-0.061188165098428726,
-0.03061872348189354,
-0.08962319791316986,
0.020001033321022987,
0.024853970855474472,
0.002267911797389388,
0.03492690622806549,
-0.033946443349123,
-0.03134758770465851
] | 0.054061
|
it implicitly calls `socket.end()`. ### `socket.end([data[, encoding]][, callback])` \* `data` {string|Buffer|Uint8Array} \* `encoding` {string} Only used when data is `string`. \*\*Default:\*\* `'utf8'`. \* `callback` {Function} Optional callback for when the socket is finished. \* Returns: {net.Socket} The socket itself. Half-closes the socket. i.e., it sends a FIN packet. It is possible the server will still send some data. See [`writable.end()`][] for further details. ### `socket.localAddress` \* Type: {string} The string representation of the local IP address the remote client is connecting on. For example, in a server listening on `'0.0.0.0'`, if a client connects on `'192.168.1.1'`, the value of `socket.localAddress` would be `'192.168.1.1'`. ### `socket.localPort` \* Type: {integer} The numeric representation of the local port. For example, `80` or `21`. ### `socket.localFamily` \* Type: {string} The string representation of the local IP family. `'IPv4'` or `'IPv6'`. ### `socket.pause()` \* Returns: {net.Socket} The socket itself. Pauses the reading of data. That is, [`'data'`][] events will not be emitted. Useful to throttle back an upload. ### `socket.pending` \* Type: {boolean} This is `true` if the socket is not connected yet, either because `.connect()` has not yet been called or because it is still in the process of connecting (see [`socket.connecting`][]). ### `socket.ref()` \* Returns: {net.Socket} The socket itself. Opposite of `unref()`, calling `ref()` on a previously `unref`ed socket will \_not\_ let the program exit if it's the only socket left (the default behavior). If the socket is `ref`ed calling `ref` again will have no effect. ### `socket.remoteAddress` \* Type: {string} The string representation of the remote IP address. For example, `'74.125.127.100'` or `'2001:4860:a005::68'`. Value may be `undefined` if the socket is destroyed (for example, if the client disconnected). ### `socket.remoteFamily` \* Type: {string} The string representation of the remote IP family. `'IPv4'` or `'IPv6'`. Value may be `undefined` if the socket is destroyed (for example, if the client disconnected). ### `socket.remotePort` \* Type: {integer} The numeric representation of the remote port. For example, `80` or `21`. Value may be `undefined` if the socket is destroyed (for example, if the client disconnected). ### `socket.resetAndDestroy()` \* Returns: {net.Socket} Close the TCP connection by sending an RST packet and destroy the stream. If this TCP socket is in connecting status, it will send an RST packet and destroy this TCP socket once it is connected. Otherwise, it will call `socket.destroy` with an `ERR\_SOCKET\_CLOSED` Error. If this is not a TCP socket (for example, a pipe), calling this method will immediately throw an `ERR\_INVALID\_HANDLE\_TYPE` Error. ### `socket.resume()` \* Returns: {net.Socket} The socket itself. Resumes reading after a call to [`socket.pause()`][]. ### `socket.setEncoding([encoding])` \* `encoding` {string} \* Returns: {net.Socket} The socket itself. Set the encoding for the socket as a [Readable Stream][]. See [`readable.setEncoding()`][] for more information. ### `socket.setKeepAlive([enable][, initialDelay])` \* `enable` {boolean} \*\*Default:\*\* `false` \* `initialDelay` {number} \*\*Default:\*\* `0` \* Returns: {net.Socket} The socket itself. Enable/disable keep-alive functionality, and optionally set the initial delay before the first keepalive probe is sent on an idle socket. Set `initialDelay` (in milliseconds) to set the delay between the last data packet received and the first keepalive probe. Setting `0` for `initialDelay` will leave the value unchanged from the default (or previous) setting. Enabling the keep-alive functionality will set the following socket options: \* `SO\_KEEPALIVE=1` \* `TCP\_KEEPIDLE=initialDelay` \* `TCP\_KEEPCNT=10` \* `TCP\_KEEPINTVL=1` ### `socket.setNoDelay([noDelay])` \* `noDelay` {boolean} \*\*Default:\*\* `true` \* Returns: {net.Socket} The socket itself. Enable/disable the use of Nagle's algorithm. When a TCP connection is created, it will have Nagle's algorithm enabled. Nagle's algorithm delays data before it is sent via the network. It attempts to optimize throughput at the expense of latency. Passing `true` for `noDelay` or not passing
|
https://github.com/nodejs/node/blob/main//doc/api/net.md
|
main
|
nodejs
|
[
-0.038886722177267075,
0.04553689435124397,
-0.014143974520266056,
0.05602477863430977,
-0.054842978715896606,
-0.07269559800624847,
0.016312522813677788,
-0.01061379536986351,
0.026528216898441315,
0.01948591135442257,
-0.04138680920004845,
0.11442429572343826,
-0.03677825629711151,
-0.0063654291443526745,
-0.003911290317773819,
0.019444197416305542,
0.03165615350008011,
-0.09103455394506454,
0.01890898309648037,
-0.053600799292325974,
-0.00733242928981781,
0.036385677754879,
0.0389799065887928,
-0.02954774908721447,
0.0026967034209519625,
0.0244990773499012,
0.011020930483937263,
-0.039519306272268295,
0.03307686373591423,
0.058851078152656555,
-0.012619655579328537,
0.011014617048203945,
-0.11503477394580841,
0.044881317764520645,
-0.04734921082854271,
0.07486477494239807,
0.04359910264611244,
-0.03648555651307106,
-0.11049579083919525,
0.01998068206012249,
0.10159538686275482,
0.011638924479484558,
-0.069673553109169,
0.021935271099209785,
-0.036119163036346436,
0.010146650485694408,
-0.04233698919415474,
-0.03866831213235855,
-0.06549283117055893,
-0.044756900519132614,
-0.050068724900484085,
0.061195820569992065,
-0.016303427517414093,
0.08345288783311844,
0.14631982147693634,
-0.08571022003889084,
-0.05778725817799568,
0.01625526323914528,
-0.03552591800689697,
0.05111467465758324,
-0.01631537638604641,
-0.003668904537335038,
-0.02915981039404869,
0.03299015760421753,
0.02437327243387699,
-0.015208701603114605,
-0.004489788319915533,
-0.016090497374534607,
-0.012091806158423424,
-0.027021892368793488,
-0.033190593123435974,
-0.011904117651283741,
-0.10147574543952942,
0.03305414691567421,
0.02592296153306961,
-0.035499293357133865,
0.02382834441959858,
-0.03141114488244057,
-0.06303731352090836,
0.02819894813001156,
-0.009670743718743324,
-0.10909327119588852,
-0.025809230282902718,
0.06893213093280792,
-0.04340329393744469,
-0.0007518859929405153,
-0.008041469380259514,
-0.007355846930295229,
0.01016775518655777,
0.06181575357913971,
-0.056200865656137466,
0.008434159681200981,
-0.04900021851062775,
0.09455499798059464,
0.02772834710776806,
0.03570909798145294,
0.037705644965171814,
0.026927053928375244,
-0.07786057144403458,
-0.0008668332593515515,
0.013894626870751381,
-0.03793816640973091,
-0.026850135996937752,
-0.028559904545545578,
0.011751876212656498,
-0.018730798736214638,
-0.011655417270958424,
-0.025991760194301605,
0.022354384884238243,
0.04389559477567673,
-0.05674467608332634,
-0.03180353343486786,
0.00008145319588948041,
0.046332985162734985,
-0.039073433727025986,
0.014613856561481953,
0.0037563564255833626,
0.06917662173509598,
-0.05300896614789963,
0.06316913664340973,
0.032431017607450485,
0.0004610334290191531,
-0.03711444512009621,
0.009067063219845295,
0.0016506424872204661,
-0.021812744438648224,
0.047704461961984634,
9.833185880014837e-35,
-0.0002941815764643252,
-0.0649111196398735,
-0.07565194368362427,
0.01982281357049942,
0.03069903329014778,
-0.01351991482079029,
0.06211603805422783,
0.021875936537981033,
-0.04513871669769287,
0.027774648740887642,
-0.041701167821884155,
0.004787829704582691,
0.07833265513181686,
0.023212997242808342,
0.01703636534512043,
0.015378871001303196,
0.10011617094278336,
0.009541074745357037,
0.10205699503421783,
0.0730920284986496,
0.02329207770526409,
0.014164568856358528,
0.026736145839095116,
-0.021755408495664597,
-0.04710239917039871,
-0.0131128691136837,
-0.078220896422863,
-0.030970050022006035,
-0.04057328402996063,
-0.009583089500665665,
-0.06176552549004555,
0.012101608328521252,
0.0111773069947958,
-0.00834390427917242,
0.015839949250221252,
-0.0607711598277092,
0.050161898136138916,
-0.06151038780808449,
-0.05713636055588722,
-0.0014446061104536057,
0.04574183002114296,
-0.0024407925084233284,
-0.13242045044898987,
0.054952457547187805,
-0.0692533627152443,
-0.08228418231010437,
-0.11882682889699936,
-0.026331357657909393,
0.0207831934094429,
0.04489517584443092,
-0.011497210711240768,
0.039036091417074203,
0.05408988893032074,
0.026984363794326782,
0.008810256607830524,
0.005993922706693411,
0.031518664211034775,
0.048434432595968246,
-0.024202603846788406,
0.02878473326563835,
0.02903680130839348,
-0.012176534160971642,
-0.015197069384157658,
-0.08110310137271881,
0.045152924954891205,
0.013659197837114334,
-0.015268019400537014,
0.025679880753159523,
-0.025559620931744576,
-0.0036545442417263985,
-0.05404013767838478,
0.061059750616550446,
-0.04667547345161438,
0.07463815063238144,
-0.02984691597521305,
0.09261761605739594,
-0.053674355149269104,
-0.03430150821805,
0.05634203925728798,
-0.0436033196747303,
0.029412446543574333,
0.029668867588043213,
-0.0158876683562994,
0.006509743630886078,
-0.023555239662528038,
0.023510977625846863,
-0.020635589957237244,
-0.06740804016590118,
0.010599493980407715,
-0.03220704197883606,
-0.022245386615395546,
-0.03329852595925331,
0.03950563445687294,
-0.0412277914583683,
-0.05488090217113495,
-3.5714431399919226e-33,
-0.007356666959822178,
0.017561646178364754,
-0.19055794179439545,
0.04011378064751625,
-0.04394444078207016,
-0.06536302715539932,
0.007455178536474705,
0.03353320434689522,
-0.03440910577774048,
-0.027150224894285202,
0.017893465235829353,
-0.016957081854343414,
0.0940985232591629,
0.007425414863973856,
0.01709035597741604,
-0.01992046646773815,
-0.03596457093954086,
-0.02065892145037651,
0.014796814881265163,
-0.048377539962530136,
-0.061986371874809265,
-0.007422602269798517,
0.05229591578245163,
-0.021381216123700142,
-0.06146487221121788,
0.01855623535811901,
-0.003557177260518074,
-0.005712924990803003,
-0.06552010774612427,
-0.04671729356050491,
0.08492051810026169,
-0.037767596542835236,
-0.018964583054184914,
-0.01458351407200098,
-0.05720740556716919,
0.073844775557518,
0.04619894549250603,
-0.003020988078787923,
0.09087374806404114,
-0.02207368239760399,
0.17358539998531342,
-0.016808459535241127,
-0.04274981841444969,
0.030636021867394447,
0.04217731952667236,
-0.013058383949100971,
-0.05234275385737419,
0.04785603657364845,
-0.046687591820955276,
-0.034569550305604935,
0.10401368886232376,
0.04294509440660477,
0.06759054958820343,
0.07210669666528702,
0.012391593307256699,
0.0345931351184845,
0.11998876184225082,
-0.03298860043287277,
0.10354156047105789,
-0.039075929671525955,
0.06708988547325134,
-0.10681997984647751,
-0.016376884654164314,
0.04256296902894974,
0.0032594085205346346,
0.01358293928205967,
-0.025911424309015274,
-0.06824936717748642,
0.08171383291482925,
-0.08485610783100128,
0.061254456639289856,
0.010957090184092522,
-0.05091557279229164,
0.04617149382829666,
0.0077779581770300865,
0.08145051449537277,
-0.028235729783773422,
-0.00033353036269545555,
0.024897852912545204,
0.11988591402769089,
-0.09374402463436127,
0.05665690079331398,
-0.06964745372533798,
0.03446682542562485,
0.056445855647325516,
-0.0627790316939354,
-0.03203112259507179,
0.04697687551379204,
-0.01942422240972519,
-0.07654685527086258,
0.01136381272226572,
0.05660654604434967,
-0.0879867896437645,
0.027445215731859207,
0.010619822889566422,
-4.79056545543699e-8,
-0.029145944863557816,
-0.028763119131326675,
-0.058304816484451294,
0.05650908127427101,
-0.020282570272684097,
0.03496513143181801,
-0.00644288444891572,
-0.07572610676288605,
0.09345953911542892,
0.036516010761260986,
-0.05965946987271309,
-0.04580886289477348,
0.02607809007167816,
-0.03684503585100174,
0.06966254115104675,
0.08871230483055115,
0.05478008836507797,
-0.033180397003889084,
0.014827548526227474,
-0.01649206504225731,
0.02942579798400402,
-0.08767955005168915,
-0.09809413552284241,
0.03315209597349167,
-0.07520237565040588,
-0.00277794455178082,
0.08167325705289841,
0.10174418985843658,
-0.14779460430145264,
-0.036818474531173706,
-0.03686707839369774,
-0.011868730187416077,
0.060620684176683426,
0.07410525530576706,
-0.05519065260887146,
0.06407655775547028,
-0.04598265886306763,
-0.004382521379739046,
0.013069478794932365,
0.10559368133544922,
-0.014998792670667171,
-0.04606461152434349,
-0.07191005349159241,
0.033935386687517166,
0.04078061506152153,
0.0073404861614108086,
0.03750455752015114,
0.0898963138461113,
-0.02944825030863285,
-0.026402579620480537,
0.051773782819509506,
-0.024478893727064133,
-0.04704534262418747,
-0.007482059299945831,
0.023571083322167397,
-0.0217934250831604,
-0.06902320683002472,
-0.04096102714538574,
-0.015194833278656006,
0.028544770553708076,
-0.01969812996685505,
0.09120751917362213,
-0.04687415063381195,
-0.05279425531625748
] | 0.095638
|
{net.Socket} The socket itself. Enable/disable the use of Nagle's algorithm. When a TCP connection is created, it will have Nagle's algorithm enabled. Nagle's algorithm delays data before it is sent via the network. It attempts to optimize throughput at the expense of latency. Passing `true` for `noDelay` or not passing an argument will disable Nagle's algorithm for the socket. Passing `false` for `noDelay` will enable Nagle's algorithm. ### `socket.setTimeout(timeout[, callback])` \* `timeout` {number} \* `callback` {Function} \* Returns: {net.Socket} The socket itself. Sets the socket to timeout after `timeout` milliseconds of inactivity on the socket. By default `net.Socket` do not have a timeout. When an idle timeout is triggered the socket will receive a [`'timeout'`][] event but the connection will not be severed. The user must manually call [`socket.end()`][] or [`socket.destroy()`][] to end the connection. ```js socket.setTimeout(3000); socket.on('timeout', () => { console.log('socket timeout'); socket.end(); }); ``` If `timeout` is 0, then the existing idle timeout is disabled. The optional `callback` parameter will be added as a one-time listener for the [`'timeout'`][] event. ### `socket.timeout` \* Type: {number|undefined} The socket timeout in milliseconds as set by [`socket.setTimeout()`][]. It is `undefined` if a timeout has not been set. ### `socket.unref()` \* Returns: {net.Socket} The socket itself. Calling `unref()` on a socket will allow the program to exit if this is the only active socket in the event system. If the socket is already `unref`ed calling `unref()` again will have no effect. ### `socket.write(data[, encoding][, callback])` \* `data` {string|Buffer|Uint8Array} \* `encoding` {string} Only used when data is `string`. \*\*Default:\*\* `utf8`. \* `callback` {Function} \* Returns: {boolean} Sends data on the socket. The second parameter specifies the encoding in the case of a string. It defaults to UTF8 encoding. Returns `true` if the entire data was flushed successfully to the kernel buffer. Returns `false` if all or part of the data was queued in user memory. [`'drain'`][] will be emitted when the buffer is again free. The optional `callback` parameter will be executed when the data is finally written out, which may not be immediately. See `Writable` stream [`write()`][stream\_writable\_write] method for more information. ### `socket.readyState` \* Type: {string} This property represents the state of the connection as a string. \* If the stream is connecting `socket.readyState` is `opening`. \* If the stream is readable and writable, it is `open`. \* If the stream is readable and not writable, it is `readOnly`. \* If the stream is not readable and writable, it is `writeOnly`. ## `net.connect()` Aliases to [`net.createConnection()`][`net.createConnection()`]. Possible signatures: \* [`net.connect(options[, connectListener])`][`net.connect(options)`] \* [`net.connect(path[, connectListener])`][`net.connect(path)`] for [IPC][] connections. \* [`net.connect(port[, host][, connectListener])`][`net.connect(port, host)`] for TCP connections. ### `net.connect(options[, connectListener])` \* `options` {Object} \* `connectListener` {Function} \* Returns: {net.Socket} Alias to [`net.createConnection(options[, connectListener])`][`net.createConnection(options)`]. ### `net.connect(path[, connectListener])` \* `path` {string} \* `connectListener` {Function} \* Returns: {net.Socket} Alias to [`net.createConnection(path[, connectListener])`][`net.createConnection(path)`]. ### `net.connect(port[, host][, connectListener])` \* `port` {number} \* `host` {string} \* `connectListener` {Function} \* Returns: {net.Socket} Alias to [`net.createConnection(port[, host][, connectListener])`][`net.createConnection(port, host)`]. ## `net.createConnection()` A factory function, which creates a new [`net.Socket`][], immediately initiates connection with [`socket.connect()`][], then returns the `net.Socket` that starts the connection. When the connection is established, a [`'connect'`][] event will be emitted on the returned socket. The last parameter `connectListener`, if supplied, will be added as a listener for the [`'connect'`][] event \*\*once\*\*. Possible signatures: \* [`net.createConnection(options[, connectListener])`][`net.createConnection(options)`] \* [`net.createConnection(path[, connectListener])`][`net.createConnection(path)`] for [IPC][] connections. \* [`net.createConnection(port[, host][, connectListener])`][`net.createConnection(port, host)`] for TCP connections. The [`net.connect()`][] function is an alias to this function. ### `net.createConnection(options[, connectListener])` \* `options` {Object} Required. Will be passed to both the [`new net.Socket([options])`][`new net.Socket(options)`] call and the [`socket.connect(options[, connectListener])`][`socket.connect(options)`] method. \* `connectListener` {Function} Common parameter of the [`net.createConnection()`][]
|
https://github.com/nodejs/node/blob/main//doc/api/net.md
|
main
|
nodejs
|
[
-0.07625095546245575,
0.04416206479072571,
-0.0393638052046299,
0.097306028008461,
-0.03562788665294647,
-0.0703502744436264,
0.014168618246912956,
-0.044971928000450134,
0.061865996569395065,
-0.05336793512105942,
-0.05855150148272514,
0.1190439984202385,
-0.026476943865418434,
-0.0357043519616127,
-0.0013036526506766677,
-0.02521912381052971,
0.03945473954081535,
-0.06397318840026855,
0.005294253118336201,
-0.1143692135810852,
-0.010146086104214191,
-0.0212407186627388,
0.03446842357516289,
-0.03938884288072586,
0.010933767072856426,
-0.10319412499666214,
0.00852226559072733,
-0.05342914164066315,
0.03654899075627327,
0.043498437851667404,
0.009755910374224186,
-0.027028271928429604,
-0.09490089863538742,
0.03918521851301193,
-0.10474617779254913,
0.04190785437822342,
-0.04278360307216644,
0.04013286158442497,
-0.13682863116264343,
0.023001791909337044,
0.08868752419948578,
0.03129279613494873,
-0.04962567612528801,
-0.054394353181123734,
-0.0002468327584210783,
0.013623163104057312,
-0.09700918942689896,
-0.05509212985634804,
-0.03492533043026924,
-0.009736549109220505,
-0.046462152153253555,
0.03756970539689064,
-0.017221273854374886,
0.017745204269886017,
0.09419205784797668,
-0.021952614188194275,
-0.040643852204084396,
0.009779952466487885,
-0.03960687667131424,
0.05320700258016586,
0.03181927651166916,
-0.04425198584794998,
0.03162064403295517,
0.05038672685623169,
0.055448949337005615,
0.07184307277202606,
0.03564976900815964,
-0.054100777953863144,
0.0018812796333804727,
0.05811181664466858,
0.025675777345895767,
0.013658017851412296,
-0.05439905449748039,
0.018717672675848007,
0.016915826126933098,
-0.06355860829353333,
0.0354023240506649,
-0.013569952920079231,
-0.029740629717707634,
0.055473703891038895,
-0.03024708665907383,
-0.03884512558579445,
-0.04618706926703453,
0.04773246496915817,
0.005201614927500486,
-0.00271634035743773,
0.016914499923586845,
0.043488115072250366,
-0.05723531171679497,
-0.013685368932783604,
-0.048743005841970444,
0.056215520948171616,
-0.04272108152508736,
0.06974075734615326,
-0.0017459113150835037,
0.03336946293711662,
0.027591858059167862,
0.010946346446871758,
-0.1367318034172058,
-0.014774723909795284,
0.04392193630337715,
-0.01629820466041565,
-0.03408714383840561,
-0.006884713191539049,
0.03585200756788254,
-0.02497945725917816,
0.014729036018252373,
-0.018370460718870163,
-0.008898274041712284,
0.0633055716753006,
-0.015168607234954834,
0.02511792816221714,
0.05470840632915497,
0.048330049961805344,
-0.056622110307216644,
0.059560153633356094,
0.017471525818109512,
0.0394473671913147,
0.07905325293540955,
0.05397016182541847,
0.10331270098686218,
0.01753169298171997,
-0.011878362856805325,
-0.08321360498666763,
0.005092896055430174,
0.010652774013578892,
0.04333367943763733,
3.531008338375544e-33,
-0.057563312351703644,
-0.02654825896024704,
-0.07604062557220459,
-0.014439673162996769,
0.02167312242090702,
-0.0490027479827404,
0.010767693631350994,
0.011599303223192692,
-0.06675957888364792,
0.011159859597682953,
-0.04567449912428856,
-0.018172748386859894,
0.02360178343951702,
0.0017763058422133327,
0.015085922554135323,
-0.009685037657618523,
0.09101118892431259,
-0.039796095341444016,
0.11278384923934937,
0.014369669370353222,
0.04032580927014351,
-0.07811066508293152,
-0.012206829153001308,
0.05639909580349922,
-0.038542114198207855,
0.02358260191977024,
-0.07720692455768585,
-0.0072831930592656136,
-0.03740613907575607,
0.0032947806175798178,
-0.006473271641880274,
0.011808360926806927,
-0.03122679702937603,
0.015462402254343033,
0.0166203323751688,
-0.06244455650448799,
-0.007992411032319069,
-0.03421347588300705,
-0.015875166282057762,
-0.015825308859348297,
-0.012979979626834393,
0.026705222204327583,
-0.10036469995975494,
0.0696348175406456,
-0.05739835649728775,
-0.0664910078048706,
-0.09509248286485672,
0.01874442771077156,
0.04191501811146736,
0.0628732368350029,
0.026863064616918564,
0.04685124009847641,
0.0762433409690857,
-0.019457265734672546,
0.03527746722102165,
-0.015385126695036888,
0.03144591301679611,
0.06447815895080566,
-0.019747834652662277,
0.024926481768488884,
0.08938904106616974,
-0.08884884417057037,
-0.02940147928893566,
-0.06582912802696228,
0.10312645882368088,
0.032847557216882706,
-0.04668750986456871,
0.006139788310974836,
-0.08314693719148636,
-0.001099713728763163,
-0.013978416100144386,
0.09665035456418991,
-0.02183627337217331,
0.0722065418958664,
-0.05022727698087692,
0.034634191542863846,
-0.017414608970284462,
-0.04533464089035988,
-0.031132733449339867,
-0.03846201300621033,
0.013157928362488747,
0.02582559734582901,
0.012652814388275146,
-0.02323002740740776,
0.07228069752454758,
-0.08405205607414246,
0.030369075015187263,
0.018434884026646614,
0.003086129203438759,
-0.008621354587376118,
-0.0016387791838496923,
0.03408234193921089,
0.048465318977832794,
-0.05544085428118706,
-0.06636054068803787,
-3.917246027354992e-33,
0.0024115496780723333,
0.006003302056342363,
-0.1597774773836136,
0.06893663853406906,
0.021171938627958298,
-0.10682412981987,
-0.022516684606671333,
-0.003337566740810871,
-0.019310124218463898,
-0.05278288573026657,
0.05159343406558037,
-0.016940440982580185,
0.09654581546783447,
-0.003411242039874196,
0.02888883464038372,
-0.03058568760752678,
-0.013305585831403732,
-0.04037480428814888,
-0.012218761257827282,
-0.03559960052371025,
-0.06315427273511887,
-0.009587522596120834,
0.017200039699673653,
-0.04855925217270851,
-0.10311132669448853,
0.0454285629093647,
-0.01584002375602722,
-0.019442236050963402,
-0.0812169685959816,
-0.029309526085853577,
-0.023415978997945786,
0.052426014095544815,
-0.040850743651390076,
0.014941610395908356,
-0.0015313802286982536,
0.10315997898578644,
0.03470257669687271,
0.03203565999865532,
0.06503400206565857,
-0.00938290636986494,
0.1670745313167572,
0.05601023882627487,
-0.0713757872581482,
-0.013943559490144253,
0.028943203389644623,
0.07341925799846649,
-0.07290513068437576,
0.0375731997191906,
-0.06107736751437187,
0.03100268915295601,
0.029540620744228363,
0.014430202543735504,
0.09878064692020416,
0.06165148690342903,
0.03011196479201317,
0.0530884750187397,
0.08929724991321564,
-0.05333641543984413,
0.07243848592042923,
-0.029153991490602493,
0.060897741466760635,
-0.09492791444063187,
0.011624610051512718,
0.0394638292491436,
0.01872684806585312,
0.020885076373815536,
-0.08902040868997574,
0.011881752870976925,
0.07452009618282318,
-0.025898803025484085,
0.007714172825217247,
0.09069625288248062,
-0.030778994783759117,
0.011119809933006763,
-0.06372363865375519,
0.07704362273216248,
0.009489552117884159,
0.012428457848727703,
0.007823290303349495,
0.013853936456143856,
-0.06894189864397049,
0.12606923282146454,
-0.03814491257071495,
-0.03291839361190796,
-0.0011148839257657528,
0.022539861500263214,
-0.05675583332777023,
0.049518171697854996,
0.052145931869745255,
-0.03279465064406395,
0.000816794577986002,
0.004776968155056238,
-0.10749600827693939,
0.02846330590546131,
-0.04597361758351326,
-4.8357268411791665e-8,
-0.012819316238164902,
0.02163475751876831,
-0.025396373122930527,
-0.033897414803504944,
0.015277537517249584,
0.03431921824812889,
0.02580336481332779,
-0.03573623299598694,
0.04943237453699112,
0.029431786388158798,
0.011938244104385376,
-0.010915720835328102,
0.03279108554124832,
-0.02975393645465374,
0.07500777393579483,
0.122674860060215,
-0.005015280097723007,
-0.01648956537246704,
0.010263171046972275,
-0.04404862970113754,
0.010023577138781548,
-0.05891915410757065,
-0.059088338166475296,
0.09727704524993896,
-0.06369483470916748,
-0.03682025521993637,
0.07563189417123795,
0.054889976978302,
-0.07756063342094421,
-0.0783095732331276,
-0.1325756311416626,
0.00858031865209341,
0.057730533182621,
0.04475653916597366,
-0.04275750368833542,
0.02291492186486721,
-0.038354694843292236,
0.03654811158776283,
0.05199723690748215,
0.07328420877456665,
-0.0004596093494910747,
-0.055901676416397095,
-0.08609712868928909,
-0.01272478699684143,
0.004221569746732712,
0.0298051368445158,
0.011522277258336544,
0.10356155782938004,
-0.004487961996346712,
0.026990756392478943,
0.011220652610063553,
-0.028935017064213753,
-0.029776785522699356,
-0.062371496111154556,
0.028215374797582626,
-0.038104165345430374,
0.0016824004705995321,
-0.042111657559871674,
0.013247823342680931,
-0.007764940615743399,
-0.05821659415960312,
0.08664212375879288,
0.01958323083817959,
-0.019299346953630447
] | 0.156231
|
for [IPC][] connections. \* [`net.createConnection(port[, host][, connectListener])`][`net.createConnection(port, host)`] for TCP connections. The [`net.connect()`][] function is an alias to this function. ### `net.createConnection(options[, connectListener])` \* `options` {Object} Required. Will be passed to both the [`new net.Socket([options])`][`new net.Socket(options)`] call and the [`socket.connect(options[, connectListener])`][`socket.connect(options)`] method. \* `connectListener` {Function} Common parameter of the [`net.createConnection()`][] functions. If supplied, will be added as a listener for the [`'connect'`][] event on the returned socket once. \* Returns: {net.Socket} The newly created socket used to start the connection. For available options, see [`new net.Socket([options])`][`new net.Socket(options)`] and [`socket.connect(options[, connectListener])`][`socket.connect(options)`]. Additional options: \* `timeout` {number} If set, will be used to call [`socket.setTimeout(timeout)`][] after the socket is created, but before it starts the connection. Following is an example of a client of the echo server described in the [`net.createServer()`][] section: ```mjs import net from 'node:net'; const client = net.createConnection({ port: 8124 }, () => { // 'connect' listener. console.log('connected to server!'); client.write('world!\r\n'); }); client.on('data', (data) => { console.log(data.toString()); client.end(); }); client.on('end', () => { console.log('disconnected from server'); }); ``` ```cjs const net = require('node:net'); const client = net.createConnection({ port: 8124 }, () => { // 'connect' listener. console.log('connected to server!'); client.write('world!\r\n'); }); client.on('data', (data) => { console.log(data.toString()); client.end(); }); client.on('end', () => { console.log('disconnected from server'); }); ``` To connect on the socket `/tmp/echo.sock`: ```js const client = net.createConnection({ path: '/tmp/echo.sock' }); ``` Following is an example of a client using the `port` and `onread` option. In this case, the `onread` option will be only used to call `new net.Socket([options])` and the `port` option will be used to call `socket.connect(options[, connectListener])`. ```mjs import net from 'node:net'; import { Buffer } from 'node:buffer'; net.createConnection({ port: 8124, onread: { // Reuses a 4KiB Buffer for every read from the socket. buffer: Buffer.alloc(4 \* 1024), callback: function(nread, buf) { // Received data is available in `buf` from 0 to `nread`. console.log(buf.toString('utf8', 0, nread)); }, }, }); ``` ```cjs const net = require('node:net'); net.createConnection({ port: 8124, onread: { // Reuses a 4KiB Buffer for every read from the socket. buffer: Buffer.alloc(4 \* 1024), callback: function(nread, buf) { // Received data is available in `buf` from 0 to `nread`. console.log(buf.toString('utf8', 0, nread)); }, }, }); ``` ### `net.createConnection(path[, connectListener])` \* `path` {string} Path the socket should connect to. Will be passed to [`socket.connect(path[, connectListener])`][`socket.connect(path)`]. See [Identifying paths for IPC connections][]. \* `connectListener` {Function} Common parameter of the [`net.createConnection()`][] functions, an "once" listener for the `'connect'` event on the initiating socket. Will be passed to [`socket.connect(path[, connectListener])`][`socket.connect(path)`]. \* Returns: {net.Socket} The newly created socket used to start the connection. Initiates an [IPC][] connection. This function creates a new [`net.Socket`][] with all options set to default, immediately initiates connection with [`socket.connect(path[, connectListener])`][`socket.connect(path)`], then returns the `net.Socket` that starts the connection. ### `net.createConnection(port[, host][, connectListener])` \* `port` {number} Port the socket should connect to. Will be passed to [`socket.connect(port[, host][, connectListener])`][`socket.connect(port)`]. \* `host` {string} Host the socket should connect to. Will be passed to [`socket.connect(port[, host][, connectListener])`][`socket.connect(port)`]. \*\*Default:\*\* `'localhost'`. \* `connectListener` {Function} Common parameter of the [`net.createConnection()`][] functions, an "once" listener for the `'connect'` event on the initiating socket. Will be passed to [`socket.connect(port[, host][, connectListener])`][`socket.connect(port)`]. \* Returns: {net.Socket} The newly created socket used to start the connection. Initiates a TCP connection. This function creates a new [`net.Socket`][] with all options set to default, immediately initiates connection with [`socket.connect(port[, host][, connectListener])`][`socket.connect(port)`], then returns the `net.Socket` that starts the connection. ## `net.createServer([options][, connectionListener])` \* `options` {Object} \* `allowHalfOpen` {boolean} If set to `false`, then the socket will automatically end the writable side when the readable side ends. \*\*Default:\*\* `false`. \* `highWaterMark` {number} Optionally overrides all [`net.Socket`][]s' `readableHighWaterMark` and `writableHighWaterMark`.
|
https://github.com/nodejs/node/blob/main//doc/api/net.md
|
main
|
nodejs
|
[
-0.0995662584900856,
-0.03060484118759632,
-0.07187463343143463,
0.056402597576379776,
-0.06980828195810318,
-0.024189703166484833,
0.06229915842413902,
0.024326767772436142,
0.006172749679535627,
0.00045817470527254045,
-0.014396102167665958,
0.02770330384373665,
-0.05564964562654495,
-0.006752307526767254,
0.03341706097126007,
0.020330142229795456,
0.025370754301548004,
-0.08105013519525528,
0.04219626262784004,
-0.031984198838472366,
-0.007476650178432465,
-0.03597734495997429,
-0.028257163241505623,
-0.1197240799665451,
-0.014722243882715702,
-0.08315224200487137,
0.05116313323378563,
-0.008087790571153164,
0.03826286271214485,
0.08826527744531631,
0.0031555311288684607,
0.014507418498396873,
-0.09190905094146729,
0.039692413061857224,
-0.061006780713796616,
0.017628725618124008,
0.0645281970500946,
0.011726299300789833,
-0.07518770545721054,
-0.010084343142807484,
0.10552649945020676,
-0.014859947375953197,
-0.06714912503957748,
-0.04647454991936684,
-0.0234017726033926,
0.0035871861036866903,
-0.07628539204597473,
-0.007961601950228214,
-0.031824223697185516,
-0.05775546655058861,
-0.01096795778721571,
0.06239369884133339,
-0.05202159658074379,
0.011999239213764668,
0.11561074107885361,
-0.034787897020578384,
-0.05186013504862785,
-0.019491814076900482,
-0.027285614982247353,
0.04808949679136276,
-0.01149718090891838,
0.007523944601416588,
-0.021657725796103477,
0.048531658947467804,
-0.014196883887052536,
-0.01247886661440134,
0.0029202457517385483,
0.02331499010324478,
0.011757892556488514,
0.020083971321582794,
-0.1308654248714447,
0.0662977322936058,
-0.09577489644289017,
-0.011595336720347404,
-0.008347829803824425,
-0.04981327801942825,
0.02110481821000576,
-0.010713702067732811,
-0.08203267306089401,
-0.005005015525966883,
-0.00043870846275240183,
0.010111680254340172,
-0.07561816275119781,
0.04697306826710701,
-0.026225436478853226,
0.07911078631877899,
-0.04579899087548256,
-0.020185792818665504,
-0.008296675980091095,
0.01150448527187109,
-0.08773241192102432,
0.05594397336244583,
-0.0889340415596962,
0.006925617344677448,
0.021294845268130302,
0.06502607464790344,
0.0016570956213399768,
-0.02745628170669079,
-0.059395186603069305,
0.008852873928844929,
-0.030421169474720955,
-0.06743709743022919,
-0.02401360124349594,
-0.06215796619653702,
0.033786363899707794,
-0.03948645666241646,
-0.07316308468580246,
-0.040442779660224915,
0.06869871914386749,
0.0706566870212555,
-0.06628990918397903,
0.038314737379550934,
-0.0017595652025192976,
-0.012483207508921623,
-0.02048017829656601,
0.05501046031713486,
0.03373993560671806,
0.019627468660473824,
0.08426646888256073,
0.07360813021659851,
0.04935743659734726,
-0.006997006479650736,
-0.03537750616669655,
-0.047073930501937866,
-0.029356801882386208,
-0.046305835247039795,
0.0064202104695141315,
6.713294614471644e-34,
0.024634653702378273,
-0.050074558705091476,
-0.012779805809259415,
0.05953767150640488,
0.04861629009246826,
0.04386838898062706,
0.09527241438627243,
0.02814253605902195,
-0.06089062616229057,
0.06415831297636032,
-0.1005694568157196,
-0.02531103976070881,
0.04531462490558624,
-0.02873818390071392,
-0.0252660121768713,
0.004080257378518581,
0.01475323922932148,
0.03342275694012642,
0.11101692914962769,
0.054246723651885986,
-0.021700909361243248,
-0.004307675641030073,
0.07110002636909485,
0.04259389638900757,
0.01458875834941864,
-0.029671546071767807,
-0.06060395762324333,
0.03639604151248932,
-0.032372914254665375,
-0.023465493693947792,
0.02129989117383957,
0.016714317724108696,
-0.04438795521855354,
0.011004133149981499,
0.04140227660536766,
-0.05354955792427063,
-0.017863694578409195,
-0.009165427647531033,
-0.059658490121364594,
-0.018305853009223938,
0.006499753333628178,
-0.0684250146150589,
-0.14249058067798615,
0.027644533663988113,
-0.03320832923054695,
-0.04170671105384827,
-0.11664316058158875,
0.004994942806661129,
0.08501248806715012,
0.01569344475865364,
-0.021658072248101234,
0.021070435643196106,
0.04720985144376755,
-0.0008376244804821908,
0.015741130337119102,
0.0011525268200784922,
-0.03614244982600212,
0.06977244466543198,
-0.010588030330836773,
0.02173745073378086,
0.0033736322075128555,
-0.01412117201834917,
-0.07655450701713562,
-0.02723696082830429,
0.09020841866731644,
0.043954189866781235,
-0.024049516767263412,
-0.00885525718331337,
-0.02324955351650715,
-0.02662060596048832,
-0.0007043620571494102,
0.03168017789721489,
-0.08745396137237549,
0.0010758077260106802,
-0.018985889852046967,
0.059966523200273514,
-0.04048819839954376,
-0.012532509863376617,
0.021599480882287025,
-0.012258600443601608,
0.030873002484440804,
0.0554225817322731,
-0.036553382873535156,
0.014184127561748028,
0.00990705844014883,
-0.02377145364880562,
-0.016059642657637596,
-0.03769994527101517,
0.02575758285820484,
-0.030880412086844444,
-0.019926631823182106,
0.02590692602097988,
0.0925845354795456,
-0.035819973796606064,
-0.023244790732860565,
-4.67991925179597e-33,
0.009422090835869312,
0.03526477515697479,
-0.1046881154179573,
-0.0009618671610951424,
-0.02172628603875637,
-0.06871040910482407,
0.02111206017434597,
-0.04610595852136612,
-0.04255596548318863,
-0.037615615874528885,
0.09509240835905075,
0.01985759101808071,
0.08059859275817871,
-0.005815405398607254,
-0.0016773217357695103,
0.015377454459667206,
-0.09018183499574661,
-0.04210222139954567,
0.014612887054681778,
0.061776287853717804,
-0.02597217634320259,
0.012256014160811901,
0.0598582848906517,
-0.09062202274799347,
-0.1178366169333458,
-0.01948421634733677,
0.05940820649266243,
0.006361739244312048,
-0.08928494900465012,
-0.002874854952096939,
0.0012192149879410863,
0.07240317761898041,
-0.04040851071476936,
0.07359189540147781,
0.005940168630331755,
0.058091070502996445,
0.11897235363721848,
-0.0032553195487707853,
0.09519340097904205,
-0.007740883156657219,
0.11030823737382889,
-0.01898283138871193,
-0.023861385881900787,
0.007884075865149498,
0.02913009002804756,
-0.0008712098351679742,
-0.051868658512830734,
0.0323166698217392,
-0.09191468358039856,
-0.012183225713670254,
0.02034277468919754,
-0.02089495211839676,
-0.030914144590497017,
0.054081011563539505,
0.009110117331147194,
0.08879977464675903,
0.12039877474308014,
-0.04955565556883812,
0.12970589101314545,
-0.0004460313357412815,
0.033923275768756866,
-0.1476745456457138,
-0.007046493235975504,
0.07111329585313797,
0.019354000687599182,
0.02752627432346344,
-0.052703842520713806,
-0.0008394730975851417,
0.034340910613536835,
-0.0339861698448658,
-0.040749095380306244,
0.01451161876320839,
-0.017979562282562256,
0.004394695162773132,
-0.024153435602784157,
-0.004381255246698856,
0.007259560748934746,
-0.025261182337999344,
0.0031618804205209017,
0.12103597074747086,
-0.04258129745721817,
0.06157132238149643,
-0.04020005464553833,
-0.05615586042404175,
-0.003342665731906891,
-0.008774105459451675,
0.018882468342781067,
0.07687798142433167,
0.012724501080811024,
-0.05224542319774628,
-0.06695609539747238,
0.05859318748116493,
-0.01030118577182293,
0.04637763276696205,
-0.019262107089161873,
-5.1918782162374555e-8,
-0.054740674793720245,
0.01913660392165184,
-0.042194195091724396,
-0.015618063509464264,
-0.00945020467042923,
0.05361399054527283,
-0.050632886588573456,
-0.06664998829364777,
0.046636711806058884,
0.033007826656103134,
-0.07887302339076996,
0.03649426996707916,
0.06863348931074142,
0.0230166744440794,
0.08536689728498459,
0.037987589836120605,
0.0021176275331526995,
-0.013186213560402393,
0.022646464407444,
-0.039089810103178024,
0.048338789492845535,
-0.06431137025356293,
0.022203855216503143,
0.09599440544843674,
-0.007933761924505234,
-0.08172276616096497,
0.06561752408742905,
0.0562569834291935,
-0.12809433043003082,
0.037581849843263626,
-0.07490319013595581,
0.009024504572153091,
0.03815487027168274,
0.033599019050598145,
-0.006805654149502516,
0.09206128865480423,
-0.14299552142620087,
0.018103186041116714,
0.05306798964738846,
0.06388410925865173,
-0.013137774541974068,
-0.0043548052199184895,
-0.11005081236362457,
0.018702765926718712,
0.030832922086119652,
0.039124198257923126,
0.00842930469661951,
0.07058008015155792,
0.004467589780688286,
0.006046078633517027,
-0.01039598137140274,
0.031868547201156616,
0.018810821697115898,
-0.08429592847824097,
-0.0009667367557995021,
0.042606960982084274,
-0.07556372135877609,
-0.018326444551348686,
-0.03022296167910099,
0.018322477117180824,
-0.07864851504564285,
0.13668344914913177,
-0.010651000775396824,
-0.03173653408885002
] | 0.092375
|
[`socket.connect(port[, host][, connectListener])`][`socket.connect(port)`], then returns the `net.Socket` that starts the connection. ## `net.createServer([options][, connectionListener])` \* `options` {Object} \* `allowHalfOpen` {boolean} If set to `false`, then the socket will automatically end the writable side when the readable side ends. \*\*Default:\*\* `false`. \* `highWaterMark` {number} Optionally overrides all [`net.Socket`][]s' `readableHighWaterMark` and `writableHighWaterMark`. \*\*Default:\*\* See [`stream.getDefaultHighWaterMark()`][]. \* `keepAlive` {boolean} If set to `true`, it enables keep-alive functionality on the socket immediately after a new incoming connection is received, similarly on what is done in [`socket.setKeepAlive()`][]. \*\*Default:\*\* `false`. \* `keepAliveInitialDelay` {number} If set to a positive number, it sets the initial delay before the first keepalive probe is sent on an idle socket. \*\*Default:\*\* `0`. \* `noDelay` {boolean} If set to `true`, it disables the use of Nagle's algorithm immediately after a new incoming connection is received. \*\*Default:\*\* `false`. \* `pauseOnConnect` {boolean} Indicates whether the socket should be paused on incoming connections. \*\*Default:\*\* `false`. \* `blockList` {net.BlockList} `blockList` can be used for disabling inbound access to specific IP addresses, IP ranges, or IP subnets. This does not work if the server is behind a reverse proxy, NAT, etc. because the address checked against the block list is the address of the proxy, or the one specified by the NAT. \* `connectionListener` {Function} Automatically set as a listener for the [`'connection'`][] event. \* Returns: {net.Server} Creates a new TCP or [IPC][] server. If `allowHalfOpen` is set to `true`, when the other end of the socket signals the end of transmission, the server will only send back the end of transmission when [`socket.end()`][] is explicitly called. For example, in the context of TCP, when a FIN packed is received, a FIN packed is sent back only when [`socket.end()`][] is explicitly called. Until then the connection is half-closed (non-readable but still writable). See [`'end'`][] event and [RFC 1122][half-closed] (section 4.2.2.13) for more information. If `pauseOnConnect` is set to `true`, then the socket associated with each incoming connection will be paused, and no data will be read from its handle. This allows connections to be passed between processes without any data being read by the original process. To begin reading data from a paused socket, call [`socket.resume()`][]. The server can be a TCP server or an [IPC][] server, depending on what it [`listen()`][`server.listen()`] to. Here is an example of a TCP echo server which listens for connections on port 8124: ```mjs import net from 'node:net'; const server = net.createServer((c) => { // 'connection' listener. console.log('client connected'); c.on('end', () => { console.log('client disconnected'); }); c.write('hello\r\n'); c.pipe(c); }); server.on('error', (err) => { throw err; }); server.listen(8124, () => { console.log('server bound'); }); ``` ```cjs const net = require('node:net'); const server = net.createServer((c) => { // 'connection' listener. console.log('client connected'); c.on('end', () => { console.log('client disconnected'); }); c.write('hello\r\n'); c.pipe(c); }); server.on('error', (err) => { throw err; }); server.listen(8124, () => { console.log('server bound'); }); ``` Test this by using `telnet`: ```bash telnet localhost 8124 ``` To listen on the socket `/tmp/echo.sock`: ```js server.listen('/tmp/echo.sock', () => { console.log('server bound'); }); ``` Use `nc` to connect to a Unix domain socket server: ```bash nc -U /tmp/echo.sock ``` ## `net.getDefaultAutoSelectFamily()` Gets the current default value of the `autoSelectFamily` option of [`socket.connect(options)`][]. The initial default value is `true`, unless the command line option `--no-network-family-autoselection` is provided. \* Returns: {boolean} The current default value of the `autoSelectFamily` option. ## `net.setDefaultAutoSelectFamily(value)` Sets the default value of the `autoSelectFamily` option of [`socket.connect(options)`][]. \* `value` {boolean} The new default value. The initial default value is `true`, unless the command line option `--no-network-family-autoselection` is provided. ## `net.getDefaultAutoSelectFamilyAttemptTimeout()` Gets the current default value of the `autoSelectFamilyAttemptTimeout` option of [`socket.connect(options)`][]. The initial
|
https://github.com/nodejs/node/blob/main//doc/api/net.md
|
main
|
nodejs
|
[
-0.08017890155315399,
-0.010540470480918884,
-0.05368269979953766,
0.0633891224861145,
-0.011313932947814465,
-0.03412109985947609,
0.012681457214057446,
-0.04286983236670494,
0.004388953093439341,
0.0016101875808089972,
-0.04322333633899689,
0.07340944558382034,
-0.03235118091106415,
0.009985869750380516,
-0.06751629710197449,
-0.02110164985060692,
-0.008000886999070644,
-0.0675896406173706,
0.027525680139660835,
-0.061737433075904846,
-0.01798141375184059,
-0.006228301208466291,
0.027214864268898964,
-0.04082506150007248,
-0.031915780156850815,
0.01991937682032585,
0.03520815819501877,
-0.013721759431064129,
0.03644754737615585,
0.05052203685045242,
-0.003742992179468274,
-0.021312562748789787,
-0.08742938190698624,
-0.026356391608715057,
-0.011178982444107533,
0.05704742670059204,
0.04507081210613251,
-0.013991998508572578,
-0.09322546422481537,
-0.013559707440435886,
0.11140286922454834,
-0.06580311805009842,
-0.06820148229598999,
0.012740926817059517,
-0.05204097554087639,
0.03140203282237053,
-0.03864980861544609,
-0.018725113943219185,
-0.06860323995351791,
0.015151591040194035,
-0.04107231646776199,
0.0033816329669207335,
-0.02250279113650322,
0.0581347793340683,
0.08307796716690063,
-0.03600507229566574,
-0.027919061481952667,
0.01674662157893181,
-0.05996144935488701,
0.019283419474959373,
0.022916477173566818,
0.018059825524687767,
-0.02583073079586029,
0.005982591304928064,
0.007235120981931686,
0.02458886057138443,
0.009786332026124,
0.0034781116992235184,
0.0565979927778244,
-0.00002024146670009941,
-0.048860326409339905,
0.07826946675777435,
-0.08413189649581909,
-0.03332117944955826,
-0.01083127036690712,
-0.042398981750011444,
0.039721596986055374,
-0.02650960348546505,
-0.06295676529407501,
0.031765181571245193,
-0.017556248232722282,
-0.09168250858783722,
-0.02006576582789421,
0.08883390575647354,
0.013400663621723652,
0.05474400147795677,
-0.003456106875091791,
-0.007701959926635027,
0.03418222442269325,
0.04790655896067619,
-0.06904072314500809,
0.045291561633348465,
0.020615339279174805,
0.04176478087902069,
0.011513261124491692,
0.05993032082915306,
-0.006111450958997011,
0.040228359401226044,
-0.08572670817375183,
-0.012501019984483719,
0.029931429773569107,
-0.05439714714884758,
-0.038727082312107086,
-0.035047825425863266,
0.13257494568824768,
-0.0708421841263771,
-0.0029567619785666466,
0.02948935329914093,
0.0750342309474945,
-0.026372328400611877,
-0.029799656942486763,
0.0061922683380544186,
0.03921467065811157,
0.04974089935421944,
-0.06059766560792923,
0.06559912860393524,
-0.0410134457051754,
0.03667174279689789,
0.011872515082359314,
0.0723571628332138,
0.07379098981618881,
-0.03069809079170227,
-0.030899617820978165,
-0.042249374091625214,
0.012210080400109291,
0.027107611298561096,
0.05335104092955589,
1.5234320461290458e-33,
0.025781087577342987,
-0.09425172209739685,
-0.07776929438114166,
0.0007425649091601372,
0.02418539486825466,
-0.007403511554002762,
0.04158084839582443,
0.05801679193973541,
-0.07496995478868484,
0.0000174036013049772,
-0.0205997247248888,
-0.006036187056452036,
-0.03224875032901764,
0.020719369873404503,
0.03588520362973213,
-0.05148887634277344,
0.05588695779442787,
-0.013152250088751316,
0.07767608761787415,
0.01872623711824417,
0.0367351695895195,
-0.06001552194356918,
-0.041079070419073105,
-0.06447180360555649,
-0.0256644319742918,
-0.0065737441182136536,
-0.043446872383356094,
0.01515799481421709,
-0.017348328605294228,
0.007759248837828636,
-0.020118659362196922,
-0.03236955776810646,
-0.014824947342276573,
-0.0010814025299623609,
-0.025629455223679543,
-0.06959468871355057,
-0.013720313087105751,
-0.046012718230485916,
-0.027542078867554665,
-0.03995991498231888,
0.011982538737356663,
-0.0309685617685318,
-0.12657015025615692,
0.05880405381321907,
-0.03336445614695549,
-0.06819524616003036,
-0.14571520686149597,
0.02828613668680191,
0.047235626727342606,
-0.0014113434590399265,
0.022114455699920654,
0.016592785716056824,
0.03334275260567665,
0.0221464391797781,
-0.04185174033045769,
-0.03451939672231674,
-0.025060830637812614,
0.06487872451543808,
-0.016461748629808426,
-0.002011251403018832,
-0.01115275640040636,
0.049449384212493896,
-0.02277146279811859,
-0.06535475701093674,
0.07601097971200943,
0.08239094167947769,
0.05513063073158264,
-0.01376505009829998,
-0.043453071266412735,
-0.04710492491722107,
-0.09460476040840149,
0.015391644090414047,
-0.029098626226186752,
0.05948810651898384,
-0.1130109503865242,
0.03537388890981674,
0.0011815238976851106,
-0.028772873803973198,
0.017923470586538315,
-0.013608310371637344,
0.04209361597895622,
0.050551652908325195,
0.01700633391737938,
0.05938250198960304,
-0.0066659217700362206,
-0.05021641403436661,
-0.010145027190446854,
-0.08907528966665268,
-0.02105085551738739,
0.002312327967956662,
0.031476881355047226,
0.0050860121846199036,
0.15393170714378357,
-0.06807345896959305,
-0.05113019794225693,
-3.796364065788182e-33,
-0.039499279111623764,
-0.02673630602657795,
-0.13118161261081696,
0.04086499288678169,
-0.0313899964094162,
-0.06244296208024025,
-0.009922306053340435,
0.023538731038570404,
-0.013440998271107674,
-0.05701655149459839,
0.051403410732746124,
0.02637779340147972,
0.008719324134290218,
-0.028970500454306602,
-0.025606511160731316,
-0.05130260810256004,
-0.055992864072322845,
0.02240118756890297,
0.022943809628486633,
0.004425075836479664,
0.0038140895776450634,
0.0030184059869498014,
0.09122148901224136,
0.019195934757590294,
-0.0797942578792572,
0.014278790913522243,
0.010732478462159634,
-0.03165614977478981,
-0.1101338192820549,
-0.004817311652004719,
0.06277935206890106,
0.052204281091690063,
-0.01744159683585167,
-0.017101559787988663,
-0.05843619257211685,
0.06034567207098007,
0.02813412994146347,
0.026905862614512444,
0.033452242612838745,
0.08364082127809525,
0.18929697573184967,
-0.03542936593294144,
-0.03690383955836296,
-0.0008695389260537922,
0.032735470682382584,
0.05002053454518318,
-0.05404708534479141,
-0.013711192645132542,
-0.051901765167713165,
0.017044220119714737,
0.060282621532678604,
-0.022153915837407112,
0.05019841343164444,
0.08206308633089066,
0.039860568940639496,
0.07513674348592758,
0.10834736377000809,
-0.03914061188697815,
0.034975435584783554,
-0.03713115304708481,
0.126713365316391,
-0.11899418383836746,
-0.05268317833542824,
0.05432608351111412,
0.021495172753930092,
0.03748054429888725,
0.00451939320191741,
0.036712855100631714,
0.04787823185324669,
-0.07136610895395279,
0.03680173680186272,
-0.007228600326925516,
-0.018241390585899353,
0.04138173162937164,
0.04738067835569382,
0.02497212402522564,
-0.07213295251131058,
-0.0317113921046257,
-0.05298240855336189,
0.11408106982707977,
-0.0609433650970459,
0.12191358953714371,
-0.11524155735969543,
-0.007890422828495502,
0.043717578053474426,
-0.06952019035816193,
-0.03351037576794624,
0.013376021757721901,
0.01369973924010992,
-0.010849972255527973,
-0.0267439316958189,
0.04629189521074295,
-0.11404453217983246,
0.007029722444713116,
-0.030126988887786865,
-4.5047187313684844e-8,
-0.0383257120847702,
-0.02776334248483181,
-0.03371235728263855,
0.02524821273982525,
-0.0032680172007530928,
0.023398105055093765,
0.019817600026726723,
-0.0638589859008789,
0.07229750603437424,
0.020607443526387215,
-0.04103681072592735,
-0.025299955159425735,
-0.010473609901964664,
-0.04644087702035904,
0.05422913655638695,
0.02220643125474453,
0.052264828234910965,
-0.0445278137922287,
-0.02002618834376335,
-0.06330493092536926,
0.05743802711367607,
-0.04972337186336517,
-0.040448494255542755,
0.08271194249391556,
-0.022428860887885094,
-0.03214804828166962,
0.1569419801235199,
0.06424711644649506,
-0.0887298583984375,
0.03639310598373413,
-0.023488564416766167,
0.012881090864539146,
0.07387848198413849,
0.08236768841743469,
-0.059912409633398056,
0.1154589056968689,
-0.10218190401792526,
0.058583296835422516,
-0.00852187443524599,
0.11924862116575241,
-0.014631886035203934,
-0.019626766443252563,
-0.09032565355300903,
0.025234278291463852,
0.03778001293540001,
-0.0016093389131128788,
0.044999994337558746,
0.09050630778074265,
-0.017049502581357956,
0.013464747928082943,
0.013802818022668362,
-0.0011698623420670629,
0.02854141592979431,
-0.022697854787111282,
0.021250542253255844,
0.002493683248758316,
-0.000002894898671002011,
-0.01669921725988388,
-0.02506498619914055,
-0.008011107333004475,
0.0436270646750927,
0.10723838210105896,
0.018061650916934013,
0.0009844162268564105
] | 0.068956
|
`autoSelectFamily` option. ## `net.setDefaultAutoSelectFamily(value)` Sets the default value of the `autoSelectFamily` option of [`socket.connect(options)`][]. \* `value` {boolean} The new default value. The initial default value is `true`, unless the command line option `--no-network-family-autoselection` is provided. ## `net.getDefaultAutoSelectFamilyAttemptTimeout()` Gets the current default value of the `autoSelectFamilyAttemptTimeout` option of [`socket.connect(options)`][]. The initial default value is `500` or the value specified via the command line option `--network-family-autoselection-attempt-timeout`. \* Returns: {number} The current default value of the `autoSelectFamilyAttemptTimeout` option. ## `net.setDefaultAutoSelectFamilyAttemptTimeout(value)` Sets the default value of the `autoSelectFamilyAttemptTimeout` option of [`socket.connect(options)`][]. \* `value` {number} The new default value, which must be a positive number. If the number is less than `10`, the value `10` is used instead. The initial default value is `250` or the value specified via the command line option `--network-family-autoselection-attempt-timeout`. ## `net.isIP(input)` \* `input` {string} \* Returns: {integer} Returns `6` if `input` is an IPv6 address. Returns `4` if `input` is an IPv4 address in [dot-decimal notation][] with no leading zeroes. Otherwise, returns `0`. ```js net.isIP('::1'); // returns 6 net.isIP('127.0.0.1'); // returns 4 net.isIP('127.000.000.001'); // returns 0 net.isIP('127.0.0.1/24'); // returns 0 net.isIP('fhqwhgads'); // returns 0 ``` ## `net.isIPv4(input)` \* `input` {string} \* Returns: {boolean} Returns `true` if `input` is an IPv4 address in [dot-decimal notation][] with no leading zeroes. Otherwise, returns `false`. ```js net.isIPv4('127.0.0.1'); // returns true net.isIPv4('127.000.000.001'); // returns false net.isIPv4('127.0.0.1/24'); // returns false net.isIPv4('fhqwhgads'); // returns false ``` ## `net.isIPv6(input)` \* `input` {string} \* Returns: {boolean} Returns `true` if `input` is an IPv6 address. Otherwise, returns `false`. ```js net.isIPv6('::1'); // returns true net.isIPv6('fhqwhgads'); // returns false ``` [IPC]: #ipc-support [Identifying paths for IPC connections]: #identifying-paths-for-ipc-connections [RFC 8305]: https://www.rfc-editor.org/rfc/rfc8305.txt [Readable Stream]: stream.md#class-streamreadable [`'close'`]: #event-close [`'connect'`]: #event-connect [`'connection'`]: #event-connection [`'data'`]: #event-data [`'drain'`]: #event-drain [`'end'`]: #event-end [`'error'`]: #event-error\_1 [`'listening'`]: #event-listening [`'timeout'`]: #event-timeout [`EventEmitter`]: events.md#class-eventemitter [`child\_process.fork()`]: child\_process.md#child\_processforkmodulepath-args-options [`dns.lookup()`]: dns.md#dnslookuphostname-options-callback [`dns.lookup()` hints]: dns.md#supported-getaddrinfo-flags [`net.Server`]: #class-netserver [`net.Socket`]: #class-netsocket [`net.connect()`]: #netconnect [`net.connect(options)`]: #netconnectoptions-connectlistener [`net.connect(path)`]: #netconnectpath-connectlistener [`net.connect(port, host)`]: #netconnectport-host-connectlistener [`net.createConnection()`]: #netcreateconnection [`net.createConnection(options)`]: #netcreateconnectionoptions-connectlistener [`net.createConnection(path)`]: #netcreateconnectionpath-connectlistener [`net.createConnection(port, host)`]: #netcreateconnectionport-host-connectlistener [`net.createServer()`]: #netcreateserveroptions-connectionlistener [`net.getDefaultAutoSelectFamily()`]: #netgetdefaultautoselectfamily [`net.getDefaultAutoSelectFamilyAttemptTimeout()`]: #netgetdefaultautoselectfamilyattempttimeout [`new net.Socket(options)`]: #new-netsocketoptions [`readable.setEncoding()`]: stream.md#readablesetencodingencoding [`server.close()`]: #serverclosecallback [`server.listen()`]: #serverlisten [`server.listen(handle)`]: #serverlistenhandle-backlog-callback [`server.listen(options)`]: #serverlistenoptions-callback [`server.listen(path)`]: #serverlistenpath-backlog-callback [`server.listen(port)`]: #serverlistenport-host-backlog-callback [`socket(7)`]: https://man7.org/linux/man-pages/man7/socket.7.html [`socket.connect()`]: #socketconnect [`socket.connect(options)`]: #socketconnectoptions-connectlistener [`socket.connect(path)`]: #socketconnectpath-connectlistener [`socket.connect(port)`]: #socketconnectport-host-connectlistener [`socket.connecting`]: #socketconnecting [`socket.destroy()`]: #socketdestroyerror [`socket.end()`]: #socketenddata-encoding-callback [`socket.pause()`]: #socketpause [`socket.resume()`]: #socketresume [`socket.setEncoding()`]: #socketsetencodingencoding [`socket.setKeepAlive()`]: #socketsetkeepaliveenable-initialdelay [`socket.setTimeout()`]: #socketsettimeouttimeout-callback [`socket.setTimeout(timeout)`]: #socketsettimeouttimeout-callback [`stream.getDefaultHighWaterMark()`]: stream.md#streamgetdefaulthighwatermarkobjectmode [`writable.destroy()`]: stream.md#writabledestroyerror [`writable.destroyed`]: stream.md#writabledestroyed [`writable.end()`]: stream.md#writableendchunk-encoding-callback [`writable.writableLength`]: stream.md#writablewritablelength [dot-decimal notation]: https://en.wikipedia.org/wiki/Dot-decimal\_notation [half-closed]: https://tools.ietf.org/html/rfc1122 [stream\_writable\_write]: stream.md#writablewritechunk-encoding-callback [unspecified IPv4 address]: https://en.wikipedia.org/wiki/0.0.0.0 [unspecified IPv6 address]: https://en.wikipedia.org/wiki/IPv6\_address#Unspecified\_address
|
https://github.com/nodejs/node/blob/main//doc/api/net.md
|
main
|
nodejs
|
[
-0.05409163609147072,
-0.012811889871954918,
-0.012036352418363094,
0.09613151848316193,
-0.057652413845062256,
0.025196000933647156,
0.008511303924024105,
-0.00954069197177887,
0.009676696732640266,
0.003192702541127801,
0.012122159823775291,
-0.009574616327881813,
-0.07069991528987885,
0.010015344247221947,
-0.07147345691919327,
0.009168768301606178,
0.054168689996004105,
-0.14461448788642883,
-0.0013111068401485682,
-0.03861718624830246,
0.00953095592558384,
-0.06000491604208946,
0.015945326536893845,
-0.08867581933736801,
0.06559538096189499,
-0.07778974622488022,
0.03680819645524025,
-0.022062458097934723,
0.01191386952996254,
0.024326516315340996,
-0.04647385701537132,
0.032806266099214554,
-0.020444441586732864,
0.030406225472688675,
-0.010704467073082924,
-0.04128462076187134,
-0.005112569313496351,
0.0548139326274395,
-0.019113104790449142,
-0.04000375419855118,
0.09282570332288742,
-0.07853531092405319,
-0.031216157600283623,
-0.00983653124421835,
0.017761025577783585,
0.03490392491221428,
-0.02255450002849102,
-0.03937967121601105,
-0.004070744384080172,
-0.004306770395487547,
-0.007549558766186237,
0.07207085937261581,
-0.012080096639692783,
-0.0030046033207327127,
0.12201280146837234,
0.0739707350730896,
-0.04445108026266098,
0.06069982796907425,
-0.030840612947940826,
0.0635533556342125,
-0.012559606693685055,
-0.05501857027411461,
-0.062084801495075226,
0.005316598806530237,
-0.007188280113041401,
0.09553427994251251,
0.07589523494243622,
-0.08168146014213562,
0.009901135228574276,
0.10265272110700607,
-0.05392907187342644,
0.06514348834753036,
-0.059498921036720276,
-0.032379597425460815,
0.07684870064258575,
0.03603450953960419,
-0.03785701468586922,
-0.04988276585936546,
0.008833618834614754,
-0.023941146209836006,
-0.016726741567254066,
0.007069902960211039,
-0.0633988156914711,
0.0640399307012558,
0.0025485355872660875,
0.06695255637168884,
-0.015236702747642994,
-0.0019046448869630694,
-0.0109218405559659,
-0.0007183592533692718,
-0.08442992717027664,
-0.058009225875139236,
-0.03652612864971161,
0.030664771795272827,
0.02216469496488571,
0.05283428728580475,
0.05729014053940773,
-0.02660353295505047,
-0.029420293867588043,
-0.053135037422180176,
0.01470195036381483,
-0.06608843058347702,
-0.03682404011487961,
-0.016211945563554764,
0.0005346578545868397,
-0.08639160543680191,
0.001767563633620739,
0.02729984186589718,
0.036273322999477386,
0.07040952891111374,
-0.04122443124651909,
0.0005480222753249109,
0.07673715054988861,
-0.001816160511225462,
-0.04278251528739929,
0.09707847237586975,
0.03167128935456276,
0.04316917806863785,
0.0780038833618164,
0.011100394651293755,
-0.006504116114228964,
-0.004355391953140497,
-0.010476731695234776,
-0.08212842792272568,
-0.025082657113671303,
0.0025207106955349445,
0.025270644575357437,
6.465580394035459e-33,
-0.00972703006118536,
-0.07048750668764114,
-0.05657427757978439,
-0.061124037951231,
-0.026182278990745544,
-0.06308185309171677,
0.024911725893616676,
0.009970070794224739,
-0.012284725904464722,
0.07039830833673477,
-0.05044824257493019,
0.015820616856217384,
0.020375192165374756,
-0.008856859058141708,
-0.032760921865701675,
0.008109224028885365,
0.014114785939455032,
0.025539549067616463,
0.15706372261047363,
0.01840704306960106,
0.06993799656629562,
-0.047275710850954056,
0.02840808965265751,
-0.07547274231910706,
0.022687315940856934,
-0.014657193794846535,
-0.012895708903670311,
0.08155078440904617,
-0.06186265870928764,
0.008086626417934895,
-0.02283991128206253,
0.018473457545042038,
0.018410081043839455,
-0.05269778519868851,
-0.023627717047929764,
-0.004367842338979244,
-0.038003358989953995,
-0.004870344884693623,
-0.02416590228676796,
-0.013589360751211643,
0.04098111763596535,
-0.019636845216155052,
-0.08649566769599915,
0.0427565835416317,
-0.012789413332939148,
-0.10755408555269241,
-0.07945198565721512,
-0.011415481567382812,
-0.0034560230560600758,
0.049497298896312714,
0.03811558336019516,
-0.0064430516213178635,
0.0001753430115059018,
0.007120154798030853,
0.025091061368584633,
0.002350128721445799,
0.009709320962429047,
0.09466239809989929,
-0.010363973677158356,
0.002684525214135647,
0.010110712610185146,
-0.07885371893644333,
-0.020457789301872253,
-0.027450865134596825,
0.10643715411424637,
0.09121035039424896,
0.02399669773876667,
-0.04195179045200348,
-0.07354582101106644,
0.0016515097813680768,
-0.034818265587091446,
-0.0018977291183546185,
-0.03977444767951965,
-0.07009945809841156,
-0.03654834255576134,
0.019955934956669807,
-0.0012663495726883411,
-0.02426467090845108,
-0.015415698289871216,
-0.021820122376084328,
0.012677646242082119,
0.05608741194009781,
-0.008671452291309834,
0.012873047031462193,
0.05276374891400337,
-0.023396166041493416,
0.034841880202293396,
-0.038385167717933655,
-0.06611716002225876,
0.01645168475806713,
0.039621174335479736,
0.024057533591985703,
0.10521702468395233,
-0.0023526574950665236,
-0.0251533854752779,
-6.950458589438206e-33,
0.06695063412189484,
0.0049720932729542255,
-0.050861164927482605,
0.056608133018016815,
0.02869846299290657,
-0.05646931380033493,
-0.0168538186699152,
0.07984167337417603,
0.04181545600295067,
-0.051813311874866486,
0.09783368557691574,
-0.0024339205119758844,
0.06447065621614456,
-0.05021686851978302,
-0.02850424312055111,
0.025359060615301132,
-0.07021687924861908,
-0.048934780061244965,
0.06347032636404037,
0.0832754522562027,
0.01758032664656639,
-0.00036841476685367525,
0.01601799577474594,
-0.02111642435193062,
-0.01640145108103752,
0.011527631431818008,
0.020856311544775963,
0.04705512523651123,
-0.0612054206430912,
-0.0656648799777031,
0.00558552285656333,
0.05179380252957344,
-0.08522213250398636,
0.01288987509906292,
0.00347716617397964,
0.0856405720114708,
0.022391652688384056,
0.06263558566570282,
0.015789777040481567,
0.13889560103416443,
0.15866775810718536,
0.0016415576683357358,
-0.15413972735404968,
0.05394026264548302,
0.009309115819633007,
0.017485236749053,
-0.030385099351406097,
-0.02227744460105896,
-0.05572185665369034,
0.009989896789193153,
-0.009129106067121029,
-0.05416042357683182,
0.07426212728023529,
0.09401945024728775,
0.05324725806713104,
0.10227812081575394,
0.12403927743434906,
-0.03458911180496216,
0.07139118015766144,
0.04872235283255577,
0.05062982439994812,
-0.12999822199344635,
0.01639844849705696,
0.08676373213529587,
0.019192537292838097,
0.05198777839541435,
-0.03987164422869682,
0.06111528351902962,
0.017457300797104836,
0.007009567692875862,
0.022861767560243607,
0.0059877117164433,
0.0065969727002084255,
-0.017422450706362724,
-0.02185129001736641,
-0.004366269335150719,
-0.02423265017569065,
0.0033839368261396885,
-0.0010173965711146593,
0.05715470016002655,
-0.08907300978899002,
0.09892141819000244,
-0.1188359335064888,
-0.01569553092122078,
-0.055876996368169785,
0.006291688419878483,
-0.05159078165888786,
0.11734335869550705,
0.0784141942858696,
0.014866543933749199,
-0.06014192849397659,
-0.022341912612318993,
-0.032021667808294296,
-0.020595606416463852,
-0.08643677830696106,
-4.829821875773632e-8,
-0.05825759097933769,
0.02726036310195923,
-0.0032986332662403584,
0.03319251164793968,
0.0830729529261589,
0.01978432945907116,
-0.03086044080555439,
-0.05531276389956474,
-0.014984109438955784,
-0.01717056892812252,
-0.018328309059143066,
0.013946402817964554,
0.008093887008726597,
-0.02859656885266304,
0.020218124613165855,
0.015807971358299255,
0.0032916751224547625,
-0.04954811930656433,
0.009111153893172741,
-0.032281678169965744,
-0.024582047015428543,
-0.09103809297084808,
-0.02541547268629074,
0.00622008228674531,
-0.008662126958370209,
-0.04453155770897865,
0.0682264193892479,
0.0718449205160141,
-0.10982585698366165,
0.08945756405591965,
-0.11805641651153564,
0.03519771248102188,
0.01879180036485195,
-0.01333649642765522,
-0.1037164032459259,
0.04584158957004547,
-0.06229062378406525,
-0.030674146488308907,
-0.0072957598604261875,
0.022913562133908272,
0.011571863666176796,
-0.03366004675626755,
-0.11555956304073334,
-0.016666434705257416,
-0.09085249900817871,
0.01179411355406046,
0.031318165361881256,
0.10009758174419403,
0.024540599435567856,
-0.0313052162528038,
-0.023976575583219528,
-0.050375428050756454,
0.015606557950377464,
-0.05551394447684288,
0.05693242326378822,
-0.02096327394247055,
0.022712506353855133,
-0.026941955089569092,
0.01275740284472704,
0.006013952661305666,
-0.04607010260224342,
0.07382501661777496,
-0.05252162367105484,
-0.046116042882204056
] | 0.055396
|
# Global objects > Stability: 2 - Stable These objects are available in all modules. The following variables may appear to be global but are not. They exist only in the scope of [CommonJS modules][]: \* [`\_\_dirname`][] \* [`\_\_filename`][] \* [`exports`][] \* [`module`][] \* [`require()`][] The objects listed here are specific to Node.js. There are [built-in objects][] that are part of the JavaScript language itself, which are also globally accessible. ## Class: `AbortController` A utility class used to signal cancelation in selected `Promise`-based APIs. The API is based on the Web API {AbortController}. ```js const ac = new AbortController(); ac.signal.addEventListener('abort', () => console.log('Aborted!'), { once: true }); ac.abort(); console.log(ac.signal.aborted); // Prints true ``` ### `abortController.abort([reason])` \* `reason` {any} An optional reason, retrievable on the `AbortSignal`'s `reason` property. Triggers the abort signal, causing the `abortController.signal` to emit the `'abort'` event. ### `abortController.signal` \* Type: {AbortSignal} ### Class: `AbortSignal` \* Extends: {EventTarget} The `AbortSignal` is used to notify observers when the `abortController.abort()` method is called. #### Static method: `AbortSignal.abort([reason])` \* `reason` {any} \* Returns: {AbortSignal} Returns a new already aborted `AbortSignal`. #### Static method: `AbortSignal.timeout(delay)` \* `delay` {number} The number of milliseconds to wait before triggering the AbortSignal. Returns a new `AbortSignal` which will be aborted in `delay` milliseconds. #### Static method: `AbortSignal.any(signals)` \* `signals` {AbortSignal\[]} The `AbortSignal`s of which to compose a new `AbortSignal`. Returns a new `AbortSignal` which will be aborted if any of the provided signals are aborted. Its [`abortSignal.reason`][] will be set to whichever one of the `signals` caused it to be aborted. #### Event: `'abort'` The `'abort'` event is emitted when the `abortController.abort()` method is called. The callback is invoked with a single object argument with a single `type` property set to `'abort'`: ```js const ac = new AbortController(); // Use either the onabort property... ac.signal.onabort = () => console.log('aborted!'); // Or the EventTarget API... ac.signal.addEventListener('abort', (event) => { console.log(event.type); // Prints 'abort' }, { once: true }); ac.abort(); ``` The `AbortController` with which the `AbortSignal` is associated will only ever trigger the `'abort'` event once. We recommended that code check that the `abortSignal.aborted` attribute is `false` before adding an `'abort'` event listener. Any event listeners attached to the `AbortSignal` should use the `{ once: true }` option (or, if using the `EventEmitter` APIs to attach a listener, use the `once()` method) to ensure that the event listener is removed as soon as the `'abort'` event is handled. Failure to do so may result in memory leaks. #### `abortSignal.aborted` \* Type: {boolean} True after the `AbortController` has been aborted. #### `abortSignal.onabort` \* Type: {Function} An optional callback function that may be set by user code to be notified when the `abortController.abort()` function has been called. #### `abortSignal.reason` \* Type: {any} An optional reason specified when the `AbortSignal` was triggered. ```js const ac = new AbortController(); ac.abort(new Error('boom!')); console.log(ac.signal.reason); // Error: boom! ``` #### `abortSignal.throwIfAborted()` If `abortSignal.aborted` is `true`, throws `abortSignal.reason`. ## Class: `Blob` See {Blob}. ## Class: `Buffer` \* Type: {Function} Used to handle binary data. See the [buffer section][]. ## Class: `ByteLengthQueuingStrategy` A browser-compatible implementation of [`ByteLengthQueuingStrategy`][]. ## `\_\_dirname` This variable may appear to be global but is not. See [`\_\_dirname`][]. ## `\_\_filename` This variable may appear to be global but is not. See [`\_\_filename`][]. ## `atob(data)` > Stability: 3 - Legacy. Use `Buffer.from(data, 'base64')` instead. Global alias for [`buffer.atob()`][]. An automated migration is available ([source](https://github.com/nodejs/userland-migrations/tree/main/recipes/buffer-atob-btoa)): ```bash npx codemod@latest @nodejs/buffer-atob-btoa ``` ## Class: `BroadcastChannel` See {BroadcastChannel}. ## `btoa(data)` > Stability: 3 - Legacy. Use `buf.toString('base64')` instead. Global alias for [`buffer.btoa()`][]. An automated migration is available ([source](https://github.com/nodejs/userland-migrations/tree/main/recipes/buffer-atob-btoa)): ```bash npx codemod@latest @nodejs/buffer-atob-btoa ``` ## `clearImmediate(immediateObject)` [`clearImmediate`][] is described
|
https://github.com/nodejs/node/blob/main//doc/api/globals.md
|
main
|
nodejs
|
[
-0.11156794428825378,
0.012330040335655212,
-0.011101549491286278,
0.06249058246612549,
0.11020249128341675,
-0.03642728552222252,
0.02359432727098465,
0.044272974133491516,
0.03062209114432335,
-0.018858060240745544,
0.006685365457087755,
0.08686023950576782,
-0.05974822863936424,
-0.03532915189862251,
0.010284796357154846,
0.045911721885204315,
-0.03413086757063866,
0.029918557032942772,
-0.07682114094495773,
-0.010193640366196632,
0.08516934514045715,
0.07206688076257706,
0.023106953129172325,
0.013713497668504715,
-0.04825598746538162,
-0.006653902120888233,
-0.022249901667237282,
-0.040554583072662354,
0.04017530381679535,
-0.023891741409897804,
-0.014010598883032799,
-0.018408911302685738,
-0.10031741112470627,
0.011933015659451485,
-0.055927176028490067,
0.11033089458942413,
-0.030259491875767708,
-0.12364763021469116,
0.050816282629966736,
-0.05756586045026779,
0.042947493493556976,
0.14657650887966156,
-0.07442304491996765,
-0.07571381330490112,
0.02840178646147251,
-0.03220662474632263,
-0.0976187065243721,
-0.015660341829061508,
-0.11339008808135986,
-0.0033486210741102695,
0.0007151707541197538,
-0.013320721685886383,
-0.07475943863391876,
-0.0009159070323221385,
0.04099702090024948,
0.004880177788436413,
-0.012553328648209572,
-0.002057678997516632,
0.032825060188770294,
0.11122587323188782,
-0.015280341729521751,
0.0191794540733099,
0.03372810781002045,
0.023626817390322685,
0.09720320999622345,
0.032852161675691605,
0.0019775654654949903,
0.004905051086097956,
0.023144857957959175,
0.028978826478123665,
-0.05688083916902542,
-0.004087551962584257,
0.013284253887832165,
0.02429158054292202,
-0.02759666182100773,
-0.08866376429796219,
-0.02988501824438572,
-0.004783501848578453,
-0.02850496582686901,
0.00994048174470663,
-0.033176347613334656,
-0.07699734717607498,
0.011589134112000465,
0.010840543545782566,
-0.03427988290786743,
0.11545585840940475,
-0.006949061993509531,
0.04357194900512695,
0.01677537150681019,
-0.007586446590721607,
-0.10392338782548904,
-0.06204203516244888,
0.03676525503396988,
0.07415322214365005,
-0.04375365003943443,
-0.011438144370913506,
0.05344832316040993,
-0.05774996429681778,
-0.03843623027205467,
0.016428053379058838,
-0.007871461100876331,
0.002207533223554492,
0.07098176330327988,
-0.00696959812194109,
0.02795279584825039,
-0.05975174903869629,
-0.022315552458167076,
-0.007595977745950222,
0.019306670874357224,
0.008459244854748249,
-0.055438898503780365,
0.045592162758111954,
-0.059215299785137177,
-0.06663592159748077,
-0.06053682044148445,
-0.0006088634836487472,
0.04780308157205582,
-0.017994597554206848,
0.10130403190851212,
0.09796088933944702,
0.12660157680511475,
0.03687024116516113,
0.0573093481361866,
-0.016033515334129333,
0.06457708030939102,
-0.008938690647482872,
0.018396465107798576,
1.4550701619665179e-33,
-0.016619088128209114,
-0.14053457975387573,
-0.019935209304094315,
0.10073759406805038,
0.050553809851408005,
0.023132044821977615,
0.029456086456775665,
0.028937770053744316,
-0.06841306388378143,
0.036864761263132095,
-0.03903723508119583,
0.06412487477064133,
-0.011463694274425507,
0.03652581945061684,
0.045267485082149506,
-0.04535550996661186,
0.08146229386329651,
0.006576303392648697,
0.1049199029803276,
0.00747947720810771,
0.035800449550151825,
-0.00047344318591058254,
-0.006421405356377363,
0.07061050087213516,
0.06324593722820282,
0.04351292923092842,
0.0073775118216872215,
0.063561350107193,
-0.01726100966334343,
0.0032363496720790863,
0.0363072007894516,
0.0435643270611763,
-0.030058391392230988,
0.05039721354842186,
0.04607256501913071,
-0.01412911619991064,
-0.07157353311777115,
0.011221774853765965,
-0.08950547128915787,
-0.040314316749572754,
0.0016984178218990564,
0.024402635172009468,
-0.11794351041316986,
0.004033190198242664,
-0.0023215413093566895,
-0.17484430968761444,
-0.021849600598216057,
-0.050279684364795685,
0.039816007018089294,
-0.02120388112962246,
-0.11162473261356354,
0.07346221804618835,
0.05724858120083809,
-0.04316205903887749,
0.05759672448039055,
-0.01809699274599552,
0.028166351839900017,
-0.022171195596456528,
-0.08461245894432068,
-0.03404433652758598,
0.0695500299334526,
-0.03419104963541031,
-0.03636811301112175,
-0.04011881723999977,
-0.06412605941295624,
0.03544719144701958,
-0.06639233976602554,
-0.06381362676620483,
-0.0014575055101886392,
0.012415705248713493,
-0.012315810658037663,
0.05071873962879181,
0.030726466327905655,
-0.009618180803954601,
0.022188391536474228,
0.023980475962162018,
-0.09895055741071701,
0.02187579683959484,
-0.025461167097091675,
-0.05981991067528725,
0.0034942328929901123,
-0.0442969985306263,
-0.04398709908127785,
0.07219248265028,
0.05352497473359108,
0.011325987055897713,
-0.03482361510396004,
-0.007306239102035761,
0.03243846446275711,
0.05751820653676987,
-0.020468654111027718,
-0.0012809298932552338,
-0.03523731604218483,
-0.07640089094638824,
-0.09349506348371506,
-4.728641288585646e-33,
0.03563084453344345,
0.00729253888130188,
-0.09511319547891617,
0.06917119026184082,
-0.02762605808675289,
-0.02579602226614952,
-0.05592218041419983,
0.00859353132545948,
-0.030510304495692253,
0.001164451939985156,
-0.02731369622051716,
0.06735864281654358,
0.05165417492389679,
0.036036744713783264,
0.030208010226488113,
0.06332332640886307,
-0.08334077894687653,
-0.09884192049503326,
-0.0004718586278613657,
-0.06870023161172867,
0.022719919681549072,
0.024547765031456947,
0.05366482958197594,
-0.0031220070086419582,
-0.03412741795182228,
-0.002832656493410468,
-0.06616315990686417,
-0.02285517379641533,
-0.01724325865507126,
-0.016189321875572205,
-0.040276773273944855,
0.014304819516837597,
-0.029141273349523544,
0.029902303591370583,
0.00008706998050911352,
-0.08494588732719421,
-0.018156051635742188,
0.0741010531783104,
-0.02057064324617386,
-0.05322526767849922,
0.05440621078014374,
0.014081176370382309,
-0.018081823363900185,
0.008029839023947716,
0.009512702003121376,
-0.016713442280888557,
0.023869706317782402,
0.06912670284509659,
0.006711794063448906,
-0.047769948840141296,
-0.04894734174013138,
-0.0923156812787056,
0.028500961139798164,
0.007616973947733641,
-0.008197924122214317,
0.025991316884756088,
0.02797871083021164,
-0.05689820647239685,
0.05242709070444107,
0.07085126638412476,
0.04709357023239136,
-0.11010883003473282,
0.025050699710845947,
0.04661701247096062,
-0.03381994739174843,
-0.02585412934422493,
-0.05687832087278366,
0.019930994138121605,
0.11222929507493973,
0.016377367079257965,
0.05812070891261101,
0.022920208051800728,
-0.03441040590405464,
-0.02482137270271778,
-0.036301951855421066,
0.01603141613304615,
-0.0013765607727691531,
-0.11863159388303757,
0.05122492462396622,
0.013431116007268429,
0.013529661111533642,
0.05996401607990265,
-0.028844468295574188,
0.0812765508890152,
0.023142974823713303,
-0.08151453733444214,
-0.037789132446050644,
0.05073501169681549,
-0.008597909472882748,
0.0006042273016646504,
-0.0091044707223773,
0.07131544500589371,
-0.08455578237771988,
-0.02953873760998249,
-0.07298730313777924,
-5.713278383723264e-8,
-0.09068459272384644,
0.030909227207303047,
-0.08476659655570984,
-0.029881959781050682,
0.004502351861447096,
-0.028301220387220383,
0.025373628363013268,
0.007994350045919418,
0.04164522886276245,
0.04223845526576042,
0.05079147219657898,
0.022036701440811157,
0.031581997871398926,
-0.029408464208245277,
-0.03318062424659729,
0.008749482221901417,
0.0013748221099376678,
0.09836690872907639,
-0.011686195619404316,
0.028130855411291122,
0.01924736611545086,
-0.020004766061902046,
0.03150114417076111,
0.014047905802726746,
0.008877488784492016,
-0.04025719314813614,
0.07523506879806519,
0.09636330604553223,
0.019308913499116898,
-0.013413633219897747,
-0.1305709034204483,
0.0605553537607193,
0.07170434296131134,
0.002823607064783573,
-0.04401861131191254,
0.06274396181106567,
-0.00861099362373352,
0.017809977754950523,
0.029178019613027573,
0.06198657676577568,
0.04708832874894142,
-0.00669702235609293,
-0.057128626853227615,
0.060663897544145584,
0.04265816509723663,
0.001429934985935688,
0.008643022738397121,
0.0038041931111365557,
-0.011955292895436287,
0.017542798072099686,
-0.03766141086816788,
-0.01613355241715908,
-0.08786500245332718,
0.08132900297641754,
-0.03910072520375252,
-0.02744392305612564,
0.007259228266775608,
-0.10400617867708206,
-0.014406317844986916,
-0.004493424668908119,
0.016907505691051483,
0.03500479459762573,
0.030960995703935623,
-0.021876070648431778
] | 0.195707
|
Global alias for [`buffer.atob()`][]. An automated migration is available ([source](https://github.com/nodejs/userland-migrations/tree/main/recipes/buffer-atob-btoa)): ```bash npx codemod@latest @nodejs/buffer-atob-btoa ``` ## Class: `BroadcastChannel` See {BroadcastChannel}. ## `btoa(data)` > Stability: 3 - Legacy. Use `buf.toString('base64')` instead. Global alias for [`buffer.btoa()`][]. An automated migration is available ([source](https://github.com/nodejs/userland-migrations/tree/main/recipes/buffer-atob-btoa)): ```bash npx codemod@latest @nodejs/buffer-atob-btoa ``` ## `clearImmediate(immediateObject)` [`clearImmediate`][] is described in the [timers][] section. ## `clearInterval(intervalObject)` [`clearInterval`][] is described in the [timers][] section. ## `clearTimeout(timeoutObject)` [`clearTimeout`][] is described in the [timers][] section. ## Class: `CloseEvent` A browser-compatible implementation of {CloseEvent}. Disable this API with the [`--no-experimental-websocket`][] CLI flag. ## Class: `CompressionStream` A browser-compatible implementation of [`CompressionStream`][]. ## `console` \* Type: {Object} Used to print to stdout and stderr. See the [`console`][] section. ## Class: `CountQueuingStrategy` A browser-compatible implementation of [`CountQueuingStrategy`][]. ## Class: `Crypto` A browser-compatible implementation of {Crypto}. This global is available only if the Node.js binary was compiled with including support for the `node:crypto` module. ## `crypto` A browser-compatible implementation of the [Web Crypto API][]. ## Class: `CryptoKey` A browser-compatible implementation of {CryptoKey}. This global is available only if the Node.js binary was compiled with including support for the `node:crypto` module. ## Class: `CustomEvent` A browser-compatible implementation of {CustomEvent}. ## Class: `DecompressionStream` A browser-compatible implementation of [`DecompressionStream`][]. ## `ErrorEvent` A browser-compatible implementation of {ErrorEvent}. ## Class: `Event` A browser-compatible implementation of the `Event` class. See [`EventTarget` and `Event` API][] for more details. ## Class: `EventSource` > Stability: 1 - Experimental. Enable this API with the [`--experimental-eventsource`][] > CLI flag. A browser-compatible implementation of {EventSource}. ## Class: `EventTarget` A browser-compatible implementation of the `EventTarget` class. See [`EventTarget` and `Event` API][] for more details. ## `exports` This variable may appear to be global but is not. See [`exports`][]. ## `fetch` A browser-compatible implementation of the [`fetch()`][] function. ```mjs const res = await fetch('https://nodejs.org/api/documentation.json'); if (res.ok) { const data = await res.json(); console.log(data); } ``` The implementation is based upon [undici](https://undici.nodejs.org), an HTTP/1.1 client written from scratch for Node.js. You can figure out which version of `undici` is bundled in your Node.js process reading the `process.versions.undici` property. ### Custom dispatcher You can use a custom dispatcher to dispatch requests passing it in fetch's options object. The dispatcher must be compatible with `undici`'s [`Dispatcher` class](https://undici.nodejs.org/#/docs/api/Dispatcher.md). ```js fetch(url, { dispatcher: new MyAgent() }); ``` It is possible to change the global dispatcher in Node.js by installing `undici` and using the `setGlobalDispatcher()` method. Calling this method will affect both `undici` and Node.js. ```mjs import { setGlobalDispatcher } from 'undici'; setGlobalDispatcher(new MyAgent()); ``` ### Related classes The following globals are available to use with `fetch`: \* [`FormData`](https://nodejs.org/api/globals.html#class-formdata) \* [`Headers`](https://nodejs.org/api/globals.html#class-headers) \* [`Request`](https://nodejs.org/api/globals.html#request) \* [`Response`](https://nodejs.org/api/globals.html#response). ## Class: `File` See {File}. ## Class: `FormData` A browser-compatible implementation of {FormData}. ## `global` > Stability: 3 - Legacy. Use [`globalThis`][] instead. \* Type: {Object} The global namespace object. In browsers, the top-level scope has traditionally been the global scope. This means that `var something` will define a new global variable, except within ECMAScript modules. In Node.js, this is different. The top-level scope is not the global scope; `var something` inside a Node.js module will be local to that module, regardless of whether it is a [CommonJS module][] or an [ECMAScript module][]. ## Class: `Headers` A browser-compatible implementation of {Headers}. ## `localStorage` > Stability: 1.2 - Release candidate. Disable this API with [`--no-experimental-webstorage`][]. A browser-compatible implementation of [`localStorage`][]. Data is stored unencrypted in the file specified by the [`--localstorage-file`][] CLI flag. The maximum amount of data that can be stored is 10 MB. Any modification of this data outside of the Web Storage API is not supported. `localStorage` data is not stored per user or per request when used in the context
|
https://github.com/nodejs/node/blob/main//doc/api/globals.md
|
main
|
nodejs
|
[
0.07068521529436111,
-0.004393004812300205,
-0.060746099799871445,
-0.06191008910536766,
0.059948090463876724,
-0.057586267590522766,
0.04200199246406555,
0.011077199131250381,
-0.026832949370145798,
0.0030088459607213736,
-0.03989153727889061,
-0.06408876925706863,
-0.05550067499279976,
0.01878618821501732,
0.0498267225921154,
0.0426899679005146,
0.02443477138876915,
0.007663310039788485,
0.04416581615805626,
-0.032426584511995316,
0.021843109279870987,
0.1352013498544693,
0.040212247520685196,
0.03045019879937172,
-0.003762868233025074,
-0.05257635563611984,
0.024885887280106544,
-0.06206999719142914,
0.033056557178497314,
-0.015964504331350327,
-0.019341692328453064,
0.08398736268281937,
0.0016597291687503457,
-0.02801826409995556,
0.03405458480119705,
0.1629728376865387,
0.002193593420088291,
-0.02809140272438526,
-0.0372265949845314,
-0.0327877439558506,
0.17535416781902313,
0.06408178806304932,
-0.038861773908138275,
-0.09067327529191971,
0.029823066666722298,
-0.023527855053544044,
-0.03029540181159973,
-0.0313076451420784,
-0.0029577610548585653,
-0.004038084298372269,
0.03272165730595589,
-0.11378445476293564,
-0.06933806836605072,
0.061374884098768234,
-0.05931137502193451,
0.017969252541661263,
-0.06525767594575882,
0.05033325403928757,
0.034359272569417953,
0.07010117918252945,
-0.07531820982694626,
-0.030099328607320786,
0.09501973539590836,
0.004732618108391762,
0.029242606833577156,
-0.008943348191678524,
-0.01757456734776497,
0.015186040662229061,
0.0030066317413002253,
0.05660926178097725,
-0.017891762778162956,
-0.04072457551956177,
-0.06249062716960907,
0.02552768960595131,
-0.05865659937262535,
-0.004383723717182875,
0.029167702421545982,
0.05654476210474968,
-0.05507718026638031,
-0.06563956290483475,
-0.016241857782006264,
-0.12181878089904785,
-0.046601731330156326,
0.043365608900785446,
-0.027983209118247032,
0.11801813542842865,
-0.029275860637426376,
-0.020902900025248528,
0.011508207768201828,
0.016258075833320618,
-0.05384165421128273,
-0.03596071898937225,
0.010826962068676949,
-0.00632648216560483,
-0.06968246400356293,
-0.028636956587433815,
0.022785061970353127,
0.03590676933526993,
0.025196457281708717,
0.0523715578019619,
-0.0349542573094368,
-0.009823121130466461,
-0.008713251911103725,
0.010934868827462196,
-0.04172026738524437,
0.01748930849134922,
0.019899431616067886,
0.020073136314749718,
0.029607495293021202,
0.05435456335544586,
-0.040949199348688126,
0.06026690825819969,
0.014681285247206688,
0.0007802826585248113,
0.028701497241854668,
0.0294896699488163,
-0.021154984831809998,
-0.03099975548684597,
0.09928954392671585,
0.11050808429718018,
0.12366589903831482,
-0.06013823673129082,
-0.028993923217058182,
0.07102157920598984,
-0.01094901841133833,
0.0008992706425487995,
0.05054255202412605,
6.564372337191922e-34,
0.023190069943666458,
-0.03428763151168823,
-0.02430466189980507,
0.07768306881189346,
0.03695247322320938,
-0.023601064458489418,
0.040797159075737,
-0.0011819013161584735,
-0.10194697231054306,
-0.006730340421199799,
-0.0330100953578949,
-0.016938943415880203,
0.005425510462373495,
-0.06363530457019806,
-0.04945610091090202,
-0.038085754960775375,
-0.003118454944342375,
0.013632897287607193,
0.12782691419124603,
0.056474559009075165,
0.0002593249664641917,
0.06664159148931503,
-0.10463380813598633,
0.013984506949782372,
0.04829040914773941,
-0.06317384541034698,
0.006906649563461542,
-0.08980486541986465,
0.00878734141588211,
0.02180967852473259,
-0.01809876412153244,
0.06505444645881653,
-0.02801360748708248,
-0.0000513330778630916,
-0.05669352412223816,
-0.08203399181365967,
-0.01019688043743372,
0.04702972620725632,
-0.12950833141803741,
-0.024382639676332474,
0.028117364272475243,
0.05315278097987175,
-0.10911194235086441,
0.0038631923962384462,
0.07022922486066818,
-0.11825288832187653,
-0.02577907033264637,
0.0365494005382061,
0.08790402114391327,
0.033161964267492294,
-0.006820806302130222,
-0.015755511820316315,
0.024319039657711983,
-0.05012119188904762,
0.016142170876264572,
-0.061959680169820786,
0.027291879057884216,
0.008527386002242565,
-0.017829326912760735,
0.015319802798330784,
0.05600506439805031,
0.075156070291996,
0.010861615650355816,
0.02600320242345333,
0.06891945749521255,
0.022472543641924858,
-0.02506965771317482,
-0.011288659647107124,
-0.02692176029086113,
-0.014198306016623974,
-0.05551961064338684,
0.023453272879123688,
-0.01945144310593605,
0.03435513377189636,
-0.0493517629802227,
-0.018746333196759224,
-0.06921704858541489,
0.038335222750902176,
-0.007597639691084623,
-0.04155454412102699,
0.0700497031211853,
0.01682290993630886,
-0.06152217835187912,
0.042588237673044205,
0.03731244429945946,
-0.017148388549685478,
0.018782498314976692,
-0.04719958454370499,
-0.07385727018117905,
0.025739429518580437,
0.08430022746324539,
-0.027620907872915268,
0.0016150233568623662,
-0.04456314444541931,
-0.08521390706300735,
-1.1431431850842235e-33,
0.05472283810377121,
0.016447067260742188,
-0.09387379884719849,
0.10375533998012543,
-0.04164978116750717,
-0.08111712336540222,
0.09477481245994568,
0.03796663507819176,
-0.024502726271748543,
-0.04730719327926636,
-0.05573016032576561,
0.07863554358482361,
0.04162788391113281,
-0.008822496049106121,
-0.003026493126526475,
-0.023530712351202965,
-0.0017741858027875423,
-0.08148469775915146,
-0.004069537855684757,
-0.043927162885665894,
-0.02106574736535549,
0.028022171929478645,
0.06807341426610947,
0.009562614373862743,
-0.05562972649931908,
0.05519386753439903,
0.0039029805921018124,
0.09207771718502045,
-0.038761842995882034,
-0.02835962362587452,
-0.07662630081176758,
0.061608411371707916,
-0.06716284900903702,
-0.02079634927213192,
0.002722938545048237,
0.011950409039855003,
0.019557489082217216,
0.0985821858048439,
0.031205695122480392,
-0.06096049025654793,
0.02934998832643032,
-0.01633812114596367,
-0.09854648262262344,
-0.06520919501781464,
-0.002539200009778142,
0.01878954842686653,
0.005370151251554489,
0.04298195242881775,
0.006488301791250706,
-0.015882866457104683,
0.06597878783941269,
-0.03140559419989586,
0.06193863973021507,
0.008903121575713158,
0.0013554595643654466,
-0.008643865585327148,
0.06729704141616821,
-0.01912790536880493,
0.002018025843426585,
-0.01629842445254326,
0.09154386818408966,
-0.07199577987194061,
0.008666525594890118,
-0.00011255998106207699,
-0.04404383525252342,
-0.03777037933468819,
-0.117915578186512,
-0.0009336447110399604,
0.011301870457828045,
-0.022641286253929138,
-0.020096786320209503,
-0.02421095222234726,
-0.013987048529088497,
0.055564213544130325,
-0.05313443765044212,
-0.03019130975008011,
0.06183304637670517,
-0.09820973128080368,
0.010221040807664394,
0.08022717386484146,
-0.1566786915063858,
0.12939120829105377,
-0.05246887356042862,
0.0578475184738636,
0.06436774879693985,
0.0036884427536278963,
-0.022465232759714127,
0.06260273605585098,
0.03314974159002304,
-0.017514610663056374,
-0.002387314336374402,
0.03535677492618561,
-0.08993953466415405,
-0.05882767587900162,
-0.059430766850709915,
-5.1076543883255e-8,
-0.007643748540431261,
0.0015869669150561094,
-0.052898574620485306,
0.0431441068649292,
0.01653241366147995,
-0.01479401346296072,
-0.005487972870469093,
-0.024946589022874832,
0.09515288472175598,
-0.019867466762661934,
-0.024031182751059532,
0.03780798614025116,
0.09679218381643295,
0.018513822928071022,
0.05028335377573967,
0.0020282648038119078,
-0.021367697045207024,
-0.05705790966749191,
-0.06635521352291107,
-0.03734050691127777,
-0.044852618128061295,
-0.0005757568869739771,
-0.05719006434082985,
-0.028687763959169388,
-0.02134517952799797,
-0.06489312648773193,
0.034241314977407455,
0.042410653084516525,
0.027649879455566406,
-0.07341563701629639,
-0.09764822572469711,
-0.0073537989519536495,
0.005610694643110037,
0.05491356551647186,
0.027888773009181023,
-0.005339131690561771,
-0.030816948041319847,
0.025675537064671516,
0.014664558693766594,
0.06383486837148666,
-0.0269941333681345,
-0.05363401025533676,
-0.019894063472747803,
0.0076529053039848804,
0.01627993956208229,
0.006266675423830748,
0.04376963898539543,
0.12535551190376282,
0.03342033922672272,
0.024145741015672684,
0.025179866701364517,
-0.033049263060092926,
-0.06314142048358917,
0.03252983093261719,
0.05381627008318901,
-0.051024287939071655,
-0.00041298329597339034,
-0.057405102998018265,
0.022211501374840736,
0.03079410269856453,
0.012163996696472168,
0.024177661165595055,
0.03650323301553726,
-0.009134089574217796
] | 0.152217
|
in the file specified by the [`--localstorage-file`][] CLI flag. The maximum amount of data that can be stored is 10 MB. Any modification of this data outside of the Web Storage API is not supported. `localStorage` data is not stored per user or per request when used in the context of a server, it is shared across all users and requests. ## Class: `MessageChannel` The `MessageChannel` class. See [`MessageChannel`][] for more details. ## Class: `MessageEvent` A browser-compatible implementation of {MessageEvent}. ## Class: `MessagePort` The `MessagePort` class. See [`MessagePort`][] for more details. ## `module` This variable may appear to be global but is not. See [`module`][]. ## Class: `Navigator` > Stability: 1.1 - Active development. Disable this API with the > [`--no-experimental-global-navigator`][] CLI flag. A partial implementation of the [Navigator API][]. ## `navigator` > Stability: 1.1 - Active development. Disable this API with the > [`--no-experimental-global-navigator`][] CLI flag. A partial implementation of [`window.navigator`][]. ### `navigator.hardwareConcurrency` \* Type: {number} The `navigator.hardwareConcurrency` read-only property returns the number of logical processors available to the current Node.js instance. ```js console.log(`This process is running on ${navigator.hardwareConcurrency} logical processors`); ``` ### `navigator.language` \* Type: {string} The `navigator.language` read-only property returns a string representing the preferred language of the Node.js instance. The language will be determined by the ICU library used by Node.js at runtime based on the default language of the operating system. The value is representing the language version as defined in [RFC 5646][]. The fallback value on builds without ICU is `'en-US'`. ```js console.log(`The preferred language of the Node.js instance has the tag '${navigator.language}'`); ``` ### `navigator.languages` \* Type: {Array} The `navigator.languages` read-only property returns an array of strings representing the preferred languages of the Node.js instance. By default `navigator.languages` contains only the value of `navigator.language`, which will be determined by the ICU library used by Node.js at runtime based on the default language of the operating system. The fallback value on builds without ICU is `['en-US']`. ```js console.log(`The preferred languages are '${navigator.languages}'`); ``` ### `navigator.platform` \* Type: {string} The `navigator.platform` read-only property returns a string identifying the platform on which the Node.js instance is running. ```js console.log(`This process is running on ${navigator.platform}`); ``` ### `navigator.userAgent` \* Type: {string} The `navigator.userAgent` read-only property returns user agent consisting of the runtime name and major version number. ```js console.log(`The user-agent is ${navigator.userAgent}`); // Prints "Node.js/21" ``` ### `navigator.locks` > Stability: 1 - Experimental The `navigator.locks` read-only property returns a [`LockManager`][] instance that can be used to coordinate access to resources that may be shared across multiple threads within the same process. This global implementation matches the semantics of the [browser `LockManager`][] API. ```mjs // Request an exclusive lock await navigator.locks.request('my\_resource', async (lock) => { // The lock has been acquired. console.log(`Lock acquired: ${lock.name}`); // Lock is automatically released when the function returns }); // Request a shared lock await navigator.locks.request('shared\_resource', { mode: 'shared' }, async (lock) => { // Multiple shared locks can be held simultaneously console.log(`Shared lock acquired: ${lock.name}`); }); ``` ```cjs // Request an exclusive lock navigator.locks.request('my\_resource', async (lock) => { // The lock has been acquired. console.log(`Lock acquired: ${lock.name}`); // Lock is automatically released when the function returns }).then(() => { console.log('Lock released'); }); // Request a shared lock navigator.locks.request('shared\_resource', { mode: 'shared' }, async (lock) => { // Multiple shared locks can be held simultaneously console.log(`Shared lock acquired: ${lock.name}`); }).then(() => { console.log('Shared lock released'); }); ``` See [`worker\_threads.locks`][] for detailed API documentation. ## Class: `PerformanceEntry` The `PerformanceEntry` class. See [`PerformanceEntry`][] for more details. ## Class: `PerformanceMark` The `PerformanceMark` class. See [`PerformanceMark`][] for more details. ## Class: `PerformanceMeasure` The `PerformanceMeasure` class. See [`PerformanceMeasure`][]
|
https://github.com/nodejs/node/blob/main//doc/api/globals.md
|
main
|
nodejs
|
[
0.0498003289103508,
0.007685437332838774,
-0.02152046374976635,
0.03718004375696182,
0.045843455940485,
-0.0915481448173523,
0.024768905714154243,
0.026127487421035767,
0.028972534462809563,
0.009497773833572865,
0.07483487576246262,
0.04442399740219116,
-0.010874269530177116,
0.03376522287726402,
-0.03288993611931801,
0.04745674133300781,
0.025434792041778564,
-0.0734848603606224,
-0.04232792556285858,
0.0445491224527359,
0.029267411679029465,
0.0157160684466362,
0.03245136886835098,
0.044584982097148895,
0.003837862052023411,
0.02584918774664402,
-0.06351789832115173,
-0.021230727434158325,
0.031912967562675476,
-0.008434886112809181,
0.0017361774807795882,
0.016601694747805595,
-0.023760808631777763,
-0.006049415562301874,
0.014522310346364975,
0.056489747017621994,
-0.04149311035871506,
-0.07200296968221664,
-0.03285667672753334,
0.011031105183064938,
0.03815413638949394,
0.08250742405653,
-0.07498057186603546,
-0.02916327305138111,
-0.04103512689471245,
-0.07358866930007935,
-0.04078470170497894,
-0.024869434535503387,
-0.06459395587444305,
0.04611587896943092,
-0.028320129960775375,
0.02161662094295025,
-0.043537795543670654,
0.020932624116539955,
0.031376201659440994,
-0.04761404171586037,
-0.07334251701831818,
0.0722140297293663,
0.019348707050085068,
0.07383116334676743,
0.019666826352477074,
0.0004787168581970036,
0.07542706280946732,
-0.06947066634893417,
-0.021718861535191536,
0.009629410691559315,
0.00032785991788841784,
-0.027833331376314163,
0.026649517938494682,
-0.040533944964408875,
-0.07634496688842773,
0.08369924873113632,
-0.029935717582702637,
0.027629628777503967,
-0.000057280660257674754,
-0.08820277452468872,
0.0012552767293527722,
0.05548321455717087,
-0.05601676180958748,
-0.04776646941900253,
0.001228541717864573,
-0.09284088015556335,
0.053010664880275726,
-0.028793510049581528,
0.025981362909078598,
-0.00711896363645792,
-0.03713220730423927,
0.0038004445377737284,
0.014802344143390656,
-0.05264965817332268,
-0.03504006937146187,
-0.002137700794264674,
-0.023113416507840157,
0.08060967922210693,
-0.04506141319870949,
0.009677797555923462,
-0.0982925072312355,
0.03631442040205002,
-0.014786060899496078,
0.016806265339255333,
0.020249608904123306,
0.034990355372428894,
0.07940036058425903,
0.07429296523332596,
-0.0010469629196450114,
-0.10052262246608734,
0.05381930246949196,
0.048056043684482574,
-0.02402815781533718,
0.022056100890040398,
-0.024083709344267845,
0.06200714409351349,
-0.028843846172094345,
0.049052104353904724,
0.004039463587105274,
0.023712119087576866,
-0.0381339006125927,
0.03882879018783569,
0.06660732626914978,
0.08806360512971878,
0.09871644526720047,
-0.06067075580358505,
-0.05751930922269821,
-0.04671216011047363,
0.06147521734237671,
0.02111145108938217,
0.11086086928844452,
2.7729599495210825e-33,
0.03397080674767494,
-0.04002414643764496,
-0.05256247892975807,
0.11075802892446518,
0.040261160582304,
-0.028358908370137215,
0.05648062378168106,
0.006397522985935211,
-0.061254989355802536,
-0.1105080246925354,
0.020152343437075615,
0.06637449562549591,
-0.027753829956054688,
0.025502564385533333,
0.08022560179233551,
0.02600429207086563,
-0.02786886692047119,
-0.01104279700666666,
0.11922328174114227,
-0.043827906250953674,
0.011895406059920788,
-0.008902577683329582,
0.007318050134927034,
-0.014499496668577194,
0.06876746565103531,
0.04359468072652817,
0.04671378806233406,
0.015298745594918728,
-0.017757780849933624,
-0.012037500739097595,
0.031221138313412666,
-0.01243793684989214,
0.019409814849495888,
0.055058736354112625,
0.0719149261713028,
0.01645118184387684,
-0.020121034234762192,
-0.0069198100827634335,
-0.10276582837104797,
0.013504661619663239,
0.03547504544258118,
-0.024560915306210518,
-0.07101242244243622,
-0.020037246868014336,
-0.13460001349449158,
-0.09070061892271042,
-0.06682845205068588,
-0.014453320764005184,
0.02600237727165222,
-0.011530398391187191,
-0.09902940690517426,
0.020528826862573624,
-0.03661424666643143,
-0.013388833962380886,
0.03660908341407776,
-0.03192044049501419,
-0.002541883150115609,
-0.01844758540391922,
-0.037936512380838394,
-0.07737469673156738,
0.006432988215237856,
-0.03194421902298927,
0.078658327460289,
-0.0013339302968233824,
0.04045754298567772,
0.010683278553187847,
0.004092939663678408,
-0.008290228433907032,
0.017962034791707993,
-0.10359379649162292,
-0.03294781967997551,
-0.0010971322190016508,
0.09212625026702881,
0.05432582646608353,
-0.05207148566842079,
-0.07710641622543335,
-0.023265065625309944,
0.034676697105169296,
-0.02359594777226448,
0.00017027057765517384,
0.05678492784500122,
-0.13444948196411133,
-0.01793784089386463,
0.07235705852508545,
0.04839550331234932,
-0.03714921325445175,
0.01088292058557272,
0.0272636990994215,
-0.004229236394166946,
0.08383653312921524,
-0.037913788110017776,
0.029370900243520737,
0.04210200533270836,
-0.056005433201789856,
-0.09965980052947998,
-3.434236500628068e-33,
-0.022680647671222687,
-0.06196488440036774,
-0.0767395868897438,
0.028599437326192856,
-0.07300577312707901,
0.026358168572187424,
0.03769668564200401,
0.08947578072547913,
-0.04475310072302818,
-0.04210027679800987,
-0.06503447890281677,
0.0462789461016655,
0.06695059686899185,
-0.002055983990430832,
-0.08543034642934799,
0.13611145317554474,
-0.02911892905831337,
-0.09090875089168549,
0.04682144522666931,
-0.09087077528238297,
-0.03797600418329239,
0.03662102669477463,
0.02972225286066532,
0.09496007859706879,
-0.03471260145306587,
-0.03771089389920235,
0.04676397517323494,
-0.027124697342514992,
-0.04532270133495331,
-0.10311583429574966,
0.017414910718798637,
-0.025606168434023857,
-0.03697671741247177,
-0.05207543820142746,
0.004094993695616722,
-0.07374580204486847,
0.009898915886878967,
0.07191341370344162,
-0.0384204126894474,
0.07732094824314117,
0.05615825951099396,
-0.015275268815457821,
-0.05021610110998154,
-0.07343970239162445,
-0.0028886429499834776,
0.017571793869137764,
0.017160847783088684,
-0.05236843600869179,
-0.04970273748040199,
0.02347523346543312,
0.07086628675460815,
-0.058565087616443634,
0.08357322961091995,
-0.01808270998299122,
-0.006724378559738398,
0.07811129093170166,
0.09248213469982147,
-0.023572949692606926,
0.019436359405517578,
-0.09627117216587067,
0.07902258634567261,
-0.11282918602228165,
-0.08012799918651581,
0.005625956226140261,
-0.03713119775056839,
0.05841294676065445,
-0.032701276242733,
-0.007643822580575943,
0.025251038372516632,
0.005561932921409607,
0.010362566448748112,
-0.06277934461832047,
0.003008205210790038,
0.030471689999103546,
0.02557448297739029,
0.060407210141420364,
0.010219474323093891,
-0.05918605998158455,
0.042255233973264694,
0.014487473294138908,
-0.010133831761777401,
0.07209109514951706,
0.007957080379128456,
-0.05422447994351387,
0.04238060861825943,
-0.0575886070728302,
-0.060851480811834335,
0.0813300684094429,
-0.03878392279148102,
-0.01382160373032093,
-0.017018936574459076,
0.056891899555921555,
-0.051922865211963654,
-0.04815848916769028,
0.013369315303862095,
-4.9385850076077986e-8,
-0.06899799406528473,
-0.022419778630137444,
-0.09953863173723221,
0.027002712711691856,
-0.004348121117800474,
-0.02041052095592022,
0.0933702290058136,
0.07265506684780121,
0.0339173749089241,
0.028652044013142586,
0.057893287390470505,
0.02488880790770054,
-0.02787715010344982,
-0.052469175308942795,
-0.010680530220270157,
0.014896072447299957,
0.02489645965397358,
-0.010028202086687088,
-0.00234801834449172,
-0.06984065473079681,
0.10751184821128845,
0.027390826493501663,
0.03276564180850983,
0.05079087242484093,
0.09441371262073517,
-0.015151089057326317,
0.06746624410152435,
0.10427796840667725,
-0.0676962286233902,
-0.12404165416955948,
-0.04945085570216179,
-0.032613784074783325,
0.04500628635287285,
-0.034689974039793015,
-0.019924603402614594,
0.0381404273211956,
-0.034100715070962906,
-0.030089830979704857,
0.04344289377331734,
0.02820054069161415,
0.07465165853500366,
-0.07710140198469162,
-0.03284997120499611,
-0.022376827895641327,
0.04892263561487198,
0.021053502336144447,
-0.027635982260107994,
0.02341403067111969,
0.03308979421854019,
0.026500945910811424,
0.011965245939791203,
-0.012362875044345856,
0.004727523308247328,
0.09670226275920868,
-0.03515664488077164,
-0.008528676815330982,
0.04067182168364525,
0.011790754273533821,
0.030977170914411545,
-0.03508178889751434,
0.0000716532813385129,
0.12608307600021362,
-0.006155364215373993,
-0.018829358741641045
] | 0.06211
|
held simultaneously console.log(`Shared lock acquired: ${lock.name}`); }).then(() => { console.log('Shared lock released'); }); ``` See [`worker\_threads.locks`][] for detailed API documentation. ## Class: `PerformanceEntry` The `PerformanceEntry` class. See [`PerformanceEntry`][] for more details. ## Class: `PerformanceMark` The `PerformanceMark` class. See [`PerformanceMark`][] for more details. ## Class: `PerformanceMeasure` The `PerformanceMeasure` class. See [`PerformanceMeasure`][] for more details. ## Class: `PerformanceObserver` The `PerformanceObserver` class. See [`PerformanceObserver`][] for more details. ## Class: `PerformanceObserverEntryList` The `PerformanceObserverEntryList` class. See [`PerformanceObserverEntryList`][] for more details. ## Class: `PerformanceResourceTiming` The `PerformanceResourceTiming` class. See [`PerformanceResourceTiming`][] for more details. ## `performance` The [`perf\_hooks.performance`][] object. ## `process` \* Type: {Object} The process object. See the [`process` object][] section. ## `queueMicrotask(callback)` \* `callback` {Function} Function to be queued. The `queueMicrotask()` method queues a microtask to invoke `callback`. If `callback` throws an exception, the [`process` object][] `'uncaughtException'` event will be emitted. The microtask queue is managed by V8 and may be used in a similar manner to the [`process.nextTick()`][] queue, which is managed by Node.js. The `process.nextTick()` queue is always processed before the microtask queue within each turn of the Node.js event loop. ```js // Here, `queueMicrotask()` is used to ensure the 'load' event is always // emitted asynchronously, and therefore consistently. Using // `process.nextTick()` here would result in the 'load' event always emitting // before any other promise jobs. DataHandler.prototype.load = async function load(key) { const hit = this.\_cache.get(key); if (hit !== undefined) { queueMicrotask(() => { this.emit('load', hit); }); return; } const data = await fetchData(key); this.\_cache.set(key, data); this.emit('load', data); }; ``` ## Class: `ReadableByteStreamController` A browser-compatible implementation of [`ReadableByteStreamController`][]. ## Class: `ReadableStream` A browser-compatible implementation of [`ReadableStream`][]. ## Class: `ReadableStreamBYOBReader` A browser-compatible implementation of [`ReadableStreamBYOBReader`][]. ## Class: `ReadableStreamBYOBRequest` A browser-compatible implementation of [`ReadableStreamBYOBRequest`][]. ## Class: `ReadableStreamDefaultController` A browser-compatible implementation of [`ReadableStreamDefaultController`][]. ## Class: `ReadableStreamDefaultReader` A browser-compatible implementation of [`ReadableStreamDefaultReader`][]. ## `require()` This variable may appear to be global but is not. See [`require()`][]. ## Class: `Response` A browser-compatible implementation of {Response}. ## Class: `Request` A browser-compatible implementation of {Request}. ## `sessionStorage` > Stability: 1.2 - Release candidate. Disable this API with [`--no-experimental-webstorage`][]. A browser-compatible implementation of [`sessionStorage`][]. Data is stored in memory, with a storage quota of 10 MB. `sessionStorage` data persists only within the currently running process, and is not shared between workers. ## `setImmediate(callback[, ...args])` [`setImmediate`][] is described in the [timers][] section. ## `setInterval(callback, delay[, ...args])` [`setInterval`][] is described in the [timers][] section. ## `setTimeout(callback, delay[, ...args])` [`setTimeout`][] is described in the [timers][] section. ## Class: `Storage` > Stability: 1.2 - Release candidate. Disable this API with [`--no-experimental-webstorage`][]. A browser-compatible implementation of {Storage}. ## `structuredClone(value[, options])` The WHATWG [`structuredClone`][] method. ## Class: `SubtleCrypto` A browser-compatible implementation of {SubtleCrypto}. This global is available only if the Node.js binary was compiled with including support for the `node:crypto` module. ## Class: `DOMException` The WHATWG {DOMException} class. ## Class: `TextDecoder` The WHATWG `TextDecoder` class. See the [`TextDecoder`][] section. ## Class: `TextDecoderStream` A browser-compatible implementation of [`TextDecoderStream`][]. ## Class: `TextEncoder` The WHATWG `TextEncoder` class. See the [`TextEncoder`][] section. ## Class: `TextEncoderStream` A browser-compatible implementation of [`TextEncoderStream`][]. ## Class: `TransformStream` A browser-compatible implementation of [`TransformStream`][]. ## Class: `TransformStreamDefaultController` A browser-compatible implementation of [`TransformStreamDefaultController`][]. ## Class: `URL` The WHATWG `URL` class. See the [`URL`][] section. ## Class: `URLPattern` > Stability: 1 - Experimental The WHATWG `URLPattern` class. See the [`URLPattern`][] section. ## Class: `URLSearchParams` The WHATWG `URLSearchParams` class. See the [`URLSearchParams`][] section. ## Class: `WebAssembly` \* Type: {Object} The object that acts as the namespace for all W3C [WebAssembly][webassembly-org] related functionality. See the [Mozilla Developer Network][webassembly-mdn] for usage and compatibility. ## Class: `WebSocket` A browser-compatible implementation of {WebSocket}. Disable this API with the [`--no-experimental-websocket`][] CLI flag. ## Class:
|
https://github.com/nodejs/node/blob/main//doc/api/globals.md
|
main
|
nodejs
|
[
-0.023925207555294037,
0.028391653671860695,
-0.09868056327104568,
0.03398551419377327,
0.003775206161662936,
0.006513737142086029,
0.009304935112595558,
-0.07441403716802597,
0.012692873366177082,
0.015073254704475403,
-0.018276603892445564,
0.028728246688842773,
-0.03303077816963196,
-0.06363481283187866,
0.05384892597794533,
-0.008748432621359825,
-0.008470031432807446,
-0.01089635118842125,
-0.05534550920128822,
-0.048896465450525284,
0.07892164587974548,
0.005177643150091171,
-0.02821268141269684,
0.04401030391454697,
-0.03076343424618244,
-0.014606514014303684,
-0.03447709232568741,
0.02342667616903782,
0.004356703255325556,
0.02020035684108734,
-0.06548629701137543,
-0.16531908512115479,
-0.13000144064426422,
0.06744854897260666,
-0.023465264588594437,
0.08155106008052826,
-0.0023129202891141176,
-0.06409036368131638,
0.046565670520067215,
-0.02228301577270031,
0.04246162250638008,
0.06109212338924408,
-0.09457419067621231,
-0.07307806611061096,
-0.047975994646549225,
-0.043236445635557175,
-0.11847617477178574,
-0.008133203722536564,
-0.04996190592646599,
-0.04120897501707077,
-0.03138727322220802,
0.022383110597729683,
0.020590979605913162,
-0.03130384162068367,
0.00481746019795537,
0.06492596119642258,
0.06926974654197693,
0.015864254906773567,
-0.042264245450496674,
0.05712058022618294,
0.014166062697768211,
-0.010467247106134892,
0.0019407758954912424,
0.03558341786265373,
0.04917566105723381,
0.0052185081876814365,
0.024839116260409355,
-0.02201162278652191,
0.0648447796702385,
-0.04764244705438614,
-0.0484326109290123,
-0.0008524438599124551,
0.04479926824569702,
-0.09696392714977264,
-0.007994633167982101,
0.005283256992697716,
-0.062457095831632614,
-0.012962162494659424,
-0.07256855815649033,
-0.0775928869843483,
-0.04528944939374924,
-0.06577356904745102,
-0.016219761222600937,
0.06172289699316025,
0.053233012557029724,
0.10005544126033783,
0.028429223224520683,
0.0056891427375376225,
0.05049590393900871,
-0.0006357046659104526,
-0.0701829344034195,
0.04931602254509926,
-0.022934481501579285,
0.00028136526816524565,
0.05416309833526611,
0.05026417225599289,
-0.024429909884929657,
0.024196788668632507,
-0.09307721257209778,
0.05331235006451607,
0.053170349448919296,
0.01410938985645771,
0.03300880268216133,
0.014498842880129814,
0.056320082396268845,
0.03153584897518158,
0.023886533454060555,
-0.010780260898172855,
-0.06085895374417305,
-0.010658551938831806,
0.03948047012090683,
0.1479046791791916,
-0.03512978181242943,
0.0709281787276268,
-0.007364247925579548,
0.08870290964841843,
-0.04478605464100838,
-0.0031962040811777115,
0.06444499641656876,
0.15250076353549957,
0.11025992035865784,
-0.029164129868149757,
0.0018461222061887383,
-0.06229289993643761,
-0.01658787578344345,
-0.02576369233429432,
0.0003474157419987023,
3.4966214551941455e-33,
0.05161993205547333,
-0.11123162508010864,
-0.04718637093901634,
0.012741531245410442,
0.03491780534386635,
0.08165394514799118,
-0.03618278726935387,
0.019484493881464005,
-0.0753362849354744,
0.021035274490714073,
0.03613348305225372,
-0.009829259477555752,
-0.004978048615157604,
-0.026522550731897354,
-0.014944879338145256,
-0.021803520619869232,
0.07136766612529755,
0.07723159343004227,
0.05065090209245682,
0.07365629076957703,
0.05690087005496025,
0.013529403135180473,
-0.048548806458711624,
0.09808048605918884,
0.005888075567781925,
0.006692536175251007,
-0.012615338899195194,
-0.01787462830543518,
-0.030975330621004105,
0.04645044729113579,
0.01641814410686493,
0.0431901291012764,
-0.04454290121793747,
0.007143137976527214,
-0.049937453120946884,
-0.04166066646575928,
0.009406995959579945,
0.017672160640358925,
-0.015845291316509247,
-0.040895015001297,
0.014069519937038422,
-0.04043741896748543,
-0.05644731968641281,
-0.08228389173746109,
-0.08439739048480988,
-0.0619969367980957,
-0.13304656744003296,
0.011647965759038925,
0.03317880257964134,
-0.05758779123425484,
-0.01160413958132267,
0.04946001246571541,
0.011700717732310295,
-0.027447186410427094,
0.03099897690117359,
-0.04055236279964447,
0.023801369592547417,
0.043244969099760056,
0.04131360352039337,
0.020804554224014282,
-0.01102397684007883,
0.017683865502476692,
-0.03626313433051109,
-0.02881237305700779,
-0.01577620580792427,
-0.0012149495305493474,
-0.02475247159600258,
-0.02482185885310173,
0.016621824353933334,
0.001229992718435824,
-0.08938981592655182,
0.03644478693604469,
0.015728410333395004,
0.019031241536140442,
0.020952312275767326,
0.00041263128514401615,
-0.04800530895590782,
-0.012439234182238579,
-0.0857137069106102,
-0.0005886940634809434,
0.12260603904724121,
0.010243288241326809,
-0.058478668332099915,
-0.0048962123692035675,
-0.06737349182367325,
0.021447349339723587,
-0.05552605167031288,
0.037073228508234024,
-0.023265065625309944,
0.05828303098678589,
-0.02956610731780529,
0.00514246104285121,
0.021992173045873642,
-0.03340545669198036,
-0.0912024974822998,
-6.285393273101726e-33,
0.008165311068296432,
-0.044880617409944534,
-0.014008461497724056,
0.023183057084679604,
0.11859779059886932,
-0.03936494514346123,
-0.07196952402591705,
-0.034940823912620544,
-0.12742885947227478,
-0.017198575660586357,
0.021057255566120148,
0.0015974685084074736,
-0.06686029583215714,
0.10126097500324249,
0.024914920330047607,
0.0704139843583107,
-0.018400343134999275,
0.04105054959654808,
0.047417040914297104,
-0.006603546906262636,
0.014959138818085194,
0.03330674767494202,
0.08051241189241409,
0.04489660635590553,
-0.031506747007369995,
-0.04502573609352112,
-0.03272432088851929,
0.0020393645390868187,
0.008472956717014313,
-0.044007036834955215,
-0.0025649999734014273,
-0.00020164268789812922,
-0.04183577373623848,
0.096804678440094,
0.029347149655222893,
-0.02289278618991375,
-0.0221520084887743,
-0.02413187175989151,
-0.02763865888118744,
0.013785668648779392,
0.11653102189302444,
-0.004103071056306362,
-0.07774984836578369,
-0.022217707708477974,
0.015825163573026657,
-0.004637174308300018,
-0.012145200744271278,
-0.09906789660453796,
-0.027507634833455086,
0.04154525324702263,
0.053632937371730804,
-0.05138003081083298,
0.01688641682267189,
0.0028623526450246572,
0.024906085804104805,
-0.0649523213505745,
0.07776717096567154,
-0.10942048579454422,
-0.052397679537534714,
0.030070997774600983,
0.010352501645684242,
-0.026578759774565697,
-0.03429824858903885,
0.07783634960651398,
0.027723101899027824,
-0.06954250484704971,
-0.04811004921793938,
-0.04864167794585228,
0.013324782252311707,
0.09474139660596848,
0.0465230755507946,
0.06079196184873581,
0.0030946675688028336,
0.06635547429323196,
-0.0010265305172652006,
0.05043015629053116,
-0.047086335718631744,
-0.06771247088909149,
-0.036080364137887955,
0.11886045336723328,
-0.029855141416192055,
-0.019163265824317932,
0.03938879445195198,
-0.011068648658692837,
-0.044505514204502106,
0.05799589678645134,
0.08437570929527283,
0.08164489269256592,
-0.028810275718569756,
-0.07918810099363327,
-0.013951793313026428,
0.025978565216064453,
-0.10223529487848282,
-0.09190860390663147,
0.01987992227077484,
-5.1152941438203925e-8,
0.014856620691716671,
-0.01942022331058979,
-0.003895208239555359,
0.06086595356464386,
-0.019836129620671272,
0.031555213034152985,
0.030279874801635742,
-0.008484763093292713,
-0.025012224912643433,
0.03956243395805359,
-0.015041389502584934,
-0.022222060710191727,
0.07801744341850281,
0.04592449218034744,
-0.0483759343624115,
-0.04461364820599556,
-0.0214939434081316,
0.0531630776822567,
0.004282941110432148,
-0.06947135180234909,
-0.012580827809870243,
-0.004683440085500479,
0.0791551023721695,
-0.016908088698983192,
-0.0479564443230629,
-0.02653426304459572,
0.06807664781808853,
0.02801504172384739,
-0.038730259984731674,
0.05861411616206169,
-0.09576914459466934,
-0.054348524659872055,
0.045050814747810364,
-0.08480200171470642,
0.0013179635861888528,
0.04462673142552376,
-0.07424551248550415,
0.03700891509652138,
0.10571449249982834,
0.05226684361696243,
0.030420372262597084,
0.010039971210062504,
0.004266421776264906,
0.05897165834903717,
0.12089742720127106,
-0.010143546387553215,
-0.05994449183344841,
0.05005649849772453,
-0.025677936151623726,
-0.03931378945708275,
-0.0478021577000618,
-0.0061555602587759495,
-0.03524070233106613,
0.09335338324308395,
-0.06351131200790405,
0.027395864948630333,
0.021657083183526993,
-0.06987764686346054,
0.06413449347019196,
-0.024526577442884445,
0.029838409274816513,
-0.02447117492556572,
-0.06375702470541,
0.007210989482700825
] | 0.057379
|
See the [`URLSearchParams`][] section. ## Class: `WebAssembly` \* Type: {Object} The object that acts as the namespace for all W3C [WebAssembly][webassembly-org] related functionality. See the [Mozilla Developer Network][webassembly-mdn] for usage and compatibility. ## Class: `WebSocket` A browser-compatible implementation of {WebSocket}. Disable this API with the [`--no-experimental-websocket`][] CLI flag. ## Class: `WritableStream` A browser-compatible implementation of [`WritableStream`][]. ## Class: `WritableStreamDefaultController` A browser-compatible implementation of [`WritableStreamDefaultController`][]. ## Class: `WritableStreamDefaultWriter` A browser-compatible implementation of [`WritableStreamDefaultWriter`][]. [CommonJS module]: modules.md [CommonJS modules]: modules.md [ECMAScript module]: esm.md [Navigator API]: https://html.spec.whatwg.org/multipage/system-state.html#the-navigator-object [RFC 5646]: https://www.rfc-editor.org/rfc/rfc5646.txt [Web Crypto API]: webcrypto.md [`--experimental-eventsource`]: cli.md#--experimental-eventsource [`--localstorage-file`]: cli.md#--localstorage-filefile [`--no-experimental-global-navigator`]: cli.md#--no-experimental-global-navigator [`--no-experimental-websocket`]: cli.md#--no-experimental-websocket [`--no-experimental-webstorage`]: cli.md#--no-experimental-webstorage [`ByteLengthQueuingStrategy`]: webstreams.md#class-bytelengthqueuingstrategy [`CompressionStream`]: webstreams.md#class-compressionstream [`CountQueuingStrategy`]: webstreams.md#class-countqueuingstrategy [`DecompressionStream`]: webstreams.md#class-decompressionstream [`EventTarget` and `Event` API]: events.md#eventtarget-and-event-api [`LockManager`]: worker\_threads.md#class-lockmanager [`MessageChannel`]: worker\_threads.md#class-messagechannel [`MessagePort`]: worker\_threads.md#class-messageport [`PerformanceEntry`]: perf\_hooks.md#class-performanceentry [`PerformanceMark`]: perf\_hooks.md#class-performancemark [`PerformanceMeasure`]: perf\_hooks.md#class-performancemeasure [`PerformanceObserverEntryList`]: perf\_hooks.md#class-performanceobserverentrylist [`PerformanceObserver`]: perf\_hooks.md#class-performanceobserver [`PerformanceResourceTiming`]: perf\_hooks.md#class-performanceresourcetiming [`ReadableByteStreamController`]: webstreams.md#class-readablebytestreamcontroller [`ReadableStreamBYOBReader`]: webstreams.md#class-readablestreambyobreader [`ReadableStreamBYOBRequest`]: webstreams.md#class-readablestreambyobrequest [`ReadableStreamDefaultController`]: webstreams.md#class-readablestreamdefaultcontroller [`ReadableStreamDefaultReader`]: webstreams.md#class-readablestreamdefaultreader [`ReadableStream`]: webstreams.md#class-readablestream [`TextDecoderStream`]: webstreams.md#class-textdecoderstream [`TextDecoder`]: util.md#class-utiltextdecoder [`TextEncoderStream`]: webstreams.md#class-textencoderstream [`TextEncoder`]: util.md#class-utiltextencoder [`TransformStreamDefaultController`]: webstreams.md#class-transformstreamdefaultcontroller [`TransformStream`]: webstreams.md#class-transformstream [`URLPattern`]: url.md#class-urlpattern [`URLSearchParams`]: url.md#class-urlsearchparams [`URL`]: url.md#class-url [`WritableStreamDefaultController`]: webstreams.md#class-writablestreamdefaultcontroller [`WritableStreamDefaultWriter`]: webstreams.md#class-writablestreamdefaultwriter [`WritableStream`]: webstreams.md#class-writablestream [`\_\_dirname`]: modules.md#\_\_dirname [`\_\_filename`]: modules.md#\_\_filename [`abortSignal.reason`]: #abortsignalreason [`buffer.atob()`]: buffer.md#bufferatobdata [`buffer.btoa()`]: buffer.md#bufferbtoadata [`clearImmediate`]: timers.md#clearimmediateimmediate [`clearInterval`]: timers.md#clearintervaltimeout [`clearTimeout`]: timers.md#cleartimeouttimeout [`console`]: console.md [`exports`]: modules.md#exports [`fetch()`]: https://developer.mozilla.org/en-US/docs/Web/API/Window/fetch [`globalThis`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/globalThis [`localStorage`]: https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage [`module`]: modules.md#module [`perf\_hooks.performance`]: perf\_hooks.md#perf\_hooksperformance [`process.nextTick()`]: process.md#processnexttickcallback-args [`process` object]: process.md#process [`require()`]: modules.md#requireid [`sessionStorage`]: https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage [`setImmediate`]: timers.md#setimmediatecallback-args [`setInterval`]: timers.md#setintervalcallback-delay-args [`setTimeout`]: timers.md#settimeoutcallback-delay-args [`structuredClone`]: https://developer.mozilla.org/en-US/docs/Web/API/Window/structuredClone [`window.navigator`]: https://developer.mozilla.org/en-US/docs/Web/API/Window/navigator [`worker\_threads.locks`]: worker\_threads.md#worker\_threadslocks [browser `LockManager`]: https://developer.mozilla.org/en-US/docs/Web/API/LockManager [buffer section]: buffer.md [built-in objects]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects [timers]: timers.md [webassembly-mdn]: https://developer.mozilla.org/en-US/docs/WebAssembly [webassembly-org]: https://webassembly.org
|
https://github.com/nodejs/node/blob/main//doc/api/globals.md
|
main
|
nodejs
|
[
-0.0680060088634491,
-0.03468210622668266,
-0.041588734835386276,
-0.007702474482357502,
-0.02718409150838852,
-0.06158037111163139,
-0.0421946756541729,
-0.03619036078453064,
-0.013670788146555424,
-0.09863118827342987,
-0.015092656016349792,
0.019311215728521347,
-0.04137357696890831,
0.05925500765442848,
0.06742856651544571,
-0.00038122126716189086,
0.06730793416500092,
-0.04590824991464615,
0.025864416733384132,
0.033210545778274536,
0.045616865158081055,
-0.02502758614718914,
0.03928917646408081,
-0.029200104996562004,
-0.01696840301156044,
0.0074164546094834805,
-0.029130561277270317,
-0.0017897734651342034,
0.06880578398704529,
0.028902394697070122,
0.09597612917423248,
-0.04771440848708153,
-0.054523859173059464,
-0.022074783220887184,
0.027894113212823868,
0.050114210695028305,
0.0740738958120346,
-0.04926241561770439,
-0.03765862435102463,
0.03675422817468643,
0.12570807337760925,
0.07160195708274841,
-0.02560720406472683,
-0.0040265703573822975,
-0.06327003985643387,
-0.0661369115114212,
-0.07371799647808075,
-0.04143126681447029,
-0.10349877923727036,
0.013438169844448566,
-0.0965922400355339,
-0.02461530640721321,
-0.04912343993782997,
0.06542816013097763,
0.03754008188843727,
-0.061434224247932434,
-0.07618273049592972,
0.09969960898160934,
0.05074338987469673,
0.024722987785935402,
0.025847412645816803,
0.0204556155949831,
0.0820278748869896,
-0.011373523622751236,
-0.008116514421999454,
0.037744246423244476,
0.04504742845892906,
-0.04623812809586525,
0.051360853016376495,
-0.010692676529288292,
-0.061512406915426254,
0.010845399461686611,
-0.0011396287009119987,
0.0054921479895710945,
-0.02402472496032715,
-0.03247690945863724,
0.03273502737283707,
0.024195794016122818,
-0.0984799787402153,
-0.009370694868266582,
-0.053630948066711426,
-0.1192849725484848,
0.02037671022117138,
0.059473004192113876,
0.012083042412996292,
0.05939890071749687,
-0.0664057731628418,
-0.061181437224149704,
0.017082013189792633,
0.0434989333152771,
-0.09830021113157272,
-0.08279765397310257,
-0.039374783635139465,
0.06368449330329895,
0.03390638157725334,
0.026188107207417488,
0.04525456205010414,
0.06653507798910141,
-0.04062240943312645,
0.043862346559762955,
-0.024626553058624268,
0.005587653256952763,
0.03431793302297592,
0.0028379678260535,
0.01251592393964529,
-0.012033645994961262,
0.022360894829034805,
0.12881414592266083,
0.009634212590754032,
-0.028413906693458557,
-0.09705275297164917,
0.034386392682790756,
0.04673754796385765,
-0.04157635197043419,
-0.06380626559257507,
-0.026423322036862373,
-0.009141078218817711,
-0.019777238368988037,
0.06351945549249649,
0.08718179911375046,
0.10528117418289185,
0.001172475516796112,
0.0064200107008218765,
-0.0009951031534001231,
0.07259399443864822,
-0.021143849939107895,
0.03361588716506958,
5.621169169910054e-33,
0.055455610156059265,
-0.02441359870135784,
-0.041289664804935455,
0.06076005473732948,
-0.011991167441010475,
-0.025093846023082733,
0.0914783775806427,
0.01055518165230751,
-0.044620972126722336,
-0.04275694489479065,
0.06828175485134125,
0.0002970764471683651,
-0.002178538590669632,
0.03611786663532257,
0.01336192898452282,
0.0012945530470460653,
-0.061255790293216705,
-0.049434468150138855,
0.11305605620145798,
0.02931405045092106,
0.019971607252955437,
-0.005640153773128986,
-0.017262162640690804,
-0.028279662132263184,
-0.03986933454871178,
0.023134730756282806,
-0.035199377685785294,
0.06268197298049927,
-0.02230008691549301,
0.0388321690261364,
0.08437544107437134,
0.03175431862473488,
-0.057502325624227524,
-0.03053608350455761,
0.05089367553591728,
-0.07344535738229752,
-0.06118520349264145,
0.007767784874886274,
-0.1003573089838028,
-0.02987017296254635,
0.016718203201889992,
-0.08099618554115295,
-0.12090682238340378,
-0.05029117316007614,
-0.003971134778112173,
-0.09723478555679321,
-0.11835625022649765,
-0.014117908664047718,
0.04395262151956558,
-0.04175686091184616,
-0.06512416154146194,
0.00008298714237753302,
0.06596428155899048,
-0.015036734752357006,
0.013625937514007092,
-0.014841926284134388,
0.008265606127679348,
0.01769665814936161,
-0.07090257108211517,
-0.015418634749948978,
-0.029081635177135468,
0.030026352033019066,
-0.006334776058793068,
-0.07994980365037918,
0.0182015523314476,
-0.00618151668459177,
-0.0011749101104214787,
-0.0040871333330869675,
-0.05962976813316345,
-0.01996646635234356,
-0.022537479177117348,
-0.004658008925616741,
-0.022512830793857574,
0.10730534046888351,
-0.009478970430791378,
-0.08459411561489105,
0.008886853232979774,
0.022400958463549614,
0.04700888320803642,
-0.061667077243328094,
0.05778957158327103,
-0.03396081551909447,
0.08757518976926804,
0.008732094429433346,
-0.014215786010026932,
-0.009968582540750504,
-0.02645856887102127,
-0.05830288678407669,
-0.04033675417304039,
0.04468400403857231,
0.05071231350302696,
0.0416816845536232,
0.045502062886953354,
-0.009370853193104267,
-0.08060337603092194,
-7.18221685159442e-33,
0.039676886051893234,
0.003286156803369522,
-0.04311554878950119,
0.05365923419594765,
-0.056372225284576416,
-0.0043690879829227924,
0.021242491900920868,
-0.026609478518366814,
-0.02564581111073494,
0.0026886090636253357,
0.03162245824933052,
0.026910332962870598,
0.03566944971680641,
-0.01774611510336399,
-0.04815992712974548,
0.08977421373128891,
0.00104658177588135,
-0.20984280109405518,
0.012743102386593819,
-0.0678548589348793,
-0.019435018301010132,
0.005370884668081999,
0.03363846242427826,
0.00011139999696752056,
-0.04328584298491478,
0.022132253274321556,
0.03124951757490635,
0.02624192275106907,
-0.029877621680498123,
-0.06645286083221436,
0.031645290553569794,
0.06240438297390938,
-0.04527537524700165,
-0.06287061423063278,
0.025747913867235184,
0.004898708313703537,
-0.02525527961552143,
0.049403298646211624,
0.012937705963850021,
-0.08656660467386246,
0.09031631797552109,
0.012135936878621578,
-0.020992930978536606,
0.025102190673351288,
0.0719616562128067,
0.050023630261421204,
-0.03371456265449524,
-0.019259851425886154,
0.017049886286258698,
0.09007562696933746,
0.02619796060025692,
0.01891390234231949,
0.03637123107910156,
-0.02171383798122406,
0.02079799398779869,
0.06519711762666702,
0.05513802170753479,
-0.06669595837593079,
-0.0009661147487349808,
-0.0003332075721118599,
0.08817897737026215,
-0.07958801835775375,
-0.025168046355247498,
0.07882954180240631,
0.05009588971734047,
-0.013772391714155674,
-0.10680917650461197,
0.06642452627420425,
0.03213650360703468,
0.004334980621933937,
0.004943329840898514,
-0.043282654136419296,
0.014066990464925766,
-0.01633758470416069,
0.05150521546602249,
-0.015655919909477234,
0.04918413236737251,
0.020888499915599823,
0.014270135201513767,
0.03535694256424904,
-0.025266103446483612,
0.11798156052827835,
-0.026943426579236984,
-0.06535946577787399,
0.027363307774066925,
-0.03631725162267685,
-0.03530561923980713,
0.09104280173778534,
-0.08721510320901871,
-0.06912782043218613,
0.020670771598815918,
0.015634380280971527,
-0.05289831757545471,
-0.015582689084112644,
0.09611190110445023,
-5.68692968272444e-8,
-0.07650837302207947,
-0.06963435560464859,
-0.13811014592647552,
0.012995637953281403,
-0.005706673488020897,
0.017365222796797752,
-0.04478027671575546,
-0.049494680017232895,
0.029624711722135544,
0.027544712647795677,
0.020877616479992867,
0.023170283064246178,
0.0004669097834266722,
0.048072971403598785,
0.0030582810286432505,
-0.08671296387910843,
-0.06250248104333878,
-0.008154935203492641,
-0.011686038225889206,
-0.07892996072769165,
0.03673351928591728,
-0.05805569514632225,
0.005518426652997732,
0.09971386194229126,
0.052291933447122574,
-0.01921829953789711,
0.04432776942849159,
0.047207046300172806,
-0.041638173162937164,
0.014741900376975536,
-0.13774606585502625,
0.014853318221867085,
0.006013335660099983,
-0.05916879326105118,
-0.043560996651649475,
0.04805905371904373,
-0.05168827250599861,
-0.022913184016942978,
-0.013044705614447594,
0.029391057789325714,
0.11007127910852432,
0.038916170597076416,
0.0011395817855373025,
0.015332586131989956,
0.057642173022031784,
0.0438087061047554,
-0.013884373940527439,
0.12215178459882736,
0.01289355382323265,
-0.007681502960622311,
0.02370133064687252,
-0.01577516458928585,
0.019141647964715958,
-0.014199207536876202,
-0.044457342475652695,
-0.001129543874412775,
0.027656981721520424,
-0.08698377013206482,
0.0022217181976884604,
-0.005827953573316336,
0.07061558216810226,
-0.03274236619472504,
0.029108967632055283,
0.028961405158042908
] | 0.040527
|
# Usage and example ## Usage `node [options] [V8 options] [script.js | -e "script" | - ] [arguments]` Please see the [Command-line options][] document for more information. ## Example An example of a [web server][] written with Node.js which responds with `'Hello, World!'`: Commands in this document start with `$` or `>` to replicate how they would appear in a user's terminal. Do not include the `$` and `>` characters. They are there to show the start of each command. Lines that don't start with `$` or `>` character show the output of the previous command. First, make sure to have downloaded and installed Node.js. See [Installing Node.js via package manager][] for further install information. Now, create an empty project folder called `projects`, then navigate into it. Linux and Mac: ```bash mkdir ~/projects cd ~/projects ``` Windows CMD: ```powershell mkdir %USERPROFILE%\projects cd %USERPROFILE%\projects ``` Windows PowerShell: ```powershell mkdir $env:USERPROFILE\projects cd $env:USERPROFILE\projects ``` Next, create a new source file in the `projects` folder and call it `hello-world.js`. Open `hello-world.js` in any preferred text editor and paste in the following content: ```js const http = require('node:http'); const hostname = '127.0.0.1'; const port = 3000; const server = http.createServer((req, res) => { res.statusCode = 200; res.setHeader('Content-Type', 'text/plain'); res.end('Hello, World!\n'); }); server.listen(port, hostname, () => { console.log(`Server running at http://${hostname}:${port}/`); }); ``` Save the file. Then, in the terminal window, to run the `hello-world.js` file, enter: ```bash node hello-world.js ``` Output like this should appear in the terminal: ```console Server running at http://127.0.0.1:3000/ ``` Now, open any preferred web browser and visit `http://127.0.0.1:3000`. If the browser displays the string `Hello, World!`, that indicates the server is working. [Command-line options]: cli.md#options [Installing Node.js via package manager]: https://nodejs.org/en/download/package-manager/ [web server]: http.md
|
https://github.com/nodejs/node/blob/main//doc/api/synopsis.md
|
main
|
nodejs
|
[
-0.005618548020720482,
0.0021349056623876095,
0.0062352330423891544,
0.03327685222029686,
0.0665125623345375,
-0.02142336219549179,
-0.026351256296038628,
0.06348077952861786,
0.033613771200180054,
0.05230621248483658,
-0.008121508173644543,
0.003547817934304476,
0.011326294392347336,
-0.036209236830472946,
0.038911476731300354,
0.05078689381480217,
-0.03406418114900589,
0.0072129047475755215,
0.05895347520709038,
-0.09143024682998657,
-0.012874225154519081,
0.013082534074783325,
0.006349590141326189,
-0.04195942357182503,
0.01891547627747059,
0.04820023104548454,
-0.011944320052862167,
0.033012956380844116,
-0.01932825706899166,
0.04396014288067818,
-0.04162254184484482,
-0.019556818529963493,
0.021890727803111076,
-0.012190123088657856,
-0.005127597600221634,
0.17370018362998962,
0.03837455436587334,
-0.05643561854958534,
-0.0960192009806633,
-0.0757199078798294,
0.05952320247888565,
0.05217963457107544,
-0.03158410266041756,
-0.02678830362856388,
-0.022525422275066376,
-0.053792230784893036,
-0.1388407200574875,
-0.05329304561018944,
-0.05591871961951256,
-0.023994429036974907,
-0.03466092795133591,
-0.09465327113866806,
-0.0006055423873476684,
-0.05627467855811119,
-0.013537962920963764,
0.026622498407959938,
-0.07082995772361755,
0.017776018008589745,
0.07413388788700104,
0.03785066679120064,
-0.043031636625528336,
-0.01884472742676735,
0.009714190848171711,
-0.0016676575178280473,
0.05489981919527054,
0.03943552076816559,
-0.042822208255529404,
0.01922636479139328,
-0.0050307465717196465,
0.06915523111820221,
-0.04736731946468353,
-0.01695237308740616,
-0.13148194551467896,
-0.03418511152267456,
-0.10288906842470169,
-0.073558509349823,
0.04045960679650307,
0.06184244528412819,
-0.041889943182468414,
0.016444845125079155,
-0.06539195030927658,
-0.07387033849954605,
-0.01784377731382847,
0.144148051738739,
-0.07903452217578888,
0.12396036833524704,
-0.01598264090716839,
0.014819527044892311,
0.10181893408298492,
0.04392154514789581,
-0.08492376655340195,
-0.12014055252075195,
-0.0014990436611697078,
0.011643954552710056,
-0.03780308738350868,
0.04141116887331009,
0.03290162608027458,
0.03262981399893761,
-0.018070878461003304,
-0.0054072728380560875,
-0.01618889719247818,
-0.04663779214024544,
0.06711360812187195,
-0.06262752413749695,
0.0010338108986616135,
0.02952568605542183,
-0.018605658784508705,
-0.0009960794122889638,
0.11340638250112534,
-0.013541806489229202,
-0.009807760827243328,
0.047937437891960144,
-0.057506538927555084,
-0.02903694473206997,
-0.002075119409710169,
-0.04059137776494026,
0.11708724498748779,
-0.029958955943584442,
0.0357930064201355,
0.1406421959400177,
0.09319235384464264,
0.02519311010837555,
-0.03345887362957001,
0.01780913956463337,
0.03875942528247833,
-0.0632343515753746,
0.046508751809597015,
3.162766733223215e-33,
0.06757792830467224,
-0.06822879612445831,
0.06079716980457306,
0.06277942657470703,
0.10084304958581924,
0.0024843751452863216,
0.06837131083011627,
-0.009042772464454174,
-0.11996830254793167,
0.05178666487336159,
0.022419802844524384,
0.0405501089990139,
0.033240627497434616,
0.07173845916986465,
-0.04296205937862396,
-0.030600108206272125,
0.08341218531131744,
-0.05735771730542183,
0.017019007354974747,
-0.057634882628917694,
-0.024802315980196,
0.02969355136156082,
0.010729723609983921,
0.10626205801963806,
0.01989009603857994,
-0.025773026049137115,
0.045131467282772064,
0.01139324251562357,
0.04149452596902847,
-0.042979538440704346,
0.021278612315654755,
0.010503580793738365,
-0.04830402135848999,
0.019924083724617958,
-0.014565009623765945,
0.02703874185681343,
-0.009275194257497787,
0.022595858201384544,
-0.04672033712267876,
0.033818040043115616,
0.0014508425956591964,
0.010944508947432041,
-0.05252913385629654,
-0.025789659470319748,
0.006876925937831402,
-0.05565609037876129,
-0.040267154574394226,
-0.039418768137693405,
0.07371548563241959,
0.03089374490082264,
-0.08043235540390015,
0.05120937526226044,
0.0656765028834343,
0.014565804973244667,
0.04506436362862587,
0.04133166745305061,
-0.03599873557686806,
-0.045463379472494125,
-0.04724369943141937,
-0.03419746831059456,
0.05265231430530548,
0.013072416186332703,
0.02454059012234211,
0.03140579164028168,
0.002218240639194846,
-0.005709584336727858,
-0.061563778668642044,
-0.013090594671666622,
0.0029558842070400715,
0.10711183398962021,
-0.06390408426523209,
-0.003227407345548272,
0.047152310609817505,
0.0603727363049984,
0.0267323050647974,
0.02474021539092064,
-0.07741866260766983,
-0.040642738342285156,
0.006482300814241171,
0.0483185276389122,
-0.0016846545040607452,
-0.046137068420648575,
-0.043794430792331696,
0.013295010663568974,
0.09564880281686783,
-0.008763191290199757,
-0.02844787947833538,
0.03682607412338257,
0.06467697769403458,
-0.017598530277609825,
0.05875440314412117,
-0.03507136180996895,
-0.02308020368218422,
-0.0315454825758934,
-0.08447449654340744,
-7.497514558527698e-33,
0.012212793342769146,
0.06574306637048721,
-0.07896536588668823,
0.03141091763973236,
-0.10031302273273468,
-0.03395562991499901,
-0.0754605159163475,
-0.04950610548257828,
-0.01912098191678524,
-0.02716604247689247,
-0.05662355199456215,
0.099751777946949,
-0.011767900548875332,
0.00995358731597662,
0.008915622718632221,
0.030687404796481133,
-0.04499225318431854,
-0.025077177211642265,
0.05770754814147949,
-0.06271148473024368,
-0.06143363192677498,
0.007409134414047003,
0.021103130653500557,
0.031201845034956932,
0.007756983395665884,
-0.09322716295719147,
0.05472400784492493,
-0.011924125254154205,
-0.04463738575577736,
-0.05900285020470619,
-0.0414297990500927,
0.0883355662226677,
-0.022491034120321274,
0.06389258056879044,
0.02599469944834709,
-0.02026721090078354,
-0.014982899650931358,
0.04543657228350639,
0.09254290163516998,
0.004831841215491295,
-0.008548268117010593,
-0.07154183834791183,
-0.010124829597771168,
-0.018355481326580048,
-0.011047848500311375,
0.022092826664447784,
-0.03964095562696457,
0.020638814195990562,
-0.046471696346998215,
-0.011186993680894375,
-0.032730624079704285,
-0.0387510284781456,
-0.05160010606050491,
-0.02665109559893608,
-0.03036155179142952,
-0.1227409765124321,
-0.012195980176329613,
0.03239871934056282,
0.059431225061416626,
-0.0009970758110284805,
0.017518874257802963,
-0.10098324716091156,
-0.042126644402742386,
-0.02955380640923977,
-0.12563951313495636,
-0.053754597902297974,
-0.10705980658531189,
0.031285881996154785,
0.028071042150259018,
-0.07810091972351074,
-0.09032382816076279,
0.0024489492643624544,
0.024048080667853355,
0.0038876801263540983,
-0.01549495942890644,
-0.0015678431373089552,
0.05036270618438721,
-0.09325160831212997,
0.011576608754694462,
0.05043641850352287,
0.05870983004570007,
0.12432961165904999,
-0.04656299203634262,
-0.012878861278295517,
-0.05464264005422592,
0.00046746167936362326,
-0.05296643450856209,
0.061211422085762024,
-0.04776352643966675,
0.003937982954084873,
0.01052946038544178,
0.05125517025589943,
-0.03565108776092529,
0.035271961241960526,
-0.07826342433691025,
-5.9039582112063727e-8,
-0.06491956859827042,
-0.03183721750974655,
-0.07456701248884201,
-0.0168132446706295,
0.007132717873901129,
0.03518136218190193,
0.015456832014024258,
0.006223844364285469,
0.02840743213891983,
-0.013452183455228806,
0.019619204103946686,
-0.03424279764294624,
-0.0032972488552331924,
-0.0101852398365736,
-0.039863936603069305,
0.05785087123513222,
0.00804327055811882,
0.08972782641649246,
0.055460210889577866,
0.05779789015650749,
0.010717830620706081,
0.017242848873138428,
-0.0043089017271995544,
0.0589076429605484,
-0.007230052258819342,
0.013548174872994423,
-0.03817206993699074,
0.08173654228448868,
-0.13356181979179382,
-0.004846373572945595,
-0.026704788208007812,
0.03759158402681351,
0.015729526057839394,
-0.030613092705607414,
0.02884763479232788,
0.0013759875437244773,
0.02492370828986168,
-0.027357716113328934,
0.04924514517188072,
-0.02322693169116974,
-0.007978188805282116,
0.041914086788892746,
-0.02491718716919422,
-0.01772145926952362,
-0.09048148989677429,
-0.03544094040989876,
0.06296877562999725,
0.04074103385210037,
-0.022792328149080276,
-0.07465309649705887,
0.05516895651817322,
-0.047618281096220016,
0.01605718955397606,
0.03293703868985176,
0.0024859856348484755,
0.054875101894140244,
0.036242756992578506,
-0.11106012761592865,
-0.022320594638586044,
0.024610955268144608,
-0.01941031590104103,
0.027240954339504242,
-0.008979057893157005,
-0.054474376142024994
] | 0.039367
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.