본문 바로가기

JSON3

Node.js를 사용해서 Notes 앱 만드는 방법 안녕하세요. 혀코입니다. 오늘은 Node.js를 사용해서 Notes 앱 만드는 방법에 대해서 알아보겠습니다. app.js를 다음과 같이 작성합니다. const yargs = require('yargs') // 사용자로부터 명령어를 받는다. const notes = require('./notes.js') // 노트 추가, 삭제, 리스트, 읽기등의 함수를 가진다. yargs.command({ // 노트를 추가할 수 있는 명령어를 정의한다. command: 'add', // 명령어 describe: 'Add a new note', //설명 builder: { // 옵션 2개 title과 body를 가진다. title: { describe: 'Note title', // 옵션 설명 demandOption: tr.. 2020. 1. 3.
Node.js에서 JSON 데이터 추가하는 방법(readFileSync, push, writeFileSync) 안녕하세요. 혀코입니다. 오늘은 Node.js에서 JSON 데이터를 추가하는 방법에 대해서 알아보겠습니다. app.js 를 다음과 같이 작성합니다. const yargs = require('yargs') const notes = require('./notes.js') // Customize yargs version yargs.version('1.1.0') // Create add command yargs.command({ command: 'add', describe: 'Add a new note', builder: { title: { describe: 'Note title', demandOption: true, type: 'string' }, body: { describe: 'Note body', dem.. 2020. 1. 2.
Node.js에서 JSON 파일에 데이터를 저장하고 읽는 방법 안녕하세요. 혀코입니다. 오늘은 Node.js에서 JSON 파일에 데이터를 저장하는 방법에 대해서 알아보겠습니다. app.js 파일을 다음과 같이 작성합니다. const book = { title: 'Ego is the Enemy', author: 'Ryan Holiday' } const bookJSON = JSON.stringify(book) console.log(bookJSON) 다음 명령어를 실행해 보겠습니다. $ node app.js 결과는 다음과 같이 출력되는 것을 확인할 수 있습니다. {"title":"Ego is the Enemy","author":"Ryan Holiday"} 이번에는 author에 해당하는 값만 출력하는 방법에 대해서 알아보겠습니다. app.js 파일을 다음과 같이 작성합니.. 2020. 1. 2.