Code Monkey home page Code Monkey logo

node-js-initial-template's Introduction

Node Js Starter Template API with MySQL, Express and JWT Authentication.

Introduction

This project provides a RESTful API for user management. It allows users to register, login, view their profile and update their information. The API is built using Node.js, Express and MySQL. It utilizes JSON Web Tokens (JWT) for authentication.

Prerequisites

To run this project, you will need the following:

  • Node.js installed on your system.
  • MySQL database server running.
  • A MySQL client, such as MySQL Workbench, to create and manage the database.

Setup

  1. Clone the project repository.
git https://github.com/vanshul22/Node-js-Initial-template.git
  1. Install the dependencies.
npm install
  1. Create a .env file in the project root directory and add the following environment variables:
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=password
DB_NAME=test
JWT_SECRET=secret
  1. Create the database and tables.
mysql -u root -p password -D test < schema.sql
  1. Server :

(A) Start the Production server.

npm run start

(B) Start the Development Server.

npm run dev

Usage

Register a new user

curl -X POST http://localhost:3000/api/users -H "Content-Type: application/json" -d '{"username": "johndoe", "password": "secret"}'

Login

curl -X POST http://localhost:3000/api/users/login -H "Content-Type: application/json" -d '{"username": "johndoe", "password": "secret"}'

Get all users

curl -X GET http://localhost:3000/api/users -H "Authorization: Bearer <token>" -H "Content-Type: application/json"

Get a user by ID

curl -X GET http://localhost:3000/api/users/1 -H "Authorization: Bearer <token>" -H "Content-Type: application/json"

Update a user

curl -X PUT http://localhost:3000/api/users/1 -H "Authorization: Bearer <token>" -H "Content-Type: application/json"

Delete a user

curl -X DELETE http://localhost:3000/api/users/1 -H "Authorization: Bearer <token>" -H "Content-Type: application/json"

node-js-initial-template's People

Contributors

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