GithubHelp home page GithubHelp logo

mattdanielbrown / nodejs-basic-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from app-generator/api-server-nodejs

0.0 1.0 0.0 263 KB

Nodejs Starter - Open-Source Javascript Boilerplate | AppSeed

Home Page: https://appseed.us/boilerplate-code/nodejs-starter

License: Other

JavaScript 5.32% TypeScript 94.68%

nodejs-basic-api's Introduction

Express/Nodejs Starter with JWT Authentication, OAuth (Github), and SQLite persistence - Provided by AppSeed. Authentication Flow uses json web tokens via Passport library - passport-jwt strategy.

๐Ÿ‘‰ Support via Discord & Email provided by AppSeed.


Features

  • ๐Ÿš€ Full-stack ready with React Soft Dashboard
  • โœ… Simple, intuitive codebase - can be extended with ease.
  • โœ… TypeScript, Joy for validation
  • โœ… Stack: NodeJS / Express / SQLite / TypeORM
  • โœ… Auth: Passport / passport-jwt strategy
  • ๐Ÿ†• OAuth for Github

Tested with:

NodeJS NPM YARN
v18.0.0 โœ… โœ…
v16.10.0 โœ… โœ…
v14.15.0 โœ… โœ…

Nodejs API Server - Open-source Nodejs Starter provided by AppSeed.


โœจ Requirements


โœจ How to use the code

๐Ÿ‘‰ Step 1 - Clone the project

$ git clone https://github.com/app-generator/api-server-nodejs.git
$ cd api-server-nodejs

๐Ÿ‘‰ Step 2 - Install dependencies via Yarn

$ npm i
// OR 
$ yarn

๐Ÿ‘‰ Step 3 - Run the SQLite migration via TypeORM

$ npm run typeorm migration:run
// OR 
$ yarn typeorm migration:run

๐Ÿ‘‰ Step 4 - Edit the .env using the template .env.sample.

PORT=5000                       # API PORT
SQLITE_PATH=./database.db       # Path to the SQLite database file
SECRET="Whatever-STRONG"        # Secret for sensitive data hashing 

# Same as for React APP
GITHUB_OAUTH_CLIENT_ID= ...     # Github OAuth secret 
GITHUB_OAUTH_CLIENT_SECRET= ... # Github OAuth secret

๐Ÿ‘‰ Step 5 - Start the API server (development mode)

$ npm run dev
// OR
$ yarn dev

๐Ÿ‘‰ Step 6 - Production Build (files generated in build directory)

$ yarn build

๐Ÿ‘‰ Step 7 - Start the API server for production (files served from build/index.js)

$ yarn start

The API server will start using the PORT specified in .env file (default 5000).


โœจ Codebase Structure

< ROOT / src >
     | 
     |-- config/                              
     |    |-- config.ts             # Configuration       
     |    |-- passport.ts           # Define Passport Strategy             
     | 
     |-- migration/
     |    |-- some_migration.ts     # database migrations
     |
     |-- models/                              
     |    |-- activeSession.ts      # Sessions Model (Typeorm)              
     |    |-- user.ts               # User Model (Typeorm) 
     | 
     |-- routes/                              
     |    |-- users.ts              # Define Users API Routes
     | 
     | 
     |-- index.js                   # API Entry Point
     |-- .env                       # Specify the ENV variables
     |                        
     |-- ************************************************************************

โœจ SQLite Path

The SQLite Path is set in .env, as SQLITE_PATH


โœจ Database migration

๐Ÿ‘‰ Generate migration:

$ yarn typeorm migration:generate -n your_migration_name

๐Ÿ‘‰ Run migration:

$ yarn typeorm migration:run

โœจ API

For a fast set up, use this POSTMAN file: api_sample

๐Ÿ‘‰ Register - api/users/register

POST api/users/register
Content-Type: application/json

{
    "username":"test",
    "password":"pass", 
    "email":"[email protected]"
}

๐Ÿ‘‰ Login - api/users/login

POST /api/users/login
Content-Type: application/json

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

๐Ÿ‘‰ Logout - api/users/logout

POST api/users/logout
Content-Type: application/json
authorization: JWT_TOKEN (returned by Login request)

{
    "token":"JWT_TOKEN"
}

โœจ Update role for existing user

๐Ÿ‘‰ Using npm:

$ npm run update-role [user_id] [role_id (optional)]


๐Ÿ‘‰ Using yarn:

$ yarn update-role [user_id] [role_id (optional)]

  • [user_id] is the id of existing user to update role for.
  • [role_id] is the id of role: 1 for admin & 2 for user. If you don't provide any role_id it would update user to admin role.

โœจ Run the Tests (minimal suite)

$ npm run test
// OR
$ yarn test

โœจ Credits

This software is provided by the core AppSeed team with an inspiration from other great NodeJS starters:



Node JS API Server - provided by AppSeed App Generator

nodejs-basic-api's People

Contributors

app-generator avatar fullstackkdev avatar natelindev avatar

Watchers

James Cloos 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.