Giter Site home page Giter Site logo

nmanikiran / rest-api-node-typescript Goto Github PK

View Code? Open in Web Editor NEW
184.0 6.0 52.0 447 KB

This is a simple REST API with node and express with typescript

TypeScript 100.00%
nodejs nodemon typescript express postgresql restapi tsc production logger sequelize

rest-api-node-typescript's Introduction

REST API with Node using Typescript

This is a simple REST API developed using node and express with typescript

alt text

❤️ Found this project useful?

If you found this project useful, then please consider giving it a ⭐️ on Github and sharing it with your friends via social media.

Requirements

Node.js, postgresql

Getting Started

Setup DB

  1. You need to install PostgreSQL

    • For Windows

      • Install PostgreSQL and set following environment variable C:\Program Files\PostgreSQL\10\bin, C:\Program Files\PostgreSQL\10\lib
    • For Ubuntu

      • Installation sudo apt update sudo apt-get install postgresql postgresql-contrib

      • Manage PostgreSQL service sudo systemctl {status | start | restart | stop} postgresql

  2. rename .env-sample to .env in the file the DB connection string need to be updated according to your credentials. ex : postgres://<YourUserName>:<YourPassword>@localhost:5432/<YourDatabase>

  3. you can find the DB and other details under src/db create a database with the name node-typescript-rest-api and then run/ import the .sql files (extract the sql files from sql.zip). Or you can run npm run seed.

  4. install pm2 globally with npm install -g pm2

Run the app locally

  • git clone https://github.com/nmanikiran/rest-api-node-typescript.git

  • npm install

  • npm start - This will start the application and run on port 3000

  • npm run dev - This will start the application in development mode

  • npm run watch & pm2 start ecosystem.config.js to start the application with cluster for scalability

you can change port in .env file check .env-sample

Folder Structure

src
└───index.ts          # Application entry point
└───routes            # Application routes / endpoints
└───controllers       # Express route controllers for all the endpoints of the app
└───repositories      # All the database interaction logic is here
└───db                # DB related files like connection / seed data
└───handlers          # Common logic
└───logs              # application logs
└───middlewares       # express middlewares
└───models            # DB Models (Postgress)
└───validators        # API Request object validations

Features

  • CRUD operations for Courses
  • CRUD operations for Lessons
  • REST API Request object validations - Basic
  • Error Logs
  • Setup docs
  • Seeder for DB

Planned

  • JWT login
  • Unit Testing
  • Postman collections
  • Improve request Object Validations
  • Improve Error Messages for request failures
  • Project / DB Setup in Ubuntu - Docs
  • Security
  • Hosting

REST Services

The application exposes a few REST endpoints

HTTP GET /api/lessons

HTTP GET /api/lessons/:id

HTTP GET /api/courses

You can use the following code snippet to call the secured endpoint:

fetch("http://localhost:3000/api/courses", {
  method: "GET",
  headers: {
    "Content-Type": "application/json",
  },
})
  .then((response) => {
    if (response.status === 200) {
      response.json().then((j) => console.log(j));
    } else {
      console.log("ERROR", response.status);
    }
  })
  .catch((error) => console.log(error));

Created & Maintained By

Mani Kiran
Mani Kiran N

💻 📖 🤔 👀 🚧
Tushar Gupta
Tushar Gupta

💻 📖 💬 🚧

Feel free to reach out to me through @nmanikiran if you have any questions or feedback!

Recommended / Preferred

VSCode

Thanks & Credits to

rest-api-node-typescript's People

Contributors

curioustushar avatar nmanikiran avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

rest-api-node-typescript's Issues

[nodemon] app crashed

I wanted to see your project, but I have this error
[nodemon] app crashed - waiting for file changes before starting...
help me please

[nodemon] app crashed

[nodemon] app crashed - waiting for file changes before starting...

node v8.11.3
npm v6.1.0

JWT based login

need to implement JWT login
and update all the apis along with postman collection

Need to send unified Error message

the strucuture cloud be
message // error mesage
errors // Array for errors for form validations & additional validations
status // http status code
stack // stack tarce

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.