constnewname=`The time is ${hoursAndMinutes} GMT`;console.log(newname)// The time is 08:00 GMT
make a function which return the new name;
constgenerateNewName=()=>{constcurrentDate=newDate().toUTCString();consthoursAndMinutes=currentDate.slice(currentDate.indexOf(":")-2,22);constnewname=`The time is ${hoursAndMinutes} GMT`;returnnewname;};console.log(generateNewName())// logs "The time is 08:00 GMT"
3- Getting the github token
you will need your github token to use it when update your account.
you can find the steps get your token in github docs
write node {filename}.js in the terminal.
e.g. node index.js
so, the whole code will be
constdotenv=require("dotenv");constfetch=require("cross-fetch")dotenv.config()consttoken=process.env.GITHUB_TOKEN//*========> [ GENERATE THE NEW NAME ] <============= constgenerateNewName=()=>{constcurrentDate=newDate().toUTCString();consthoursAndMinutes=currentDate.slice(currentDate.indexOf(":")-2,22);constnewname=`The time is ${hoursAndMinutes} GMT`;returnnewname;};//!======================//*========> [ UPDATE ACCOUNT FUNCTION ] <============= constupdateAccount=async()=>{letres=awaitfetch('https://api.github.com/user',{method:'PATCH',body:JSON.stringify({name:generateNewName(),}),headers:{'Content-type':'application/json; charset=UTF-8',Authorization:`Bearer ${token}`,},})console.log(res.status)}//!=====================================//*========> [ EVERY MINUTE ] <============= setInterval(()=>{updateAccount()},60000)// !================