content
large_stringlengths
3
20.5k
url
large_stringlengths
54
193
branch
large_stringclasses
4 values
source
large_stringclasses
42 values
embeddings
listlengths
384
384
score
float64
-0.21
0.65
should choose \_one\_ of the methods of consuming data and \_should never\_ use multiple methods to consume data from a single stream. Specifically, using a combination of `on('data')`, `on('readable')`, `pipe()`, or async iterators could lead to unintuitive behavior. #### Class: `stream.Readable` ##### Event: `'close'...
https://github.com/nodejs/node/blob/main//doc/api/stream.md
main
nodejs
[ -0.03769557923078537, -0.013761756010353565, -0.008195677772164345, 0.05734400823712349, 0.05653270706534386, -0.08665315061807632, 0.05884624272584915, 0.030087199062108994, 0.05205560848116875, -0.017598900943994522, -0.037031929939985275, 0.0414956733584404, -0.09989459067583084, -0.001...
0.090407
{ console.log(data); } }); ``` If the end of the stream has been reached, calling [`stream.read()`][stream-read] will return `null` and trigger the `'end'` event. This is also true if there never was any data to be read. For instance, in the following example, `foo.txt` is an empty file: ```js const fs = require('node:...
https://github.com/nodejs/node/blob/main//doc/api/stream.md
main
nodejs
[ -0.0017338177422061563, 0.010686350986361504, -0.042204052209854126, 0.06606370210647583, 0.08232027292251587, -0.037253789603710175, -0.00433906726539135, 0.05701236426830292, 0.08096813410520554, 0.024558119475841522, -0.03924769535660744, 0.09519311785697937, -0.05607854947447777, -0.01...
0.075066
data will be automatically managed so that the destination `Writable` stream is not overwhelmed by a faster `Readable` stream. The following example pipes all of the data from the `readable` into a file named `file.txt`: ```js const fs = require('node:fs'); const readable = getReadableStreamSomehow(); const writable = ...
https://github.com/nodejs/node/blob/main//doc/api/stream.md
main
nodejs
[ -0.02536769211292267, -0.021636174991726875, -0.04837340489029884, 0.05023388937115669, 0.006174146663397551, -0.0770842656493187, -0.0322599820792675, 0.06673094630241394, 0.000050538015784695745, -0.006667217239737511, -0.04960312694311142, 0.09203777462244034, -0.0012420850107446313, 0....
0.087336
indicating that it has consumed all buffered content but there may be more data yet to be buffered. In such cases, a new `'readable'` event is emitted once there's more data in the buffer, and the `'end'` event signifies the end of data transmission. Therefore to read a file's whole contents from a `readable`, it is ne...
https://github.com/nodejs/node/blob/main//doc/api/stream.md
main
nodejs
[ 0.012947994284331799, 0.019887864589691162, 0.02151154913008213, 0.020354866981506348, 0.04548272117972374, -0.055184002965688705, 0.04397020861506462, 0.05517124384641647, 0.04664243012666702, -0.023084495216608047, -0.08129949122667313, 0.1216946393251419, -0.1151595339179039, -0.0047138...
0.076951
=> { assert.equal(typeof chunk, 'string'); console.log('Got %d characters of string data:', chunk.length); }); ``` ##### `readable.unpipe([destination])` \* `destination` {stream.Writable} Optional specific stream to unpipe \* Returns: {this} The `readable.unpipe()` method detaches a `Writable` stream previously attach...
https://github.com/nodejs/node/blob/main//doc/api/stream.md
main
nodejs
[ -0.043954867869615555, 0.0373612716794014, 0.031404048204422, 0.03123212605714798, 0.02527575008571148, -0.07821781933307648, 0.001392063102684915, 0.07858947664499283, 0.0002222232724307105, -0.012511848472058773, -0.021335411816835403, 0.07668717950582504, -0.050007082521915436, 0.001762...
0.096339
as it is currently defined. (See [Compatibility][] for more information.) When using an older Node.js library that emits [`'data'`][] events and has a [`stream.pause()`][stream-pause] method that is advisory only, the `readable.wrap()` method can be used to create a [`Readable`][] stream that uses the old stream as its...
https://github.com/nodejs/node/blob/main//doc/api/stream.md
main
nodejs
[ -0.05259402096271515, -0.011336307972669601, -0.026234352961182594, 0.05581866204738617, 0.12090146541595459, 0.01638123393058777, -0.03612704947590828, 0.02805153839290142, -0.0009569434332661331, -0.02168925851583481, -0.03647911548614502, 0.11253045499324799, -0.09883321821689606, -0.00...
0.145314
the stream. \* `data` {any} a chunk of data from the stream. \* `options` {Object} \* `signal` {AbortSignal} aborted if the stream is destroyed allowing to abort the `fn` call early. \* `options` {Object} \* `concurrency` {number} the maximum concurrent invocation of `fn` to call on the stream at once. \*\*Default:\*\*...
https://github.com/nodejs/node/blob/main//doc/api/stream.md
main
nodejs
[ -0.04148627072572708, -0.0035489569418132305, -0.0012315514031797647, 0.011958074755966663, -0.00039526427281089127, -0.08233598619699478, 0.05858059972524643, 0.04963718727231026, 0.004736968316137791, -0.02053568884730339, -0.03376399353146553, 0.020951654762029648, -0.05484090745449066, ...
0.15453
the maximum concurrent invocation of `fn` to call on the stream at once. \*\*Default:\*\* `1`. \* `signal` {AbortSignal} allows destroying the stream if the signal is aborted. \* Returns: {Promise} a promise for when the stream has finished. This method allows iterating a stream. For each chunk in the stream the `fn` f...
https://github.com/nodejs/node/blob/main//doc/api/stream.md
main
nodejs
[ -0.0737854540348053, -0.03808880224823952, -0.08241882175207138, 0.022287551313638687, 0.035123784095048904, -0.06952665746212006, 0.014781235717236996, 0.05821174755692482, 0.08802611380815506, -0.03229993209242821, -0.02476762980222702, 0.08324076980352402, -0.05839076638221741, -0.03126...
0.159944
return value is truthy, the stream is destroyed and the promise is fulfilled with `true`. If none of the `fn` calls on the chunks return a truthy value, the promise is fulfilled with `false`. ```mjs import { Readable } from 'node:stream'; import { stat } from 'node:fs/promises'; // With a synchronous predicate. await R...
https://github.com/nodejs/node/blob/main//doc/api/stream.md
main
nodejs
[ -0.059784986078739166, 0.051076456904411316, -0.008430385030806065, 0.05068034678697586, 0.10572906583547592, -0.034337643533945084, -0.01428557001054287, 0.04087650775909424, 0.04098771885037422, 0.022128859534859657, -0.06044670566916466, 0.06991469115018845, -0.017119962722063065, -0.01...
0.066911
all awaited return values are truthy value for `fn`. Once an `fn` call on a chunk awaited return value is falsy, the stream is destroyed and the promise is fulfilled with `false`. If all of the `fn` calls on the chunks return a truthy value, the promise is fulfilled with `true`. ```mjs import { Readable } from 'node:st...
https://github.com/nodejs/node/blob/main//doc/api/stream.md
main
nodejs
[ -0.07067564874887466, 0.04147141054272652, 0.0029345802031457424, 0.058672644197940826, 0.08565428853034973, -0.023514945060014725, -0.014545734971761703, 0.03410499915480614, 0.04941050335764885, 0.01190864946693182, -0.04725818336009979, 0.05044598504900932, -0.021949954330921173, -0.025...
0.061204
value obtained from the last call to `fn` or the `initial` value if specified or the first chunk of the stream otherwise. \* `data` {any} a chunk of data from the stream. \* `options` {Object} \* `signal` {AbortSignal} aborted if the stream is destroyed allowing to abort the `fn` call early. \* `initial` {any} the init...
https://github.com/nodejs/node/blob/main//doc/api/stream.md
main
nodejs
[ -0.1285158395767212, 0.10297756642103195, 0.05041923746466637, 0.05856718122959137, 0.017731700092554092, -0.05800597369670868, 0.04612858220934868, 0.0820644274353981, 0.034255798906087875, -0.010364759713411331, -0.019798340275883675, 0.06582155078649521, -0.05230066925287247, -0.0000551...
0.1668
stream connected to the other side: ```js const [ sideA, sideB ] = duplexPair(); ``` Whatever is written to one stream is made readable on the other. It provides behavior analogous to a network connection, where the data written by the client becomes readable by the server, and vice-versa. The Duplex streams are symmet...
https://github.com/nodejs/node/blob/main//doc/api/stream.md
main
nodejs
[ -0.07465671747922897, -0.030356161296367645, -0.024412866681814194, 0.022889016196131706, -0.0221610926091671, -0.02634170651435852, -0.051282722502946854, 0.0330209843814373, 0.02148444578051567, -0.049511197954416275, -0.030302131548523903, 0.10790958255529404, -0.06060982123017311, 0.03...
0.083935
`Readable` streams which have emitted `'end'` or `'close'`. \* `Writable` streams which have emitted `'finish'` or `'close'`. `stream.pipeline()` leaves dangling event listeners on the streams after the `callback` has been invoked. In the case of reuse of streams after failure, this can cause event listener leaks and s...
https://github.com/nodejs/node/blob/main//doc/api/stream.md
main
nodejs
[ -0.05825020745396614, 0.0022977322805672884, 0.030664950609207153, 0.027620961889624596, 0.017816990613937378, -0.06778403371572495, -0.024218646809458733, 0.050072528421878815, 0.07099037617444992, 0.007582810241729021, -0.09170488268136978, 0.09841395169496536, -0.0759623572230339, 0.007...
0.051266
### `stream.isWritable(stream)` \* `stream` {Writable|Duplex|WritableStream} \* Returns: {boolean|null} - Only returns `null` if `stream` is not a valid `Writable`, `Duplex` or `WritableStream`. Returns whether the stream is writable. ### `stream.Readable.from(iterable[, options])` \* `iterable` {Iterable} Object imple...
https://github.com/nodejs/node/blob/main//doc/api/stream.md
main
nodejs
[ -0.0497007891535759, 0.01875448040664196, -0.0632627010345459, 0.0483161099255085, 0.03873179852962494, -0.030214596539735794, -0.02040410041809082, 0.025427045300602913, -0.0337507389485836, -0.05924001336097717, -0.04344182088971138, 0.041223976761102676, -0.07361471652984619, 0.07917562...
0.041792
`allowHalfOpen` {boolean} \* `decodeStrings` {boolean} \* `encoding` {string} \* `highWaterMark` {number} \* `objectMode` {boolean} \* `signal` {AbortSignal} \* Returns: {stream.Duplex} ```mjs import { Duplex } from 'node:stream'; import { ReadableStream, WritableStream, } from 'node:stream/web'; const readable = new R...
https://github.com/nodejs/node/blob/main//doc/api/stream.md
main
nodejs
[ -0.021513106301426888, 0.04418512433767319, 0.004005109891295433, 0.007932503707706928, -0.009040925651788712, -0.02240912802517414, 0.003939473535865545, 0.01623464748263359, -0.01685699261724949, -0.006916990969330072, -0.03800290822982788, 0.009440186433494091, -0.01387370191514492, 0.0...
0.040054
JavaScript's prototypal inheritance model. First, a stream developer would declare a new JavaScript class that extends one of the four basic stream classes (`stream.Writable`, `stream.Readable`, `stream.Duplex`, or `stream.Transform`), making sure they call the appropriate parent class constructor: ```js const { Writab...
https://github.com/nodejs/node/blob/main//doc/api/stream.md
main
nodejs
[ -0.09636393189430237, -0.007456588093191385, 0.06552191823720932, -0.01060499344021082, 0.03436831012368202, 0.002353120129555464, -0.035348232835531235, 0.0912311002612114, -0.06783662736415863, -0.02940836176276207, -0.011149433441460133, 0.03116554580628872, -0.09695668518543243, 0.0649...
0.032161
should emit `'close'` after it has been destroyed. \*\*Default:\*\* `true`. \* `write` {Function} Implementation for the [`stream.\_write()`][stream-\_write] method. \* `writev` {Function} Implementation for the [`stream.\_writev()`][stream-\_writev] method. \* `destroy` {Function} Implementation for the [`stream.\_des...
https://github.com/nodejs/node/blob/main//doc/api/stream.md
main
nodejs
[ -0.046082381159067154, 0.0018279553623870015, 0.012669113464653492, -0.025282898917794228, 0.04760943353176117, -0.063873291015625, 0.02374187298119068, 0.0155932093039155, 0.039742279797792435, 0.00797589123249054, -0.010479525662958622, 0.03541738539934158, -0.07603295147418976, 0.013328...
0.145288
methods only. The `callback` function must be called synchronously inside of `writable.\_write()` or asynchronously (i.e. different tick) to signal either that the write completed successfully or failed with an error. The first argument passed to the `callback` must be the `Error` object if the call failed or `null` if...
https://github.com/nodejs/node/blob/main//doc/api/stream.md
main
nodejs
[ -0.06308449804782867, -0.026233449578285217, -0.04563356935977936, 0.07719706743955612, -0.05088530108332634, -0.08525906503200531, -0.03288009762763977, 0.028590327128767967, 0.06385913491249084, 0.0022887494415044785, -0.040547072887420654, 0.11984677612781525, -0.038892004638910294, -0....
0.111577
[`writable.\_write()`][], [`writable.\_writev()`][] and [`writable.\_final()`][] methods must be propagated by invoking the callback and passing the error as the first argument. Throwing an `Error` from within these methods or manually emitting an `'error'` event results in undefined behavior. If a `Readable` stream pi...
https://github.com/nodejs/node/blob/main//doc/api/stream.md
main
nodejs
[ -0.027738049626350403, -0.007483793888241053, 0.011819352395832539, 0.02942449040710926, -0.0049293446354568005, -0.05353508144617081, -0.04260893166065216, 0.05897853150963783, 0.019954156130552292, -0.028908373787999153, -0.06900536268949509, 0.05999020114541054, -0.04602891579270363, 0....
0.092612
// ... }, }); ``` Calling `abort` on the `AbortController` corresponding to the passed `AbortSignal` will behave the same way as calling `.destroy(new AbortError())` on the readable created. ```js const { Readable } = require('node:stream'); const controller = new AbortController(); const read = new Readable({ read(siz...
https://github.com/nodejs/node/blob/main//doc/api/stream.md
main
nodejs
[ -0.08232107013463974, 0.00367768038995564, -0.017048262059688568, 0.04107500612735748, 0.04051641374826431, -0.013387016952037811, -0.01092706061899662, 0.06682867556810379, 0.05850674584507942, -0.0034773540683090687, -0.034238941967487335, 0.10433559864759445, -0.0862729400396347, -0.008...
0.120709
\* `chunk` {Buffer|TypedArray|DataView|string|null|any} Chunk of data to push into the read queue. For streams not operating in object mode, `chunk` must be a {string}, {Buffer}, {TypedArray} or {DataView}. For object mode streams, `chunk` may be any JavaScript value. \* `encoding` {string} Encoding of string chunks. M...
https://github.com/nodejs/node/blob/main//doc/api/stream.md
main
nodejs
[ -0.04893339052796364, -0.028950754553079605, -0.044520918279886246, 0.02634940855205059, -0.08196493238210678, -0.04925859346985817, 0.037900883704423904, -0.023954052478075027, 0.016085635870695114, -0.03913908079266548, -0.03517802059650421, 0.047188181430101395, -0.06568117439746857, 0....
0.103493
JavaScript does not have support for multiple inheritance, the `stream.Duplex` class is extended to implement a [`Duplex`][] stream (as opposed to extending the `stream.Readable` \_and\_ `stream.Writable` classes). The `stream.Duplex` class prototypically inherits from `stream.Readable` and parasitically from `stream.W...
https://github.com/nodejs/node/blob/main//doc/api/stream.md
main
nodejs
[ -0.0476725809276104, -0.0526629313826561, 0.036518488079309464, -0.00036076034302823246, -0.027745002880692482, -0.0014509832253679633, 0.009400399401783943, 0.0101414630189538, -0.05910728499293327, -0.06570761650800705, -0.056461308151483536, 0.07258899509906769, -0.06209651008248329, 0....
0.033573
set exclusively for either the `Readable` or `Writable` side using the `readableObjectMode` and `writableObjectMode` options respectively. In the following example, for instance, a new `Transform` stream (which is a type of [`Duplex`][] stream) is created that has an object mode `Writable` side that accepts JavaScript ...
https://github.com/nodejs/node/blob/main//doc/api/stream.md
main
nodejs
[ -0.0440545454621315, 0.0042700013145804405, -0.0603952519595623, 0.020032158121466637, -0.10746443271636963, 0.033358242362737656, -0.025234278291463852, 0.027898306027054787, -0.0010996157070621848, -0.05750473961234093, -0.08815278112888336, 0.04641178250312805, -0.05845232680439949, 0.0...
0.06429
be implemented by child classes, and called by the internal `Readable` class methods only. In some cases, a transform operation may need to emit an additional bit of data at the end of the stream. For example, a `zlib` compression stream will store an amount of internal state used to optimally compress the output. When...
https://github.com/nodejs/node/blob/main//doc/api/stream.md
main
nodejs
[ -0.13822542130947113, 0.07427546381950378, -0.02742253988981247, 0.03218567371368408, -0.056335385888814926, -0.10595734417438507, -0.042201150208711624, 0.03396352007985115, 0.021868722513318062, -0.02420056238770485, -0.02511165849864483, 0.10345679521560669, -0.011726956814527512, -0.02...
0.148227
for examples and testing, but there are some use cases where `stream.PassThrough` is useful as a building block for novel sorts of streams. ## Additional notes ### Streams compatibility with async generators and async iterators With the support of async generators and iterators in JavaScript, async generators are effec...
https://github.com/nodejs/node/blob/main//doc/api/stream.md
main
nodejs
[ -0.11197518557310104, 0.008929313160479069, -0.04857314005494118, 0.08719390630722046, 0.0547308623790741, -0.02977711707353592, -0.0517137311398983, 0.032658226788043976, 0.01751670613884926, -0.08562050014734268, -0.07313267141580582, 0.059362009167671204, -0.07223998755216599, -0.013833...
0.095874
Prior to Node.js 0.10, the incoming message data would be simply discarded. However, in Node.js 0.10 and beyond, the socket remains paused forever. The workaround in this situation is to call the [`stream.resume()`][stream-resume] method to begin the flow of data: ```js // Workaround. net.createServer((socket) => { soc...
https://github.com/nodejs/node/blob/main//doc/api/stream.md
main
nodejs
[ -0.05690647289156914, -0.024674242362380028, 0.012350312434136868, 0.059882402420043945, 0.03232305124402046, -0.021262699738144875, -0.03557209670543671, -0.045449066907167435, 0.017446473240852356, 0.02295686863362789, -0.04468753561377525, 0.1370241641998291, -0.08500628918409348, -0.00...
0.057785
# Asynchronous context tracking > Stability: 2 - Stable ## Introduction These classes are used to associate state and propagate it throughout callbacks and promise chains. They allow storing data throughout the lifetime of a web request or any other asynchronous duration. It is similar to thread-local storage in other ...
https://github.com/nodejs/node/blob/main//doc/api/async_context.md
main
nodejs
[ -0.12447480112314224, 0.04581790789961815, -0.06367533653974533, 0.11791470646858215, -0.02267284318804741, -0.038013141602277756, 0.03451845422387123, -0.0008479335810989141, 0.019958999007940292, -0.05886002629995346, -0.03258824720978737, 0.024251636117696762, -0.012060933746397495, -0....
0.13704
1 - Experimental Disables the instance of `AsyncLocalStorage`. All subsequent calls to `asyncLocalStorage.getStore()` will return `undefined` until `asyncLocalStorage.run()` or `asyncLocalStorage.enterWith()` is called again. When calling `asyncLocalStorage.disable()`, all current contexts linked to the instance will b...
https://github.com/nodejs/node/blob/main//doc/api/async_context.md
main
nodejs
[ -0.07551515102386475, 0.051314521580934525, -0.0924014151096344, 0.12512344121932983, -0.007937654852867126, -0.06916199624538422, 0.007516087964177132, -0.04407404363155365, 0.005750061944127083, -0.04250003769993782, 0.03715159744024277, 0.0675201267004013, -0.009836630895733833, -0.0447...
0.033362
Returns the same object or value // The error will be caught here } ``` ### Usage with `async/await` If, within an async function, only one `await` call is to run within a context, the following pattern should be used: ```js async function fn() { await asyncLocalStorage.run(new Map(), () => { asyncLocalStorage.getStore...
https://github.com/nodejs/node/blob/main//doc/api/async_context.md
main
nodejs
[ -0.07539411634206772, 0.034932442009449005, -0.07463320344686508, 0.1171450987458229, -0.04737767204642296, -0.014916489832103252, -0.00816156342625618, 0.02986362762749195, 0.06554034352302551, -0.033308159559965134, 0.024681352078914642, -0.0017168994527310133, -0.03382464498281479, -0.0...
0.012718
set to `true`, disables `emitDestroy` when the object is garbage collected. This usually does not need to be set (even if `emitDestroy` is called manually), unless the resource's `asyncId` is retrieved and the sensitive API's `emitDestroy` is called with it. When set to `false`, the `emitDestroy` call on garbage collec...
https://github.com/nodejs/node/blob/main//doc/api/async_context.md
main
nodejs
[ -0.023352326825261116, 0.03111192397773266, -0.07263199239969254, 0.11765429377555847, -0.035308755934238434, -0.04654772952198982, 0.06521569937467575, -0.018015198409557343, 0.09356196224689484, -0.022776130586862564, -0.02040478214621544, 0.017524054273962975, -0.0019405317725613713, -0...
0.063938
const { task, callback } = this.tasks.shift(); this.runTask(task, callback); } }); } addNewWorker() { const worker = new Worker(new URL('task\_processor.js', import.meta.url)); worker.on('message', (result) => { // In case of success: Call the callback that was passed to `runTask`, // remove the `TaskInfo` associated w...
https://github.com/nodejs/node/blob/main//doc/api/async_context.md
main
nodejs
[ -0.08510802686214447, 0.04953237250447273, -0.0009263730607926846, 0.07246863842010498, 0.017817825078964233, -0.03379422426223755, -0.009673028253018856, 0.025421738624572754, 0.07444286346435547, -0.025610079988837242, -0.027460400015115738, -0.008527515456080437, -0.06440545618534088, -...
0.142216
= require('./worker\_pool.js'); const os = require('node:os'); const pool = new WorkerPool(os.availableParallelism()); let finished = 0; for (let i = 0; i < 10; i++) { pool.runTask({ a: 42, b: 100 }, (err, result) => { console.log(i, err, result); if (++finished === 10) pool.close(); }); } ``` ### Integrating `AsyncRes...
https://github.com/nodejs/node/blob/main//doc/api/async_context.md
main
nodejs
[ -0.06569556891918182, 0.04007228463888168, 0.023845965042710304, 0.0863913893699646, 0.03337162360548973, -0.0720013752579689, 0.07043133676052094, -0.000652571558021009, 0.05155015364289284, -0.06495990604162216, -0.09719076007604599, 0.008131048642098904, -0.08104679733514786, 0.03476680...
0.108342
# Test runner > Stability: 2 - Stable The `node:test` module facilitates the creation of JavaScript tests. To access it: ```mjs import test from 'node:test'; ``` ```cjs const test = require('node:test'); ``` This module is only available under the `node:` scheme. Tests created via the `test` module consist of a single ...
https://github.com/nodejs/node/blob/main//doc/api/test.md
main
nodejs
[ -0.11503232270479202, 0.008515949361026287, -0.005958080291748047, 0.11243806034326553, 0.0567578487098217, -0.0558910146355629, -0.045724641531705856, 0.04339301213622093, 0.01071004755795002, -0.03699905425310135, -0.012330036610364914, 0.06870049983263016, 0.018259935081005096, -0.04746...
0.158815
in the following example. ```js // The skip option is used, but no message is provided. test('skip option', { skip: true }, (t) => { // This code is never executed. }); // The skip option is used, and a message is provided. test('skip option with message', { skip: 'this is skipped' }, (t) => { // This code is never exe...
https://github.com/nodejs/node/blob/main//doc/api/test.md
main
nodejs
[ -0.029382510110735893, 0.06625095754861832, 0.05588700249791145, 0.08110252022743225, 0.0710849016904831, -0.05627009645104408, -0.025190452113747597, -0.04076866805553436, 0.07588277012109756, -0.04359716922044754, 0.06815757602453232, 0.03840721771121025, -0.011600030586123466, -0.012733...
0.072823
(t) => { t.todo(); }); test('todo() method with message', (t) => { t.todo('this is a todo test and is not treated as a failure'); throw new Error('this does not fail the test'); }); ``` ## Expecting tests to fail This flips the pass/fail reporting for a specific test or suite: A flagged test/test-case must throw in ord...
https://github.com/nodejs/node/blob/main//doc/api/test.md
main
nodejs
[ -0.06418342143297195, 0.05116208270192146, 0.09452960640192032, 0.010872979648411274, 0.05338168889284134, -0.05465751141309738, -0.018215123564004898, 0.0293843075633049, -0.05320751294493675, 0.008029070682823658, -0.016685601323843002, -0.04672708362340927, 0.029758740216493607, 0.05738...
0.08237
do not run these tests. await t.test('skipped subtest 3', { only: false }); await t.test('skipped subtest 4', { skip: true }); }); // The 'only' option is not set, so this test is skipped. test('this test is not run', () => { // This code is not run. throw new Error('fail'); }); describe('a suite', () => { // The 'only...
https://github.com/nodejs/node/blob/main//doc/api/test.md
main
nodejs
[ -0.03887820616364479, 0.10669399797916412, 0.027822846546769142, 0.06549163907766342, 0.05561712756752968, -0.018582923337817192, -0.028565963730216026, -0.015572436153888702, 0.03255762159824371, -0.035620253533124924, 0.010287933051586151, -0.045389510691165924, -0.013587288558483124, -0...
0.063969
outstanding. The first `setImmediate()` attempts to create a new subtest. Because the parent test has already finished and output its results, the new subtest is immediately marked as failed, and reported later to the {TestsStream}. The second `setImmediate()` creates an `uncaughtException` event. `uncaughtException` a...
https://github.com/nodejs/node/blob/main//doc/api/test.md
main
nodejs
[ -0.023775408044457436, -0.007700735237449408, 0.015744220465421677, 0.11310292780399323, 0.09711746871471405, -0.0024590801913291216, -0.027622241526842117, 0.054148007184267044, 0.01500598806887865, -0.016292918473482132, -0.014869773760437965, 0.010894188657402992, 0.041636738926172256, ...
0.090191
across systems. ```bash node --test "\*\*/\*.test.js" "\*\*/\*.spec.js" ``` Matching files are executed as test files. More information on the test file execution can be found in the [test runner execution model][] section. ### Test runner execution model When process-level test isolation is enabled, each matching test...
https://github.com/nodejs/node/blob/main//doc/api/test.md
main
nodejs
[ -0.03804146870970726, -0.03117540292441845, -0.030411247164011, 0.05900036543607712, 0.09068571031093597, -0.05560947582125664, -0.052245207130908966, 0.0031250184401869774, 0.0422530472278595, 0.019077250733971596, -0.027634086087346077, 0.07279045879840851, -0.02556515485048294, -0.02084...
0.072549
a corresponding 'enable' comment is encountered. console.log('this is never executed'); } /\* node:coverage enable \*/ ``` Coverage can also be disabled for a specified number of lines. After the specified number of lines, coverage will be automatically reenabled. If the number of lines is not explicitly provided, a si...
https://github.com/nodejs/node/blob/main//doc/api/test.md
main
nodejs
[ -0.06097825616598129, 0.0431862510740757, -0.050303202122449875, 0.09497939050197601, 0.07552853971719742, -0.04001680389046669, -0.015523645095527172, 0.0020315737929195166, -0.01997830905020237, 0.03457239642739296, -0.005798755679279566, 0.05208057165145874, 0.01778949424624443, 0.00461...
0.094716
to mock mock.timers.enable({ apis: ['setTimeout'] }); setTimeout(fn, 9999); assert.strictEqual(fn.mock.callCount(), 0); // Advance in time mock.timers.tick(9999); assert.strictEqual(fn.mock.callCount(), 1); // Reset the globally tracked mocks. mock.timers.reset(); // If you call reset mock instance, it will also reset ...
https://github.com/nodejs/node/blob/main//doc/api/test.md
main
nodejs
[ -0.07285000383853912, -0.008423248305916786, -0.01281069777905941, 0.07780620455741882, -0.031122051179409027, -0.009940804913640022, -0.050493836402893066, 0.011410283856093884, 0.06032496690750122, -0.019396154209971428, -0.011835874058306217, 0.0050605302676558495, -0.04125922545790672, ...
0.051596
be a positive integer, or another Date object. ```mjs import assert from 'node:assert'; import { test } from 'node:test'; test('mocks the Date object with initial time', (context) => { // Optionally choose what to mock context.mock.timers.enable({ apis: ['Date'], now: 100 }); assert.strictEqual(Date.now(), 100); // Adv...
https://github.com/nodejs/node/blob/main//doc/api/test.md
main
nodejs
[ -0.05706596374511719, 0.06600672006607056, 0.030470170080661774, 0.0684647262096405, -0.012550922110676765, 0.006039234343916178, -0.05547156184911728, 0.014750714413821697, 0.02710632048547268, 0.02158108353614807, 0.004536681342869997, -0.029047513380646706, 0.0041164616122841835, 0.0431...
0.041047
{ // Optionally choose what to mock context.mock.timers.enable({ apis: ['setTimeout', 'Date'] }); const fn = context.mock.fn(); setTimeout(fn, 1000); setTimeout(fn, 2000); setTimeout(fn, 3000); context.mock.timers.runAll(); // All timers are executed as the time is now reached assert.strictEqual(fn.mock.callCount(), 3)...
https://github.com/nodejs/node/blob/main//doc/api/test.md
main
nodejs
[ -0.07728090137243271, 0.05733015388250351, -0.01832924410700798, 0.04732858017086983, -0.00827572401612997, -0.041092921048402786, -0.06254971772432327, 0.05883076414465904, 0.028721870854496956, -0.012347519397735596, -0.012674668803811073, 0.015208776108920574, 0.006932445336133242, -0.0...
0.059048
a {TestsStream} Example of a custom reporter using {stream.Transform}: ```mjs import { Transform } from 'node:stream'; const customReporter = new Transform({ writableObjectMode: true, transform(event, encoding, callback) { switch (event.type) { case 'test:dequeue': callback(null, `test ${event.data.name} dequeued`); br...
https://github.com/nodejs/node/blob/main//doc/api/test.md
main
nodejs
[ -0.08349958062171936, 0.04468346759676933, -0.01785101182758808, 0.06444721668958664, 0.012929409742355347, -0.017008362337946892, -0.021924087777733803, 0.06688977777957916, 0.07845035940408707, 0.04414989426732063, 0.009286136366426945, 0.036405712366104126, -0.05729874595999718, 0.04165...
0.106964
reporter will output to `file.txt`: ```bash node --test-reporter=spec --test-reporter=dot --test-reporter-destination=stdout --test-reporter-destination=file.txt ``` When a single reporter is specified, the destination will default to `stdout`, unless a destination is explicitly provided. ## `run([options])` \* `option...
https://github.com/nodejs/node/blob/main//doc/api/test.md
main
nodejs
[ -0.008065040223300457, -0.018759461119771004, -0.08838266134262085, 0.11804840713739395, 0.05036161094903946, -0.0613856315612793, -0.025136776268482208, 0.01670515164732933, 0.008239050395786762, 0.054897185415029526, 0.036035288125276566, 0.04768938571214676, 0.023607978597283363, -0.055...
0.111074
`watch` {boolean} Whether to run in watch mode or not. \*\*Default:\*\* `false`. \* `shard` {Object} Running tests in a specific shard. \*\*Default:\*\* `undefined`. \* `index` {number} is a positive integer between 1 and `` that specifies the index of the shard to run. This option is \_required\_. \* `total` {number} ...
https://github.com/nodejs/node/blob/main//doc/api/test.md
main
nodejs
[ 0.036886535584926605, 0.00048618382425047457, -0.03199157118797302, 0.06571712344884872, 0.008486458100378513, 0.007153905928134918, -0.013027548789978027, -0.03176978975534439, 0.018387839198112488, -0.002122277393937111, 0.00033396450453437865, 0.004381047561764717, 0.04510582610964775, ...
0.037113
Shorthand for skipping a suite. This is the same as [`suite([name], { skip: true }[, fn])`][suite options]. ## `suite.todo([name][, options][, fn])` Shorthand for marking a suite as `TODO`. This is the same as [`suite([name], { todo: true }[, fn])`][suite options]. ## `suite.only([name][, options][, fn])` Shorthand for...
https://github.com/nodejs/node/blob/main//doc/api/test.md
main
nodejs
[ -0.03756476193666458, 0.09274027496576309, 0.02618853747844696, 0.10003163665533066, 0.004358631558716297, -0.03866308927536011, 0.10674645751714706, 0.00419874582439661, -0.02711966447532177, -0.06420518457889557, 0.021811719983816147, -0.01622852124273777, 0.012593189254403114, -0.009492...
0.11886
reject) => { setTimeout(resolve, 1000); }); }); }); ``` The `timeout` option can be used to fail the test if it takes longer than `timeout` milliseconds to complete. However, it is not a reliable mechanism for canceling tests because a running test might block the application thread and thus prevent the scheduled cance...
https://github.com/nodejs/node/blob/main//doc/api/test.md
main
nodejs
[ -0.060254327952861786, 0.1303129494190216, 0.014101585373282433, 0.08885445445775986, 0.008522122167050838, -0.08942671120166779, 0.004573339130729437, -0.010747980326414108, 0.03856252133846283, -0.03310265392065048, -0.00956854596734047, 0.02860971726477146, -0.003472131211310625, -0.028...
0.08882
A number of milliseconds the hook will fail after. If unspecified, subtests inherit this value from their parent. \*\*Default:\*\* `Infinity`. This function creates a hook that runs before each test in the current suite. ```js describe('tests', async () => { beforeEach(() => console.log('about to run a test')); it('is ...
https://github.com/nodejs/node/blob/main//doc/api/test.md
main
nodejs
[ -0.06279740482568741, 0.015150933526456356, -0.005164889618754387, 0.11196360737085342, -0.007631583139300346, -0.038695257157087326, -0.07947147637605667, 0.01595422811806202, 0.0429263710975647, -0.07229345291852951, -0.011083160527050495, 0.053394824266433716, -0.07697711139917374, -0.0...
0.056701
property contains the thrown value. \*\*Default:\*\* `undefined`. \* `result` {any} The value returned by the mocked function. \* `stack` {Error} An `Error` object whose stack can be used to determine the callsite of the mocked function invocation. \* `target` {Function|undefined} If the mocked function is a constructo...
https://github.com/nodejs/node/blob/main//doc/api/test.md
main
nodejs
[ -0.11112307012081146, 0.01352023333311081, -0.030385367572307587, 0.050170689821243286, -0.06852998584508896, -0.07524394989013672, 0.08165240287780762, 0.014826332218945026, 0.035042017698287964, -0.03744648024439812, -0.01990392804145813, -0.03444821015000343, 0.0001687326584942639, -0.0...
0.093194
times that the property was accessed (read or written). This function returns the number of times that the property was accessed. This function is more efficient than checking `ctx.accesses.length` because `ctx.accesses` is a getter that creates a copy of the internal access tracking array. ### `ctx.mockImplementation(...
https://github.com/nodejs/node/blob/main//doc/api/test.md
main
nodejs
[ -0.0570237897336483, 0.053333576768636703, -0.030886683613061905, 0.06033530831336975, -0.0634523332118988, -0.07555247098207474, 0.0948454812169075, -0.009935162961483002, -0.0040453714318573475, 0.018357092514634132, -0.031005991622805595, -0.02569286711513996, 0.028265034779906273, -0.0...
0.069943
The `times` option is used to modify the mock behavior such that the first two invocations add two to the counter instead of one. ```js test('mocks a counting function', (t) => { let cnt = 0; function addOne() { cnt++; return cnt; } function addTwo() { cnt += 2; return cnt; } const fn = t.mock.fn(addOne, addTwo, { time...
https://github.com/nodejs/node/blob/main//doc/api/test.md
main
nodejs
[ -0.059458307921886444, -0.054624393582344055, 0.006206830497831106, 0.023087169975042343, -0.08218668401241302, 0.006696495693176985, 0.001957744127139449, 0.0389394536614418, 0.026009758934378624, -0.013004119507968426, 0.012320807203650475, -0.011683209799230099, -0.022493012249469757, -...
0.031733
as a CJS or builtin module. \* Returns: {MockModuleContext} An object that can be used to manipulate the mock. This function is used to mock the exports of ECMAScript modules, CommonJS modules, JSON modules, and Node.js builtin modules. Any references to the original module prior to mocking are not impacted. In order t...
https://github.com/nodejs/node/blob/main//doc/api/test.md
main
nodejs
[ -0.09400658309459686, -0.046512529253959656, -0.02039914019405842, 0.059520281851291656, 0.06522616744041443, -0.039447858929634094, -0.044722266495227814, 0.04303520545363426, -0.005167096387594938, -0.029694223776459694, -0.001110435463488102, -0.0028462905902415514, -0.0011819102801382542...
0.131953
following properties are supported: \* `apis` {Array} An optional array containing the timers to mock. The currently supported timer values are `'setInterval'`, `'setTimeout'`, `'setImmediate'`, and `'Date'`. \*\*Default:\*\* `['setInterval', 'setTimeout', 'setImmediate', 'Date']`. If no array is provided, all time rel...
https://github.com/nodejs/node/blob/main//doc/api/test.md
main
nodejs
[ -0.08684439957141876, 0.03237330541014671, -0.05078573897480965, 0.07466185092926025, -0.08564724028110504, 0.009119195863604546, 0.014511308632791042, 0.010698182508349419, -0.007384235505014658, -0.0023435649927705526, -0.01787901110947132, -0.04969031736254692, -0.011068210005760193, 0....
0.102038
it', (context) => { const fn = context.mock.fn(); context.mock.timers.enable({ apis: ['setTimeout'] }); const nineSecs = 9000; setTimeout(fn, nineSecs); const threeSeconds = 3000; context.mock.timers.tick(threeSeconds); context.mock.timers.tick(threeSeconds); context.mock.timers.tick(threeSeconds); assert.strictEqual(f...
https://github.com/nodejs/node/blob/main//doc/api/test.md
main
nodejs
[ -0.059768155217170715, 0.013888622634112835, -0.03868354484438896, 0.05933408439159393, -0.020035969093441963, -0.005011158064007759, -0.03439585119485855, 0.01984110288321972, 0.06967537850141525, -0.040675319731235504, 0.0033714775927364826, -0.03173523023724556, -0.04903799295425415, -0...
0.090981
Optionally choose what to mock context.mock.timers.enable({ apis: ['setTimeout'] }); setTimeout(globalTimeoutObjectSpy, 9999); nodeTimers.setTimeout(nodeTimerSpy, 9999); const promise = nodeTimersPromises.setTimeout(9999).then(nodeTimerPromiseSpy); // Advance in time context.mock.timers.tick(9999); assert.strictEqual(g...
https://github.com/nodejs/node/blob/main//doc/api/test.md
main
nodejs
[ -0.11651265621185303, 0.010827324353158474, -0.009040886536240578, 0.07084944099187851, -0.01603325828909874, -0.020131006836891174, -0.056083936244249344, 0.0453052744269371, 0.04102743789553642, -0.009567064233124256, -0.014405136927962303, -0.016456924378871918, 0.0012005524476990104, 0...
0.046743
['Date'] }); context.mock.timers.setTime(setTime); // Date.now is now 1000 assert.strictEqual(Date.now(), setTime); }); ``` ```cjs const assert = require('node:assert'); const { test } = require('node:test'); test('setTime replaces current time', (context) => { const now = Date.now(); const setTime = 1000; // Date.now ...
https://github.com/nodejs/node/blob/main//doc/api/test.md
main
nodejs
[ -0.057359009981155396, 0.026835311204195023, 0.023206109181046486, 0.05453750863671303, -0.033335041254758835, -0.0017243438633158803, -0.03955839201807976, 0.023709958419203758, 0.03577575832605362, -0.00008727699605515227, -0.011600956320762634, -0.02111097425222397, -0.020433083176612854,...
0.054572
coverage for all files. \* `totalLineCount` {number} The total number of lines. \* `totalBranchCount` {number} The total number of branches. \* `totalFunctionCount` {number} The total number of functions. \* `coveredLineCount` {number} The number of covered lines. \* `coveredBranchCount` {number} The number of covered ...
https://github.com/nodejs/node/blob/main//doc/api/test.md
main
nodejs
[ -0.030677203088998795, 0.05775359272956848, -0.024587053805589676, 0.06641822308301926, 0.008043418638408184, -0.04445480555295944, 0.003573087975382805, 0.07684658467769623, -0.012258214876055717, 0.05527028441429138, -0.005771303083747625, 0.01977890357375145, 0.01422212179750204, -0.024...
0.048872
messages. \* `'warn'`: Warnings. \* `'error'`: Errors. Emitted when [`context.diagnostic`][] is called. This event is guaranteed to be emitted in the same order as the tests are defined. ### Event: `'test:enqueue'` \* `data` {Object} \* `column` {number|undefined} The column number where the test is defined, or `undefi...
https://github.com/nodejs/node/blob/main//doc/api/test.md
main
nodejs
[ -0.08248637616634369, 0.026248525828123093, -0.08504434674978256, 0.09914422780275345, 0.010144425556063652, -0.07001958787441254, 0.044305283576250076, 0.013958272524178028, 0.05999738350510597, -0.012039465829730034, 0.06686268746852875, 0.006410721689462662, 0.055604904890060425, 0.0398...
0.042484
test was run through the REPL. \* `file` {string|undefined} The path of the test file, `undefined` if test was run through the REPL. \* `line` {number|undefined} The line number where the test is defined, or `undefined` if the test was run through the REPL. \* `nesting` {number} The nesting level of the test. \* `count...
https://github.com/nodejs/node/blob/main//doc/api/test.md
main
nodejs
[ -0.1052926629781723, -0.0010310375364497304, -0.04595039784908295, 0.0991373360157013, 0.01875009760260582, -0.06511451303958893, -0.05355197191238403, 0.005600443575531244, 0.08026625216007233, 0.011084911413490772, 0.054289188235998154, 0.048109736293554306, 0.005362389143556356, 0.01618...
0.033399
mode. ### Event: `'test:watch:restarted'` Emitted when one or more tests are restarted due to a file change in watch mode. ## Class: `TestContext` An instance of `TestContext` is passed to each test function in order to interact with the test runner. However, the `TestContext` constructor is not exposed as part of the ...
https://github.com/nodejs/node/blob/main//doc/api/test.md
main
nodejs
[ -0.07534071803092957, 0.01327434927225113, -0.07527373731136322, 0.1138768121600151, 0.052163321524858475, 0.004088700748980045, 0.016155516728758812, -0.004182382952421904, 0.020077012479305267, -0.02833801880478859, -0.012545935809612274, 0.029128916561603546, -0.055825501680374146, 0.01...
0.13026
test('test', (t) => { t.plan(1); t.assert.strictEqual(true, true); }); ``` #### `context.assert.fileSnapshot(value, path[, options])` \* `value` {any} A value to serialize to a string. If Node.js was started with the [`--test-update-snapshots`][] flag, the serialized value is written to `path`. Otherwise, the serialize...
https://github.com/nodejs/node/blob/main//doc/api/test.md
main
nodejs
[ -0.041860535740852356, 0.09952278435230255, 0.002145243575796485, 0.049105461686849594, 0.022581465542316437, -0.05557827651500702, -0.07135125249624252, 0.028783446177840233, 0.0045160348527133465, 0.011201758868992329, -0.009243401698768139, 0.0705583244562149, 0.0028641419485211372, -0....
0.051786
been attempted. ### `context.plan(count[,options])` \* `count` {number} The number of assertions and subtests that are expected to run. \* `options` {Object} Additional options for the plan. \* `wait` {boolean|number} The wait time for the plan: \* If `true`, the plan waits indefinitely for all assertions and subtests ...
https://github.com/nodejs/node/blob/main//doc/api/test.md
main
nodejs
[ -0.09980763494968414, 0.04267478361725807, -0.019440600648522377, 0.09315406531095505, 0.02925410307943821, -0.04413576051592827, -0.0029819367919117212, -0.009703397750854492, 0.011663359589874744, -0.008418676443397999, -0.013484184630215168, -0.052439212799072266, 0.022683946415781975, ...
0.142567
terminate execution of the test function. This function does not return a value. ```js test('top level test', (t) => { // Make sure to return here as well if the test contains additional logic. t.skip('this is skipped'); }); ``` ### `context.todo([message])` \* `message` {string} Optional `TODO` message. This function ...
https://github.com/nodejs/node/blob/main//doc/api/test.md
main
nodejs
[ -0.038221873342990875, 0.07987402379512787, 0.06238091364502907, 0.06401970982551575, 0.08461810648441315, -0.0881313681602478, 0.03215930983424187, 0.018342100083827972, 0.010138417594134808, -0.019374456256628036, 0.013013003394007683, -0.006595151498913765, -0.04113755375146866, 0.02689...
0.120759
of `condition` before trying again. \*\*Default:\*\* `50`. \* `timeout` {number} The poll timeout in milliseconds. If `condition` has not succeeded by the time this elapses, an error occurs. \*\*Default:\*\* `1000`. \* Returns: {Promise} Fulfilled with the value returned by `condition`. This method polls a `condition` ...
https://github.com/nodejs/node/blob/main//doc/api/test.md
main
nodejs
[ -0.09500541538000107, 0.08250033855438232, -0.024200057610869408, 0.05949122831225395, 0.007436799351125956, -0.0035586347803473473, -0.03999942168593407, 0.016901172697544098, -0.006983743514865637, -0.01885446347296238, 0.02478518895804882, -0.047021880745887756, 0.06284774839878082, -0....
0.049637
# Child process > Stability: 2 - Stable The `node:child\_process` module provides the ability to spawn subprocesses in a manner that is similar, but not identical, to popen(3). This capability is primarily provided by the [`child\_process.spawn()`][] function: ```cjs const { spawn } = require('node:child\_process'); co...
https://github.com/nodejs/node/blob/main//doc/api/child_process.md
main
nodejs
[ -0.10885142534971237, -0.047891765832901, -0.04423139616847038, 0.018473103642463684, 0.06500328332185745, -0.05254676192998886, -0.044210035353899, 0.08340714871883392, 0.061456214636564255, -0.04272766038775444, -0.05346538871526718, 0.03093680925667286, -0.009281718172132969, -0.0304051...
0.032761
These objects implement the Node.js [`EventEmitter`][] API, allowing the parent process to register listener functions that are called when certain events occur during the life cycle of the child process. The [`child\_process.exec()`][] and [`child\_process.execFile()`][] methods additionally allow for an optional `cal...
https://github.com/nodejs/node/blob/main//doc/api/child_process.md
main
nodejs
[ -0.07132501900196075, -0.004339041654020548, -0.028309158980846405, 0.047791384160518646, 0.04911917820572853, -0.03805434703826904, 0.021844638511538506, 0.08380314707756042, 0.07599259912967682, 0.06270099431276321, -0.01885751262307167, 0.04246768355369568, -0.08302692323923111, 0.01471...
0.147752
exec('echo "The \\$HOME variable is $HOME"'); // The $HOME variable is escaped in the first instance, but not in the second. ``` ```mjs import { exec } from 'node:child\_process'; exec('"/path/to/test file/test.sh" arg1 arg2'); // Double quotes are used so that the space in the path is not interpreted as // a delimiter...
https://github.com/nodejs/node/blob/main//doc/api/child_process.md
main
nodejs
[ -0.005698320455849171, 0.0210221316665411, 0.012757227756083012, 0.05840738117694855, 0.05073479935526848, -0.0372324213385582, 0.04717092961072922, 0.052755728363990784, 0.013439704664051533, 0.03610176593065262, 0.024833012372255325, -0.023102600127458572, 0.004653739742934704, -0.017721...
0.04815
import { exec } from 'node:child\_process'; const controller = new AbortController(); const { signal } = controller; const child = exec('grep ssh', { signal }, (error) => { console.error(error); // an AbortError }); controller.abort(); ``` ### `child\_process.execFile(file[, args][, options][, callback])` \* `file` {st...
https://github.com/nodejs/node/blob/main//doc/api/child_process.md
main
nodejs
[ -0.020719140768051147, 0.0169678945094347, -0.0869608223438263, -0.004289610777050257, 0.044901493936777115, -0.022113995626568794, 0.014308069832623005, 0.10280443727970123, 0.019913606345653534, 0.06808526813983917, 0.009422478266060352, -0.0012915042461827397, -0.06925182789564133, 0.00...
0.078502
from 'node:util'; import child\_process from 'node:child\_process'; const execFile = promisify(child\_process.execFile); async function getVersion() { const { stdout } = await execFile('node', ['--version']); console.log(stdout); } getVersion(); ``` \*\*If the `shell` option is enabled, do not pass unsanitized user inp...
https://github.com/nodejs/node/blob/main//doc/api/child_process.md
main
nodejs
[ 0.014906764961779118, 0.025654831901192665, -0.06803432106971741, 0.045266106724739075, 0.066661536693573, -0.031989604234695435, -0.03136610612273216, 0.10003844648599625, -0.011044728569686413, 0.03323088586330414, -0.0011709860991686583, -0.01978326216340065, -0.09289873391389847, -0.02...
0.091084
large number of child Node.js processes is not recommended. By default, `child\_process.fork()` will spawn new Node.js instances using the [`process.execPath`][] of the parent process. The `execPath` property in the `options` object allows for an alternative execution path to be used. Node.js processes launched with a ...
https://github.com/nodejs/node/blob/main//doc/api/child_process.md
main
nodejs
[ -0.06309713423252106, -0.06803356856107712, -0.011996285058557987, -0.025982361286878586, 0.0668126717209816, -0.11892955750226974, -0.03377866372466087, 0.11934884637594223, 0.04434608668088913, 0.08225999772548676, -0.021778149530291557, 0.04786982759833336, -0.05288064479827881, -0.0131...
0.053699
be killed by timeout or abort signal. \*\*Default:\*\* `'SIGTERM'`. \* Returns: {ChildProcess} The `child\_process.spawn()` method spawns a new process using the given `command`, with command-line arguments in `args`. If omitted, `args` defaults to an empty array. \*\*If the `shell` option is enabled, do not pass unsan...
https://github.com/nodejs/node/blob/main//doc/api/child_process.md
main
nodejs
[ -0.07200358808040619, 0.0007246799068525434, -0.035428404808044434, 0.04918592423200607, 0.03468116372823715, -0.046479105949401855, 0.018539775162935257, 0.1072264015674591, 0.025003407150506973, 0.03274178504943848, 0.0031247891020029783, -0.0039026166778057814, -0.055617328733205795, 0....
0.184604
corresponding `AbortController` is similar to calling `.kill()` on the child process except the error passed to the callback will be an `AbortError`: ```cjs const { spawn } = require('node:child\_process'); const controller = new AbortController(); const { signal } = controller; const grep = spawn('grep', ['ssh'], { si...
https://github.com/nodejs/node/blob/main//doc/api/child_process.md
main
nodejs
[ -0.07071210443973541, 0.008035063743591309, -0.034025829285383224, -0.015954503789544106, 0.08720366656780243, -0.010756133124232292, 0.04311056062579155, 0.07850637286901474, 0.05801740288734436, 0.04071592912077904, 0.02720377780497074, 0.027144799008965492, -0.026749582961201668, -0.009...
0.109257
equal to `['pipe', 'pipe', 'pipe']`. For convenience, `options.stdio` may be one of the following strings: \* `'pipe'`: equivalent to `['pipe', 'pipe', 'pipe']` (the default) \* `'overlapped'`: equivalent to `['overlapped', 'overlapped', 'overlapped']` \* `'ignore'`: equivalent to `['ignore', 'ignore', 'ignore']` \* `'...
https://github.com/nodejs/node/blob/main//doc/api/child_process.md
main
nodejs
[ 0.009188322350382805, -0.004428916145116091, -0.03668814152479172, -0.03173485025763512, -0.05177420377731323, -0.08916285634040833, 0.043524350970983505, 0.10546760261058807, -0.0406830869615078, -0.025101587176322937, -0.004867259878665209, -0.03648108243942261, -0.007794089615345001, -0...
0.154064
value is interpreted as a file descriptor that is open in the parent process. It is shared with the child process, similar to how {Stream} objects can be shared. Passing sockets is not supported on Windows. 8. `null`, `undefined`: Use default value. For stdio fds 0, 1, and 2 (in other words, stdin, stdout, and stderr) ...
https://github.com/nodejs/node/blob/main//doc/api/child_process.md
main
nodejs
[ -0.06826332956552505, 0.044546306133270264, -0.09666091203689575, 0.018401237204670906, -0.016229040920734406, -0.007105543743818998, 0.018094662576913834, 0.13185925781726837, 0.026681985706090927, -0.01160888746380806, -0.06261669844388962, -0.021503912284970284, -0.07557401806116104, 0....
0.099675
inside of a shell. Uses `'/bin/sh'` on Unix, and `process.env.ComSpec` on Windows. A different shell can be specified as a string. See [Shell requirements][] and [Default Windows shell][]. \*\*Default:\*\* `false` (no shell). \* Returns: {Buffer|string} The stdout from the command. The `child\_process.execFileSync()` m...
https://github.com/nodejs/node/blob/main//doc/api/child_process.md
main
nodejs
[ -0.015947163105010986, 0.011264093220233917, -0.0920022651553154, -0.002206866629421711, 0.05014699697494507, -0.04155345261096954, -0.021703826263546944, 0.08629561960697174, 0.0790090337395668, 0.07518403232097626, -0.03477879986166954, 0.030010441318154335, -0.04638402909040451, -0.0506...
0.130245
terminated and any output is truncated. See caveat at [`maxBuffer` and Unicode][]. \*\*Default:\*\* `1024 \* 1024`. \* `encoding` {string} The encoding used for all stdio inputs and outputs. \*\*Default:\*\* `'buffer'`. \* `windowsHide` {boolean} Hide the subprocess console window that would normally be created on Wind...
https://github.com/nodejs/node/blob/main//doc/api/child_process.md
main
nodejs
[ 0.02819911204278469, 0.003941503819078207, -0.08314937353134155, 0.04320762678980827, -0.004996942821890116, -0.009223202243447304, -0.002621972933411598, 0.10736410319805145, 0.0605800561606884, 0.030859151855111122, -0.03428884595632553, -0.019663915038108826, -0.05084776505827904, -0.03...
0.095505
the child process failed or timed out. The `child\_process.spawnSync()` method is generally identical to [`child\_process.spawn()`][] with the exception that the function will not return until the child process has fully closed. When a timeout has been encountered and `killSignal` is sent, the method won't return until...
https://github.com/nodejs/node/blob/main//doc/api/child_process.md
main
nodejs
[ -0.005721727851778269, 0.020149478688836098, -0.08177157491445541, 0.023855866864323616, 0.032594945281744, -0.05619485676288605, -0.013025294058024883, 0.1283123940229416, 0.004420854151248932, 0.06582282483577728, -0.0007631045882590115, -0.03354866802692413, -0.036780282855033875, -0.02...
0.096
a signal. \* `signal` {string} The signal by which the child process was terminated, or `null` if the child process did not terminated due to a signal. The `'exit'` event is emitted after the child process ends. If the process exited, `code` is the final exit code of the process, otherwise `null`. If the process termin...
https://github.com/nodejs/node/blob/main//doc/api/child_process.md
main
nodejs
[ -0.04245375469326973, -0.016354024410247803, -0.014830515719950199, 0.023933153599500656, 0.05446978285908699, -0.025455068796873093, -0.01842653751373291, 0.036567993462085724, 0.0876661017537117, 0.020301567390561104, -0.028563039377331734, 0.014852691441774368, -0.0819120854139328, -0.0...
0.147201
process of being received. This will most often be triggered immediately after calling `subprocess.disconnect()`. When the child process is a Node.js instance (e.g. spawned using [`child\_process.fork()`][]), the `process.disconnect()` method can be invoked within the child process to close the IPC channel as well. ###...
https://github.com/nodejs/node/blob/main//doc/api/child_process.md
main
nodejs
[ -0.05836378037929535, 0.009313330054283142, -0.03074059821665287, 0.02647906169295311, 0.056454136967659, -0.07877740263938904, 0.03125424310564995, 0.04841955378651619, 0.06855157017707825, 0.02369529940187931, -0.057794053107500076, 0.010647423565387726, -0.08168970793485641, -0.05436934...
0.106203
fails to spawn due to errors, then the value is `undefined` and `error` is emitted. ```cjs const { spawn } = require('node:child\_process'); const grep = spawn('grep', ['ssh']); console.log(`Spawned child pid: ${grep.pid}`); grep.stdin.end(); ``` ```mjs import { spawn } from 'node:child\_process'; const grep = spawn('g...
https://github.com/nodejs/node/blob/main//doc/api/child_process.md
main
nodejs
[ -0.07329542934894562, 0.009685919620096684, 0.017735106870532036, 0.008461441844701767, 0.057315561920404434, -0.02250857464969158, -0.01325959712266922, 0.0736420750617981, 0.06575489044189453, 0.02276630699634552, -0.044021304696798325, -0.04953924939036369, 0.0011377162300050259, 0.0168...
0.019385
and buffered in the socket will not be sent to the child. Sending IPC sockets is not supported on Windows. The optional `callback` is a function that is invoked after the message is sent but before the child process may have received it. The function is called with a single argument: `null` on success, or an [`Error`][...
https://github.com/nodejs/node/blob/main//doc/api/child_process.md
main
nodejs
[ -0.09051986783742905, -0.026725824922323227, -0.047742221504449844, 0.07452726364135742, -0.0046624853275716305, -0.04879441112279892, 0.03711027279496193, 0.06546872854232788, 0.07747314870357513, 0.022472692653536797, -0.0300707146525383, 0.03713439032435417, -0.05423269420862198, -0.013...
0.105712
=> { // If this is special priority... if (socket.remoteAddress === '74.125.127.100') { special.send('socket', socket); return; } // This is normal priority. normal.send('socket', socket); }); server.listen(1337); ``` The `subprocess.js` would receive the socket handle as the second argument passed to the event callbac...
https://github.com/nodejs/node/blob/main//doc/api/child_process.md
main
nodejs
[ -0.08117346465587616, -0.0406598262488842, 0.002594398334622383, -0.010849758051335812, -0.021739939227700233, -0.0896107405424118, 0.0032526846043765545, 0.02587670087814331, 0.09463939815759659, 0.03726759925484657, -0.07651636749505997, 0.08657293021678925, -0.034152429550886154, 0.0591...
0.085026
assert.strictEqual(subprocess.stdio[0], null); assert.strictEqual(subprocess.stdio[0], subprocess.stdin); assert(subprocess.stdout); assert.strictEqual(subprocess.stdio[1], subprocess.stdout); assert.strictEqual(subprocess.stdio[2], null); assert.strictEqual(subprocess.stdio[2], subprocess.stderr); ``` ```mjs import as...
https://github.com/nodejs/node/blob/main//doc/api/child_process.md
main
nodejs
[ -0.055408865213394165, -0.005559995770454407, 0.011890007182955742, 0.005260928999632597, 0.03969041630625725, -0.06260691583156586, -0.07316946983337402, 0.11831897497177124, -0.002115120878443122, 0.015895109623670578, -0.07300646603107452, -0.042460814118385315, 0.023492885753512383, 0....
0.031522
requires opting in by setting the `serialization` option to `'advanced'` when calling [`child\_process.spawn()`][] or [`child\_process.fork()`][]. [Advanced serialization]: #advanced-serialization [Default Windows shell]: #default-windows-shell [HTML structured clone algorithm]: https://developer.mozilla.org/en-US/docs...
https://github.com/nodejs/node/blob/main//doc/api/child_process.md
main
nodejs
[ -0.06884299218654633, -0.0318242609500885, -0.06698018312454224, -0.000625237007625401, -0.03653869777917862, -0.09676342457532883, -0.02157367765903473, 0.015657899901270866, -0.014695299789309502, 0.008708763867616653, -0.002876590471714735, -0.036789100617170334, 0.01643969491124153, 0....
0.056194
# Assert > Stability: 2 - Stable The `node:assert` module provides a set of assertion functions for verifying invariants. ## Strict assertion mode In strict assertion mode, non-strict methods behave like their corresponding strict methods. For example, [`assert.deepEqual()`][] will behave like [`assert.deepStrictEqual(...
https://github.com/nodejs/node/blob/main//doc/api/assert.md
main
nodejs
[ -0.09506801515817642, 0.02533201314508915, 0.041743937879800797, 0.08052825927734375, 0.0504646971821785, -0.0780942365527153, -0.035604264587163925, -0.0030536584090441465, -0.08403772860765457, -0.018523558974266052, -0.017994092777371407, -0.03860095515847206, 0.07284962385892868, 0.024...
0.10672
`'full'`, shows the full diff in assertion errors. Defaults to `'simple'`. Accepted values: `'simple'`, `'full'`. A subclass of {Error} that indicates the failure of an assertion. All instances contain the built-in `Error` properties (`message` and `name`) and: \* `actual` {any} Set to the `actual` argument for methods...
https://github.com/nodejs/node/blob/main//doc/api/assert.md
main
nodejs
[ -0.07443275302648544, 0.0585285909473896, 0.0642521008849144, 0.08324945718050003, 0.05340307578444481, -0.10577473789453506, -0.005588962230831385, 0.03297936171293259, -0.05294225364923477, 0.025576207786798477, 0.008824171498417854, -0.055519673973321915, 0.0810461938381195, 0.008697355...
0.045267
when using destructured methods, avoid destructuring and call methods directly on the instance. ## `assert(value[, message])` \* `value` {any} The input that is checked for being truthy. \* `message` {string|Error|Function} An alias of [`assert.ok()`][]. ## `assert.deepEqual(actual, expected[, message])` \* `actual` {a...
https://github.com/nodejs/node/blob/main//doc/api/assert.md
main
nodejs
[ -0.09238405525684357, -0.0031946683302521706, 0.03625648841261864, 0.018374435603618622, -0.008233464322984219, -0.08129649609327316, -0.0380730964243412, 0.02646295726299286, -0.07257416099309921, -0.044689103960990906, -0.02748512104153633, -0.030127063393592834, 0.050876617431640625, 0....
0.078376
value of the `message` parameter. If the `message` parameter is undefined, a default error message is assigned. If the `message` parameter is an instance of {Error} then it will be thrown instead of the [`AssertionError`][]. ## `assert.deepStrictEqual(actual, expected[, message])` \* `actual` {any} \* `expected` {any} ...
https://github.com/nodejs/node/blob/main//doc/api/assert.md
main
nodejs
[ -0.0802910327911377, 0.018312551081180573, 0.0762878805398941, 0.045835014432668686, -0.006460023112595081, -0.08513257652521133, 0.008560416288673878, 0.040033116936683655, -0.023389484733343124, -0.03875456005334854, -0.043094452470541, -0.06580781191587448, 0.013443365693092346, 0.04854...
0.092701
assert.deepStrictEqual(weakMap1, weakMap1); // OK const weakSet1 = new WeakSet(); const weakSet2 = new WeakSet(); weakSet1.add(obj); weakSet2.add(obj); // Comparing different instances fails, even with same contents assert.deepStrictEqual(weakSet1, weakSet2); // AssertionError: Values have same structure but are not re...
https://github.com/nodejs/node/blob/main//doc/api/assert.md
main
nodejs
[ -0.06996538490056992, -0.02246650867164135, 0.07521893084049225, 0.0011178934946656227, 0.007331791799515486, -0.057659812271595, -0.05199552699923515, 0.0015417553950101137, -0.025746550410985947, -0.10711409896612167, -0.05175625905394554, -0.0851336419582367, 0.033442575484514236, -0.01...
0.020793
OK ``` ```cjs const assert = require('node:assert/strict'); assert.doesNotMatch('I will fail', /fail/); // AssertionError [ERR\_ASSERTION]: The input was expected to not match the ... assert.doesNotMatch(123, /pass/); // AssertionError [ERR\_ASSERTION]: The "string" argument must be of type string. assert.doesNotMatch(...
https://github.com/nodejs/node/blob/main//doc/api/assert.md
main
nodejs
[ -0.09647823125123978, 0.055753473192453384, 0.03020447865128517, 0.0683225616812706, 0.012414385564625263, -0.0173322893679142, 0.032196756452322006, 0.012431410141289234, -0.012635407969355583, -0.08159345388412476, -0.047563280910253525, -0.06049487367272377, 0.024688344448804855, 0.0641...
0.076467
import assert from 'node:assert/strict'; assert.doesNotThrow( () => { throw new TypeError('Wrong value'); }, TypeError, ); ``` ```cjs const assert = require('node:assert/strict'); assert.doesNotThrow( () => { throw new TypeError('Wrong value'); }, TypeError, ); ``` If an [`AssertionError`][] is thrown and a value is pr...
https://github.com/nodejs/node/blob/main//doc/api/assert.md
main
nodejs
[ -0.04211072996258736, 0.08788605779409409, 0.06914689391851425, 0.08005188405513763, 0.029154762625694275, -0.051241591572761536, 0.05311218649148941, -0.010600855574011803, -0.01169106550514698, -0.02651141956448555, 0.024566706269979477, -0.043770451098680496, 0.04570501670241356, 0.0401...
0.08896
assert = require('node:assert/strict'); assert.ifError(null); // OK assert.ifError(0); // AssertionError [ERR\_ASSERTION]: ifError got unwanted exception: 0 assert.ifError('error'); // AssertionError [ERR\_ASSERTION]: ifError got unwanted exception: 'error' assert.ifError(new Error()); // AssertionError [ERR\_ASSERTION...
https://github.com/nodejs/node/blob/main//doc/api/assert.md
main
nodejs
[ -0.07940606772899628, 0.03697412088513374, 0.023070402443408966, 0.038869135081768036, 0.10544309765100479, -0.03642731159925461, 0.030345618724822998, -0.01875314861536026, 0.017996564507484436, -0.04895063489675522, 0.03191134333610535, -0.011295469477772713, 0.019527709111571312, 0.0650...
0.045019
assert.notDeepStrictEqual({ a: 1 }, { a: '1' }); // OK ``` If the values are deeply and strictly equal, an [`AssertionError`][] is thrown with a `message` property set equal to the value of the `message` parameter. If the `message` parameter is undefined, a default error message is assigned. If the `message` parameter ...
https://github.com/nodejs/node/blob/main//doc/api/assert.md
main
nodejs
[ -0.0496126264333725, 0.035262126475572586, 0.041154880076646805, 0.008581873029470444, -0.0029935918282717466, -0.06434448808431625, 0.030247528105974197, 0.00871219951659441, -0.06833214312791824, -0.01622362993657589, 0.009156308136880398, -0.07669191807508469, 0.11238683015108109, 0.053...
0.032963
// assert.ok(false) assert.ok(0); // AssertionError: The expression evaluated to a falsy value: // // assert.ok(0) ``` ```cjs const assert = require('node:assert/strict'); assert.ok(true); // OK assert.ok(1); // OK assert.ok(); // AssertionError: No value argument passed to `assert.ok()` assert.ok(false, 'it\'s false')...
https://github.com/nodejs/node/blob/main//doc/api/assert.md
main
nodejs
[ -0.13548187911510468, 0.06753186881542206, 0.010360630229115486, 0.04759962484240532, 0.04105133190751076, -0.011697775684297085, 0.015803705900907516, 0.02726326324045658, 0.025110462680459023, -0.0045223236083984375, -0.02362004853785038, -0.02454826422035694, -0.03053070418536663, 0.049...
0.035067
`message` {string|Error|Function} Postfix `printf`-like arguments in case it's used as format string. If message is a function, it is called in case of a comparison failure. The function receives the `actual` and `expected` arguments and has to return a string that is going to be used as error message. `printf`-like fo...
https://github.com/nodejs/node/blob/main//doc/api/assert.md
main
nodejs
[ -0.025444133207201958, 0.07459086179733276, 0.04184379801154137, 0.03963146731257439, -0.0029782652854919434, -0.06761663407087326, -0.005199054256081581, 0.030472714453935623, -0.021976977586746216, -0.03709433972835541, -0.015950437635183334, -0.029147416353225708, 0.08388878405094147, 0...
0.091056
= 'bar'; err.info = { nested: true, baz: 'text', }; err.reg = /abc/i; assert.throws( () => { throw err; }, { name: 'TypeError', message: 'Wrong value', info: { nested: true, baz: 'text', }, // Only properties on the validation object will be tested for. // Using nested objects requires all properties to be present. Oth...
https://github.com/nodejs/node/blob/main//doc/api/assert.md
main
nodejs
[ -0.03657836839556694, 0.14123980700969696, 0.0971410796046257, 0.0663779079914093, 0.00997986365109682, -0.03359198570251465, 0.02936812862753868, -0.011327886022627354, 0.015117944218218327, -0.006643474567681551, -0.044131800532341, -0.05896296352148056, 0.02649059146642685, 0.0970693081...
0.000133
``` ```cjs const assert = require('node:assert/strict'); assert.throws( () => { throw new Error('Wrong value'); }, /^Error: Wrong value$/, ); ``` Custom error validation: The function must return `true` to indicate all internal validations passed. It will otherwise fail with an [`AssertionError`][]. ```mjs import asser...
https://github.com/nodejs/node/blob/main//doc/api/assert.md
main
nodejs
[ -0.05191668123006821, 0.0728180930018425, 0.07437644153833389, 0.06111364811658859, 0.04754263907670975, -0.03726969659328461, 0.007631555199623108, 0.04268598556518555, -0.029934274032711983, -0.030910607427358627, -0.003841801080852747, -0.047188833355903625, 0.06519291549921036, 0.01813...
0.044617
(as message) in case the function does not throw: assert.throws(notThrowing, 'Second'); // AssertionError [ERR\_ASSERTION]: Missing expected exception: Second // If it was intended to match for the error message do this instead: // It does not throw because the error messages match. assert.throws(throwingSecond, /Secon...
https://github.com/nodejs/node/blob/main//doc/api/assert.md
main
nodejs
[ -0.0370369553565979, 0.04071494936943054, 0.07270529866218567, 0.05377385765314102, 0.0546984039247036, -0.036919087171554565, 0.006383241154253483, 0.009924749843776226, 0.0018101498717442155, -0.03256935626268387, -0.004143684636801481, -0.059818871319293976, 0.08237678557634354, 0.03376...
0.020969
); // OK assert.partialDeepStrictEqual(123n, 123n); // OK assert.partialDeepStrictEqual( [1, 2, 3, 4, 5, 6, 7, 8, 9], [5, 4, 8], ); // AssertionError assert.partialDeepStrictEqual( { a: 1 }, { a: 1, b: 2 }, ); // AssertionError assert.partialDeepStrictEqual( { a: { b: 2 } }, { a: { b: '2' } }, ); // AssertionError ``` ...
https://github.com/nodejs/node/blob/main//doc/api/assert.md
main
nodejs
[ -0.07054631412029266, 0.09550713747739792, 0.06796392053365707, 0.021612675860524178, -0.030096527189016342, 0.0167288389056921, -0.03649488463997841, -0.025156186893582344, -0.011246934533119202, -0.007621750235557556, -0.07332409918308258, -0.03930448368191719, 0.010702087543904781, 0.05...
0.011508
# REPL > Stability: 2 - Stable The `node:repl` module provides a Read-Eval-Print-Loop (REPL) implementation that is available both as a standalone program or includible in other applications. It can be accessed using: ```mjs import repl from 'node:repl'; ``` ```cjs const repl = require('node:repl'); ``` ## Design and f...
https://github.com/nodejs/node/blob/main//doc/api/repl.md
main
nodejs
[ -0.13750645518302917, 0.002248306293040514, -0.06426481902599335, 0.06610836088657379, 0.019181715324521065, -0.040903009474277496, -0.01867767609655857, 0.017265863716602325, 0.025397446006536484, -0.026093875989317894, -0.04236967861652374, 0.04603302851319313, 0.021245116367936134, -0.0...
0.08138