Coder Social home page Coder Social logo

mujtabadustox / nodejs-postgresql-product-backend-rest-jwt Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 19 KB

Product Backend in Nodejs and PostgreSQL using Knex with JWT User Authentication and Token based Authorization for APIs

JavaScript 100.00%
knex nodejs postgresql product rest-api

nodejs-postgresql-product-backend-rest-jwt's Introduction

I used PostgreSQL from my local PC , you can find its url from knex file , just have to change back to yours

After that please run migrations and seed since for authentication I am creating two more coloumns in Customer table , email and password and run the seed file to populate ,the emails are [email protected] and passwords are firstname+123 (hashed value , using bcrypt 10 rounds)

1st i have uploaded .env file since it is a private repo , 2nd i have used Raw SQL even though knex ORM is in project because it is was this way in the code given

  • npm i //to install new dependencies
  • npx knex migrate:latest --env development //to run migrations
  • npx knex seed:run --env=development //to run seeds
  • then nodemon (node server.js)

to get the token run the Customer Post api , localhost:3000/customer and add email and password in body i.e

{ "email": "[email protected]", "password" : "liam123" }

image

after getting the token please ut token in postman Header by creating key Authorization and value Bearer [token], I havent tried with postmans built in Authorization Tab but that should work too

image

the get apis are simple

for post and put

post order

send this body and token in header

{ "customer_id" : 1 , "products" : [ { "product_id" : 8 , "quantity" : 17 }, { "product_id" : 9 , "quantity" : 23 } ] }

image

for put request send this body and token in header

image

image

image

I havent tested this fully but it works for a dummy backend , sometimes values get bad because of mutation i am using very bad logic , using let keyword etc , I havent thought on it much , but it does work 99% of the time , it can be better i will do later if i get time for now for this task i feel like it is ok

Thank you

nodejs-postgresql-product-backend-rest-jwt's People

Contributors

mujtabadustox avatar

Watchers

Mohammad Sahil Achhava 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.