This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require("fs"); | |
const createTodo = (title, todo) => { | |
try { | |
// check if the json file exists | |
fs.access('todos.json', (err) => { | |
// if it does not exist, create a new json file | |
if (err){ | |
fs.writeFileSync('todos.json', JSON.stringify([])) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const listTodo = () => { | |
try { | |
// read from the todos.json if it exists | |
const todoBuffer = fs.readFileSync("todos.json"); | |
// convert it to string | |
let dataJSON = todoBuffer.toString(); | |
// parse the data | |
const todos = JSON.parse(dataJSON); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getOneTodo = (title) => { | |
try { | |
// read from the todos.json if it exists | |
const todoBuffer = fs.readFileSync("todos.json"); | |
// convert it to string | |
let dataJSON = todoBuffer.toString(); | |
// parse the data | |
const todos = JSON.parse(dataJSON); | |
const Todo = todos.find((item) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const deleteTodo = (title) => { | |
try { | |
// read from the todos.json if it exists | |
const todoBuffer = fs.readFileSync("todos.json"); | |
// convert it to string | |
let dataJSON = todoBuffer.toString(); | |
// parse the data | |
const todos = JSON.parse(dataJSON); | |
const remain = todos.filter((item) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const yargs = require("yargs"); | |
const utils = require("./utils"); | |
yargs.command({ | |
command: "add", | |
describe: "Add a new todo", | |
builder: { | |
title: { | |
describe: "Todo title", | |
type: "string", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
yargs.command({ | |
command: "list", | |
describe: "Get all Todos", | |
handler: function () { | |
utils.listTodo() | |
}, | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
yargs.command({ | |
command: "read", | |
describe: "get a specific todo with the title", | |
builder: { | |
title: { | |
describe: "Todo title", | |
type: "string", | |
demandOption: true, | |
} | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
yargs.command({ | |
command: "delete", | |
describe: " Remove a specific todo with the title", | |
builder: { | |
title: { | |
describe: "Todo title", | |
type: "string", | |
demandOption: true, | |
} | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "sequelize-project", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"keywords": [], | |
"author": "", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require("express"); | |
const cors = require("cors"); | |
const morgan = require("morgan"); | |
require("dotenv").config(); | |
const port = process.env.PORT || 3000; | |
const app = express(); | |
app.use( |
OlderNewer