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

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.

主站蜘蛛池模板: 泗水县| 赣榆县| 黄冈市| 凤山市| 昭苏县| 尼木县| 拉孜县| 安宁市| 行唐县| 岫岩| 措美县| 绵阳市| 义乌市| 伊春市| 望都县| 曲周县| 临澧县| 夏津县| 恭城| 醴陵市| 桃园市| 钟祥市| 任丘市| 广丰县| 定日县| 民和| 巴塘县| 大同县| 嘉祥县| 金秀| 侯马市| 辉县市| 平江县| 武定县| 堆龙德庆县| 青阳县| 湘阴县| 阳江市| 黄梅县| 庐江县| 嘉善县|