Skip to content

Instantly share code, notes, and snippets.

View Josh4324's full-sized avatar

ADESANYA JOSHUA AYODEJI Josh4324

View GitHub Profile
@Josh4324
Josh4324 / gist1.js
Last active November 23, 2020 22:13
Create Todo
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([]))
}
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);
@Josh4324
Josh4324 / getOne.js
Last active November 24, 2020 09:44
Get One Todo
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) => {
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) => {
const yargs = require("yargs");
const utils = require("./utils");
yargs.command({
command: "add",
describe: "Add a new todo",
builder: {
title: {
describe: "Todo title",
type: "string",
yargs.command({
command: "list",
describe: "Get all Todos",
handler: function () {
utils.listTodo()
},
});
yargs.command({
command: "read",
describe: "get a specific todo with the title",
builder: {
title: {
describe: "Todo title",
type: "string",
demandOption: true,
}
},
yargs.command({
command: "delete",
describe: " Remove a specific todo with the title",
builder: {
title: {
describe: "Todo title",
type: "string",
demandOption: true,
}
},
@Josh4324
Josh4324 / package.json
Created July 26, 2021 08:39
Package.json initial content
{
"name": "sequelize-project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
@Josh4324
Josh4324 / app.js
Last active July 26, 2021 14:52
Initial code inside app.js
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(