Skip to content

Instantly share code, notes, and snippets.

View anmolsukki's full-sized avatar
🎯
Software Engineer | Web Developer

Anmol Kumar Singh anmolsukki

🎯
Software Engineer | Web Developer
View GitHub Profile
@anmolsukki
anmolsukki / App.js
Last active May 5, 2020 13:50
[ NodeJs ] Json File Crud ( yargs )
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',
square = (x) => {
return x * x
}
console.log(square(3))
const squares = (x) => x * x;
console.log(squares(4))
@anmolsukki
anmolsukki / index.js
Created May 5, 2020 12:46
[ NodeJs ] Read Write Json Challenge ( https://repl.it/@anmolsukki/4ReadWriteJson )
const fs = require('fs')
const dataBuffer = fs.readFileSync('person.json')
const dataJSON = dataBuffer.toString()
const user = JSON.parse(dataJSON)
user.name = 'Gunther'
user.age = 54
const userJSON = JSON.stringify(user)
const fs = require("fs");
const dataBuffer = fs.readFileSync("person.json")
console.log(dataBuffer)
console.log(dataBuffer.toString())
const dataJSON = dataBuffer.toString()
const data = JSON.parse(dataJSON)
console.log(data.title)
@anmolsukki
anmolsukki / index.js
Created May 5, 2020 12:39
[ NodeJs ] Write Json FileSystem ( https://repl.it/@anmolsukki/2WriteJsonFile )
const fs = require("fs");
const book = {
title: "Ego is the enemy",
author: "Ryan Holiday"
}
const bookJson = JSON.stringify(book);
fs.writeFileSync("1-person.json", bookJson)
const book = {
title: "Ego is the enemy",
author: "Ryan Holiday"
}
const bookJson = JSON.stringify(book);
console.log(bookJson)
const personData = JSON.parse(bookJson)
console.log(personData.author)
const chalk = require("chalk");
console.log(chalk.blue("Success!"))
const blueMessage = chalk.yellow("Succes!")
console.log(blueMessage)
const boldYellow = chalk.bold.yellow("Succes!")
console.log(boldYellow)
const boldInverse = chalk.bold.inverse.blue("Succes!")
const name = "Anmol"
module.exports = name
console.log("Anmol")
const add = function(a, b) {
return a + b
}
module.exports = add