Giter VIP home page Giter VIP logo

kumparan-technical-test's Introduction

Kumparan technical test

RESTfull API with Node.js using the Express.js Framework. Express.js is one of the popular web frameworks in the Node.js . Explore More Express.js. Also use Redis for Caching. So, the data retrieval process is faster . This RESTful API was tested using mocha and chai with more than 30% of coverage, also with istanbul for the code coverage. for handle thousand data, redis is the way because It use caching method load more faster and efficient .

Built With

Express.js Node.js

Requirements

  1. Node Js
  2. database (Mysql)
  3. Postman
  4. Web Server (ex. XAMPP)

Getting Started

In this project I use the Morgan package which serves as recording every request to the server.

Here to Use Morgan

var express = require('express')
var morgan  = require('morgan')
 
var app = express()
app.use(morgan())

and then there is a nodemon package to automatically restart the app node when our code changes so there is no need to restart manually

npm install -g nodemon

If use yarn

yarn add -g nodemon

Usage For Development

Clone this repository, then :

  1. Open app's directory in CMD or Terminal
  2. Type npm install or yarn install
  3. Make new file a called .env, set up first here
  4. Turn on Web Server and MySQL can using Third-party tool like xampp, etc.
  5. Create a database with the name article_service_db, and Import file article_service_db.sql to phpmyadmin
  6. Open Postman desktop application or Chrome web app extension that has installed before
  7. Choose HTTP Method and enter request url.(ex. localhost:8080/book)
  8. You can see all the end point here

if use yarn , type this to start server

yarn start



Set up .env file

Open .env file on your code editor, and copy paste this code below :

SECRET_KEY=passwordkuaneh
REFRESH_TOKEN_SECRET=anehpasswordku

PORT = YOUR_CHOOSEN_PORT
DB_HOST= localhost
DB_USER= root
DB_PASSWORD=
DB_DATABASE= article_service_db
  

Screenshots Coverage

if dont wanna to use redis, follow this step

in app.js delete/ comment this code

in routes/article.js delete midd.getArticles

in controllers/article.js uncomment from above without redis and comment above redis

command line

for start server

yarn start

for start unit and integration test

yarn test

for start test and check coverage

yarn cover

End Point

GET

GET Article response

  • /article
{
    "status": 200,
    "message": "GET Data Successfully",
    "data": [
        {
            "id": 4,
            "author_id": "123123",
            "title": "test",
            "body": "try body",
            "created_at": "2022-01-06T16:22:30.000Z",
            "author_name": "j.k rowling"
        },
        {
            "id": 3,
            "author_id": "123123",
            "title": "twitter",
            "body": "A twitter is a network of 3D virtual worlds focused on social connection. ... In futurism ",
            "created_at": "2022-01-06T15:15:36.000Z",
            "author_name": "j.k rowling"
        },
        {
            "id": 2,
            "author_id": "123123",
            "title": "facebook",
            "body": "facebook is the most popular social media now,",
            "created_at": "2022-01-06T11:24:34.000Z",
            "author_name": "j.k rowling"
        },
        {
            "id": 1,
            "author_id": "123123",
            "title": "metaverse",
            "body": "A metaverse is a network of 3D virtual worlds focused on social connection. ... In futurism ",
            "created_at": "2022-01-06T11:22:12.000Z",
            "author_name": "j.k rowling"
        }
    ]
}
  • /article?query=meta
 {
    "status": 200,
    "message": "GET Data Successfully",
    "data": [
        {
            "id": 1,
            "author_id": "123123",
            "title": "metaverse",
            "body": "A metaverse is a network of 3D virtual worlds focused on social connection. ... In futurism ",
            "created_at": "2022-01-06T11:22:12.000Z",
            "author_name": "j.k rowling"
        }
    ]
}

POST

  • /article
 {
    "status": 200,
    "message": "POST Data Successfully",
    "data": {
        "id": "11",
        "author_id": "123123",
        "title": "twitter",
        "body": "A twitter is a network of 3D virtual worlds focused on social connection. ... In futurism ",
        "result": {
            "fieldCount": 0,
            "affectedRows": 1,
            "insertId": 11,
            "serverStatus": 2,
            "warningCount": 0,
            "message": "",
            "protocol41": true,
            "changedRows": 0
        }
    }
}

Dependencies

  • express
  • mysql
  • body-parser
  • morgan
  • nodemon
  • cors
  • redis
  • dotenv

Dev packages

  • mocha
  • chai
  • chai-http
  • nyc

Authors

  • Dwiky satria hutomo

http://github.com/dwikysahut

kumparan-technical-test's People

Contributors

dwikysahut avatar

Watchers

Tedja 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.