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.
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 | Status |
---|---|---|---|
v16.13.0 |
v8.1.0 |
v1.22.5 |
✔️ |
v14.15.0 |
v6.14.8 |
v1.22.5 |
✔️ |
v12.22.0 |
v6.14.11 |
v1.22.5 |
✔️ |
Can be used with other React Starters for a complete Full-Stack experience:
React Node JS Berry | React Node Soft Dashboard | React Node Datta Able |
---|---|---|
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 NPM or Yarn
$ npm i
// OR
$ yarn
Step 3 - Run the SQLite migration via TypeORM
$ yarn typeorm migration:run
Step 4 - Start the API server (development mode)
$ npm run dev
// OR
$ yarn dev
Step 5 - Production Build (files generated in
build
directory)
$ npm run build
// OR
$ yarn build
Step 6 - Start the API server for production (files served from
build/index.js
)
$ npm run start
// OR
$ yarn start
The API server will start using the PORT
specified in .env
file (default 5000).
< 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
|
|-- ************************************************************************
The SQLite Path is set in .env
, as SQLITE_PATH
Generate migration:
$ yarn typeorm migration:generate -n your_migration_name
run migration:
$ yarn typeorm migration:run
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"
}
yarn test
This software is provided by the core AppSeed team with an inspiration from other great NodeJS starters:
- Initial verison - coded by Teo Deleanu
- Hackathon Starter - A truly amazing boilerplate for Node.js apps
- Node Server Boilerplate - just another cool starter
- React NodeJS Argon - released by Creative-Tim and ProjectData
Node JS API Server - provided by AppSeed App Generator