Mercurial > hg > nginx-site
comparison xml/en/docs/njs/reference.xml @ 2507:8ad2ea80e0c2
njs-0.3.9
author | Yaroslav Zhuravlev <yar@nginx.com> |
---|---|
date | Tue, 03 Mar 2020 15:45:30 +0000 |
parents | 805c4b84cc61 |
children | d3d5b67a1462 |
comparison
equal
deleted
inserted
replaced
2506:feb8b843e482 | 2507:8ad2ea80e0c2 |
---|---|
7 <!DOCTYPE article SYSTEM "../../../../dtd/article.dtd"> | 7 <!DOCTYPE article SYSTEM "../../../../dtd/article.dtd"> |
8 | 8 |
9 <article name="Reference" | 9 <article name="Reference" |
10 link="/en/docs/njs/reference.html" | 10 link="/en/docs/njs/reference.html" |
11 lang="en" | 11 lang="en" |
12 rev="35"> | 12 rev="36"> |
13 | 13 |
14 <section id="summary"> | 14 <section id="summary"> |
15 | 15 |
16 <para> | 16 <para> |
17 <link doc="index.xml">njs</link> provides objects, methods and properties | 17 <link doc="index.xml">njs</link> provides objects, methods and properties |
217 </tag-desc> | 217 </tag-desc> |
218 | 218 |
219 <tag-name><literal>method</literal></tag-name> | 219 <tag-name><literal>method</literal></tag-name> |
220 <tag-desc> | 220 <tag-desc> |
221 HTTP method, by default the <literal>GET</literal> method is used | 221 HTTP method, by default the <literal>GET</literal> method is used |
222 </tag-desc> | |
223 | |
224 <tag-name><literal>detached</literal></tag-name> | |
225 <tag-desc> | |
226 boolean flag (<link doc="changes.xml" id="njs0.3.9">0.3.9</link>), | |
227 if <literal>true</literal>, the created subrequest is a detached subrequest. | |
228 Responses to detached subrequests are ignored. | |
229 Unlike ordinary subrequests, a detached subrequest | |
230 can be created inside a variable handler. | |
231 The detached flag and callback argument are mutually exclusive. | |
222 </tag-desc> | 232 </tag-desc> |
223 | 233 |
224 </list> | 234 </list> |
225 </para> | 235 </para> |
226 | 236 |
1160 | 1170 |
1161 <section id="njs_api_fs" name="File System"> | 1171 <section id="njs_api_fs" name="File System"> |
1162 | 1172 |
1163 <para> | 1173 <para> |
1164 The File System module provides operations with files. | 1174 The File System module provides operations with files. |
1175 </para> | |
1176 | |
1177 <para> | |
1165 The module object is returned by <literal>require('fs')</literal>. | 1178 The module object is returned by <literal>require('fs')</literal>. |
1166 <list type="tag"> | 1179 Since (<link doc="changes.xml" id="njs0.3.9">0.3.9</link>), |
1180 promissified versions of methods described below are available through | |
1181 <literal>require('fs').promises</literal> object: | |
1182 <example> | |
1183 > var fs = require('fs').promises; | |
1184 undefined | |
1185 > fs.readFile("/file/path").then((data)=>console.log(data)) | |
1186 <file data> | |
1187 </example> | |
1188 <list type="tag"> | |
1189 | |
1190 <tag-name id="fs_accesssync"><literal>accessSync(<value>path</value>[, | |
1191 <value>mode</value>])</literal></tag-name> | |
1192 <tag-desc> | |
1193 Synchronously tests permissions for a file or directory | |
1194 specified in the <literal>path</literal> | |
1195 (<link doc="changes.xml" id="njs0.3.9">0.3.9</link>). | |
1196 If the check fails, an error will be returned, | |
1197 otherwise, the method will return undefined. | |
1198 <list type="tag"> | |
1199 | |
1200 <tag-name><literal>mode</literal></tag-name> | |
1201 <tag-desc> | |
1202 by default is <link id="access_const"><literal>fs.constants.F_OK</literal></link>. | |
1203 The mode argument is an optional integer | |
1204 that specifies the accessibility checks to be performed. | |
1205 <example> | |
1206 try { | |
1207 fs.accessSync('/file/path', fs.constants.R_OK | fs.constants.W_OK); | |
1208 console.log('has access'); | |
1209 } catch (e) { | |
1210 console.log('no access');) | |
1211 } | |
1212 </example> | |
1213 </tag-desc> | |
1214 | |
1215 </list> | |
1216 </tag-desc> | |
1167 | 1217 |
1168 <tag-name id="appendfilesync"><literal>appendFileSync(<value>filename</value>, | 1218 <tag-name id="appendfilesync"><literal>appendFileSync(<value>filename</value>, |
1169 <value>data</value>[, <value>options</value>])</literal></tag-name> | 1219 <value>data</value>[, <value>options</value>])</literal></tag-name> |
1170 <tag-desc> | 1220 <tag-desc> |
1171 Synchronously appends specified <literal>data</literal> | 1221 Synchronously appends specified <literal>data</literal> |
1223 >> var gzipped = /^\x1f\x8b/.test(file); gzipped | 1273 >> var gzipped = /^\x1f\x8b/.test(file); gzipped |
1224 true | 1274 true |
1225 </example> | 1275 </example> |
1226 </tag-desc> | 1276 </tag-desc> |
1227 | 1277 |
1278 <tag-name id="fs_realpathsync"><literal>realpathSync(<value>path</value>[, | |
1279 <value>options</value>])</literal></tag-name> | |
1280 <tag-desc> | |
1281 Synchronously computes the canonical pathname by resolving | |
1282 <literal>.</literal>, <literal>..</literal> and symbolic links using | |
1283 <link url="http://man7.org/linux/man-pages/man3/realpath.3.html">realpath(3)</link> | |
1284 The <literal>options</literal> argument can be a string specifying an encoding, | |
1285 or an object with an encoding property specifying the character encoding | |
1286 to use for the path passed to the callback | |
1287 (<link doc="changes.xml" id="njs0.3.9">0.3.9</link>). | |
1288 </tag-desc> | |
1289 | |
1228 <tag-name id="writefilesync"><literal>writeFileSync(<value>filename</value>, | 1290 <tag-name id="writefilesync"><literal>writeFileSync(<value>filename</value>, |
1229 <value>data</value>[, | 1291 <value>data</value>[, |
1230 <value>options</value>])</literal></tag-name> | 1292 <value>options</value>])</literal></tag-name> |
1231 <tag-desc> | 1293 <tag-desc> |
1232 Synchronously writes <literal>data</literal> to a file | 1294 Synchronously writes <literal>data</literal> to a file |
1254 >> var file = fs.writeFileSync('hello.txt', 'Hello world') | 1316 >> var file = fs.writeFileSync('hello.txt', 'Hello world') |
1255 undefined | 1317 undefined |
1256 </example> | 1318 </example> |
1257 </tag-desc> | 1319 </tag-desc> |
1258 | 1320 |
1259 <tag-name id="renamesync"><literal>renameSync(<value>oldPath</value>, | 1321 <tag-name id="fs_renamesync"><literal>renameSync(<value>oldPath</value>, |
1260 <value>newPath</value>)</literal></tag-name> | 1322 <value>newPath</value>)</literal></tag-name> |
1261 <tag-desc> | 1323 <tag-desc> |
1262 Synchronously changes the name or location of a file from | 1324 Synchronously changes the name or location of a file from |
1263 <literal>oldPath</literal> to <literal>newPath</literal> | 1325 <literal>oldPath</literal> to <literal>newPath</literal> |
1264 (<link doc="changes.xml" id="njs0.3.4">0.3.4</link>). | 1326 (<link doc="changes.xml" id="njs0.3.4">0.3.4</link>). |
1268 >> var file = fs.renameSync('hello.txt', 'HelloWorld.txt') | 1330 >> var file = fs.renameSync('hello.txt', 'HelloWorld.txt') |
1269 undefined | 1331 undefined |
1270 </example> | 1332 </example> |
1271 </tag-desc> | 1333 </tag-desc> |
1272 | 1334 |
1273 </list> | 1335 <tag-name id="fs_symlinksync"><literal>symlinkSync(<value>target</value>, |
1274 </para> | 1336 <value>path</value>)</literal></tag-name> |
1337 <tag-desc> | |
1338 Synchronously creates the link called <literal>path</literal> | |
1339 pointing to <literal>target</literal> using | |
1340 <link url="http://man7.org/linux/man-pages/man2/symlink.2.html">symlink(2)</link> | |
1341 (<link doc="changes.xml" id="njs0.3.9">0.3.9</link>). | |
1342 Relative targets are relative to the link’s parent directory. | |
1343 </tag-desc> | |
1344 | |
1345 <tag-name id="fs_unlinksync"><literal>unlinkSync(<value>path</value>)</literal></tag-name> | |
1346 <tag-desc> | |
1347 Synchronously unlinks a file by <literal>path</literal> | |
1348 (<link doc="changes.xml" id="njs0.3.9">0.3.9</link>). | |
1349 </tag-desc> | |
1350 | |
1351 </list> | |
1352 </para> | |
1353 | |
1354 | |
1355 <section id="access_const" name="File Access Constants"> | |
1356 | |
1357 <para> | |
1358 The <link id="fs_accesssync"><literal>access()</literal></link> method | |
1359 can accept the following flags. | |
1360 These flags are exported by <literal>fs.constants</literal>: | |
1361 | |
1362 <list type= "bullet" compact="no"> | |
1363 | |
1364 <listitem> | |
1365 <literal>F_OK</literal>—indicates that the file | |
1366 is visible to the calling process, | |
1367 used by default if no mode is specified | |
1368 </listitem> | |
1369 | |
1370 <listitem> | |
1371 <literal>R_OK</literal>—indicates that the file can be | |
1372 read by the calling process | |
1373 </listitem> | |
1374 | |
1375 <listitem> | |
1376 <literal>W_OK</literal>—indicates that the file can be | |
1377 written by the calling process | |
1378 </listitem> | |
1379 | |
1380 <listitem> | |
1381 <literal>X_OK</literal>—indicates that the file can be | |
1382 executed by the calling process | |
1383 </listitem> | |
1384 | |
1385 </list> | |
1386 </para> | |
1387 | |
1388 </section> | |
1275 | 1389 |
1276 | 1390 |
1277 <section id="njs_api_fs_flags" name="File System Flags"> | 1391 <section id="njs_api_fs_flags" name="File System Flags"> |
1278 | 1392 |
1279 <para> | 1393 <para> |