GithubHelp home page GithubHelp logo

express-backend-starter's Introduction

Backend-Starter

Simple server app with JWT authentication that uses Mysql, Node.js, and the Express web framework

Requirements

  • git
  • Node.js
  • A browser (e.g., Firefox or Chrome)
  • bash shell
  • Mysql

How To Start

  • rename the .env.example file to .env
  • add mysql database information
  • paste your cluster connection string to DB_CONNECTION in .env
  • add TOKEN_SECRET for JWT
  • Install dependencies with npm install
  • Run the server locally with npm start or npm run dev

View local app in browser

Test requests with Postman

test app with Postman (provides token)

  1. POST http://localhost:3000/api/users/register - set Body / Raw / JSON - Send
{
  "name": "Fajar Rivaldi Chan",
  "email": "[email protected]",
  "password": "123456789"
}

Should return something like:

{
    "name": "Fajar Rivaldi Chan",
    "email": "[email protected]",
    "password": "$2a$10$hQN7uKIcuu2fXTet2nxPSe3jXD7GtSglsX/2JZM3Wxz31JWk8mTTS",
    "_id": "6288838ce9afa35b2f1537b1",
    "created_at": "2022-05-21T06:15:40.958Z",
    "__v": 0
}
  1. POST http://localhost:3000/api/users/login - set Body / Raw / JSON - Send
{
  "email": "[email protected]",
  "password": "123456789"
}

Should return something like:

{
    "messsage": "loggedd In ",
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2Mjg4ODM4Y2U5YWZhMzViMmYxNTM3YjEiLCJpYXQiOjE2NTMxMTM3OTR9.7wdHLeDIxzJCm7ZyOWJSlk1b1HPp2Y4cxIVNzcnjf5g",
    "name": "fajri",
    "email": "[email protected]"
}
  1. GET http://localhost:3000/api/example set Headers auth-token : <YOUR_TOKEN> example auth-token : eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2Mjg4ODM4Y2U5YWZhMzViMmYxNTM3YjEiLCJpYXQiOjE2NTMxMTM3OTR9.7wdHLeDIxzJCm7ZyOWJSlk1b1HPp2Y4cxIVNzcnjf5g

response:

{
    "title": "Example Title",
    "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin vel libero turpis. Suspendisse venenatis, nunc nec aliquam mollis, mi libero aliquam nunc, ut condimentum odio metus id nisi. Sed ac ex placerat, egestas dui vel, fermentum leo. Fusce sed velit at enim tempus vehicula. Nulla maximus sit amet turpis id aliquam. Donec ut arcu hendrerit, convallis augue et, laoreet tortor. Proin interdum magna consectetur lacinia posuere. Sed erat nunc, laoreet sed justo id, dapibus imperdiet elit. Vestibulum sit amet ornare ipsum. Sed cursus metus non nisl euismod, eget mollis metus blandit. Nulla facilisi. "
}

express-backend-starter's People

Contributors

fajar-dev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.