0

In this case when initializing the file handling system in node.js the online documentation uses:

const fs = require('fs');
const { URL } = require('url');
const fileUrl = new URL('file:///tmp/hello');

fs.readFileSync(fileUrl);

I am not familiar with the braces around the URL as in { URL }. What do they do here? On the previous line the fs is not surrounded with braces.

https://nodejs.org/dist/latest-v8.x/docs/api/fs.html#fs_threadpool_usage

Bob Brunius
  • 1,344
  • 5
  • 14
  • 21
  • Does this answer your question? [Javascript object bracket notation ({ Navigation } =) on left side of assign](https://stackoverflow.com/questions/26999820/javascript-object-bracket-notation-navigation-on-left-side-of-assign) – Zam Abdul Vahid Apr 02 '21 at 01:05

1 Answers1

0

It's a destructuring assignment. Without the brackets you would have to use url.URL() every time instead of simply URL():

const url = require('url');
const fileUrl = new url.URL('file:///tmp/hello');

Here's a similar answer if you want more info.

Simon
  • 774
  • 4
  • 21