Giter Club home page Giter Club logo

filemanager-nodejs's Introduction

fileManager-NodeJS

image

Tech Technologies

  • NodeJS
  • AMAZON S3

npm Packages

  • express
  • aws-sdk
  • multer, multer-s3
  • jsonwebtoken, bcrypt
  • sequelize, sequelize-cli
  • dotenv, body-parser
  • pg, pg-hstore
  • nodemon (dev dependency)

API's defined in depth

Every API starts with /api/v1 here api defines that the link is an API, and v1 mentions the version of the API. All endpoints are defined in the way they'll be used in real life.

User API

  1. Let's register our users first.
    .../user/signup
    This takes body params, the user's EMAIL, and PASSWORD. Raw passwords without encryption are not recommended to store in the database, so using BCRYPT to encrypt passwords.

  1. Getting a user token for LOGIN and further authorization to access other endpoints
    .../user/signin
    Request body parameter [RBP]: User's EMAIL and PASSWORD
    Response: JWT token

  1. We'll be needing some API to get user details from JWT token
    .../user/currentUser
    x-access-token (header parameter)[RHP]: JWT Token
    Response: User Details

Folder API

There can be factorial ways to define the relationship between folders and subfolders. Here I'm storing the parentFolder name of a file by default it's root.

  1. Creating Folders
    .../folder/create
    RBP: UserId, folderName, parentFolder
    RHP: x-access-token (jwt token)
    Response: JSON data showing Success if folder created / Error

  1. Get all folders associated with a user
    .../folder/all
    RBP: userId
    RHP: x-access-token (jwt token)
    Response: Folder Data / Error

  1. Update folder properties
    .../folder/update
    parentFolder is very useful information to handle the subfolders.
    RBP: userId , folderId, folderName(optional), parentFolder(optional)
    RHP: x-access-token (jwt token)
    Response : Update success message with updated details / Error

File API

Using Amazon S3 bucket to store files and Postgres database to store metadata of the file.

  1. Uploading file to S3
    /uploadPage
    This endpoint will open an HTML interface to upload files.
    /upload
    The above endpoint will upload the file and return the data from S3 bucket

  1. Adding file data to POSTGRES database
    ../file/add
    RBP: userId, fileName
    RHP: x-access-token (jwt token)
    Response : Created success message with file details / Error

  1. Getting files
  • without search query parameter
    ../file/get
    RBP: userId
    RHP: x-access-token (jwt token)
    Response : All file data associated with a user / Error

  • with the search parameter
    ../file/get?search=anyName
    RBP: userId
    RHP: x-access-token (jwt token)
    Query Parameters : anyName
    Response : Search query result / Error

  1. Update a File
    ../file/update
    RBP: userId, filed, fileName(optional) , parentFolder(optional), isPublic(optional)
    RHP: x-access-token (jwt token)
    Response : Updated data with success message / Error

  1. Share file to Public
    This endpoint is used to share files with anyone over the internet but it should be made public by the owner of the file [isPublic].
    /file?id=fileId
    Query Parameter: fileId
    Response : file data / Error

Folder Structure Explained in .\src

  • \apis: API folder handles all the endpoint names and versions.
  • \config: CONFIG folder handled database connection, database configuration, and environment variable exports
  • \controller: CONTROLLER layer folder handles all requests and responses that an API endpoint is getting.
  • \middlewares: MIDDLEWARES have two middleware files one is to verify the user inputs and another to check the authorization of the user.
  • \migration: This folder tracks all changes in the schema of any particular table.
  • \models: MODELS folder contains all schema information about a table.
  • \respository: REPOSITORY layer has access to directly create changes in the database.
  • \seeders: SEEDERS folder is used to insert sample data into the tables
  • \service: SERVICE layer very important layer that contains all business logic and complexities.
  • \index.html: HTML file provides interface to upload file
  • \index.js MAIN file which handles the start server and handles all requests.

Local Development Setup

INSTALL

Node
Postgres

Open terminal

  1. Clone this repository
git clone [email protected]:futoid/fileManager-NodeJS.git
  1. Installing all dependency
npm install
  1. Creating NEW DATABASE
psql -U <PSQL_USERNAME>

Create a new database. And remember this DATABASE_NAME.

CREATE DATABASE <DATABASE_NAME>

change /src/config/config.json

{
  "development": {
    "username": PSQL_USERNAME,
    "password": POSTGRES_PASSWORD,
    "database": DATABASE_NAME,
    "host": "127.0.0.1",
    "dialect": "postgres"
  }
}

create .env

PORT = PORT
JWT_KEY = STRONG KEY - ANYTHING not common
DEV_DATABASE_URL = postgres://<PSQL_USERNAME>:<PSQL_USERNAME>@127.0.0.1:5432/<DATABASE_NAME>
USERNAME = PSQL_USERNAME
DB_PASSWORD = POSTGRES_PASSWORD

# S3 Access Keys
S3_REGION = 
ACCESS_KEY = 
SECRET_KET = 

Creating Tables

npx sequelize db:migrate

This command will create all required tables into our DATABASE as mentioned in ./src/models folder

RUNNING PROJECT

npm start

Test all endpoints in any API testing tool.

Created by: Aliek Mandal

filemanager-nodejs's People

Contributors

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