Coder Social home page Coder Social logo

board-infinity-assignment's Introduction

Board-Infinity-assignment

Link to Heroku app https://board-inf-avinash11804771.herokuapp.com/ ##Task Implementation Create a REST API to add tasks and list them.
Run using command: npm run watch or nodemon index.js or node index.js

Task is to automatically delete the task after a DURATION.

Duration(in Minutes) of task is provided by USER
To implement automatic deletion in MongoDB used TTL Time to live.

  1. we need to create a index in collection using createIndex in mongoDB
    Code

     db.tasks.createIndex( { "expireAt": 1 }, { expireAfterSeconds: 0 } )
    

Whenever we insert a document and want that document to be deleted automatically we need to pass expireAt value as date and mongoDB will delete after the date-time.

    db.tasks.insert( {
       "expireAt": new Date(),
       "logEvent": 2,
       "logMessage": "Success!"
    } )

There are 2 endpoints /listTasks and /addTasks

  1. /listTasks returns all the task and we populate the data on frontend.
  2. /addTasks takes data from front-end and created expireAt date UTC date by adding Duration to current dateTime and insert into Database.

Node Modules Used

"dependencies": {
    "body-parser": "^1.19.0",
    "dotenv": "^8.2.0",
    "express": "^4.17.1",
    "mongoose": "^5.9.26",
    "nodemon": "^2.0.4"
  },

Data fromat to save in DB for /addTasks

    const task=new tasks({
            taskName:req.body.name,
            taskDesc:req.body.desc,
            creator:req.body.creator,
            duration:duration,
            expireAt:new Date(timeNow.toISOString())
        })
    task.save()
        .then(ans=>{
            return res.json({
                success:true
            })
        })

Returning Tasks to front-end /getTasks

app.get('/listTasks',((req, res) => {
    tasks.find({})
        .then(data=>{
            return res.json(data);
        })
}))

##Created by Avinash Kumar 11804771, [email protected] PS: Automatically deletion of task may not take effect instantaneously because mongoDB checks every 60 sec so it might take close to 1 min for task to delete automatically

board-infinity-assignment's People

Contributors

avinash0786 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.