Skip to content

app-generator/api-server-nodejs-demo

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Nodejs API Server

Express / Nodejs Starter with JWT authentication, and SQLite persistance - Provided by AppSeed App Generator. Authentication Flow uses json web tokens via Passport library - passport-jwt strategy.



👉 Learn how to deploy this product LIVE on Render using the Python Deployer (free tool)



Features:

  • API Definition - the unified API structure implemented by this server
  • ✅ Simple, intuitive codebase - can be extended with ease.
  • TypeScript, Joy for validation
  • Stack: NodeJS / Express / SQLite / TypeORM
  • ✅ Auth: Passport / passport-jwt strategy

Tested with:

NodeJS NPM YARN
v18.0.0
v17.0.0
v16.13.0
v16.0.0

Can be used with other React Starters for a complete Full-Stack experience:

React Node JS Berry React Node Soft Dashboard React Node Horizon
React Node JS Berry React Node Soft Dashboard React Node Horizon

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

$ yarn

Step 3 - Run the SQLite migration via TypeORM

$ yarn typeorm migration:run

Step 4 - Start the API server (development mode)

$ yarn dev

Step 5 - Production Build (files generated in build directory)

$ yarn build

Step 6 - 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":"test@appseed.us"
}

Login - api/users/login

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

{
    "password":"pass", 
    "email":"test@appseed.us"
}

Logout - api/users/logout

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

{
    "token":"JWT_TOKEN"
}

✨ Run the Tests

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

About

Nodejs API & React - Deploy LIVE on Render | AppSeed

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published