官术网_书友最值得收藏!

JSON

Now that you know how to parse command-line arguments using process.argv and yargs, you've solved the first piece to the puzzle for the notes application. Now, how do we get that unique input from the user? The second piece to the puzzle is to solve how we store this information.

When someone adds a new note, we want to save it somewhere, preferably on the filesystem. So the next time they try to fetch, remove, or read that note, they actually get the note back. To do this, we'll need to introduce something called JSON. If you're already familiar with JSON, you probably know it is super popular. It stands for JavaScript Object Notation, and it's a way to represent JavaScript arrays and objects using a string. Now, why would you ever want to do that?

Well, you might want to do that because strings are just text, and that's pretty much supported anywhere. I can save JSON to a text file, and then I can read it later, parse it back into a JavaScript array or object, and do something with it. This is exactly what we'll take a look at in this section.

To explore JSON and how it works, let's go ahead and make a new folder inside our project called playground.

Throughout the book, I'll create the playground folders and various projects, which store simple one-off files that aren't a part of the bigger application; they're just a way to explore a new feature or learn a new concept.

In the playground folder, we'll make a file called json.js, this is where we can explore how JSON works. To get started, let's make a very simple object.

主站蜘蛛池模板: 英超| 兖州市| 曲松县| 文水县| 芷江| 苗栗市| 江安县| 衡阳县| 沁阳市| 南宫市| 万盛区| 汨罗市| 上虞市| 房产| 新田县| 泰州市| 绥德县| 长泰县| 密云县| 韶关市| 砚山县| 达拉特旗| 宾川县| 淅川县| 香港 | 云霄县| 黔东| 东至县| 富源县| 宝应县| 兴文县| 康马县| 波密县| 卓资县| 启东市| 揭阳市| 阿拉尔市| 罗江县| 巍山| 固阳县| 柏乡县|