Skip to content

Commit 19eabff

Browse files
author
App Generator
committed
Release v1.0.0
Persistance migrated to SQLite3 / TypeORM
1 parent eaa01de commit 19eabff

25 files changed

+811
-1
lines changed

.env

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
NODE_ENV=DEV
2+
PORT=5000
3+
SQLITE_PATH=./database.db
4+
SECRET="SuperS3cret_4277m"

.eslintrc.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module.exports = {
2+
env: {
3+
es2021: true,
4+
node: true,
5+
},
6+
extends: ['airbnb-typescript/base', 'plugin:@typescript-eslint/recommended'],
7+
parser: '@typescript-eslint/parser',
8+
parserOptions: {
9+
ecmaVersion: 2018,
10+
sourceType: 'module',
11+
project: './tsconfig.json',
12+
},
13+
rules: {
14+
'@typescript-eslint/explicit-module-boundary-types': 'off',
15+
'no-param-reassign': 'off',
16+
'no-underscore-dangle': 'off',
17+
'consistent-return': 'off',
18+
'no-console': 'off',
19+
'import/prefer-default-export': 'off',
20+
'@typescript-eslint/no-non-null-assertion': 'off',
21+
'class-methods-use-this': 'off',
22+
'@typescript-eslint/naming-convention': 'off'
23+
},
24+
};

.gitattributes

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Declare files that will always have LF line endings on checkout.
2+
3+
*.html text eol=lf
4+
*.scss text eol=lf
5+
*.sass text eol=lf
6+
*.css text eol=lf
7+
*.js text eol=lf
8+
*.json text eol=lf
9+
*.svg text eol=lf
10+
*.yml text eol=lf
11+
*.yaml text eol=lf
12+
*.md text eol=lf
13+
14+
.babelrc text eol=lf
15+
.gitignore text eol=lf
16+
.gitattributes text eol=lf
17+
18+
LICENSE text eol=lf
19+
20+
# Denote all files that are truly binary and should not be modified.
21+
22+
*.png binary
23+
*.jpg binary
24+
*.jpeg binary
25+
*.gif binary
26+
*.bmp binary
27+
*.ai binary
28+
*.psd binary
29+
*.pdf binary
30+
31+
*.otf binary
32+
*.eot binary
33+
*.ttf binary
34+
*.woff binary
35+
*.woff2 binary
36+
*.zip binary
37+
*.rar binary

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
node_modules
2+
build
3+
4+
# Logs
5+
*.log
6+
npm-debug.log*
7+
yarn-debug.log*
8+
yarn-error.log*
9+
10+
*.db

.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v14

CHANGELOG.md

+16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
# Change Log
22

3+
## [v1.0.0] 2021-07-20
4+
### Stable release
5+
6+
- Persistance migrated to SQLite3 / TypeORM
7+
- Stack: Node JS/ Express / TypeORM / SQLite3
8+
- API:
9+
- Sign UP: `/api/users/register`
10+
- Sign IN: `/api/users/login`
11+
- Logout: `/api/users/logout`
12+
- Check Session: `/api/users/checkSession`
13+
- Edit User: `/api/users/edit`
14+
- Data persistence
15+
- TypeORM / SQLite3
16+
- Db migrations are in `src/migrations` folder
17+
- Added new config `ormconfig.json`
18+
319
## [0.0.9] 2021-07-19
420
### Production Update
521

LICENSE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ SOFTWARE.
2323
<br />
2424

2525
---
26-
For more information regarding licensing, please contact the AppSeed Service < *support@appseed.us* >
26+
For more information regarding licensing, please contact AppSeed < *support @ appseed.us* >

README.md

+191
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
2+
# Nodejs API Server
3+
4+
Express / Nodejs Starter with JWT authentication, and **SQLite** persistance - Provided by **AppSeed** [App Generator](https://appseed.us/app-generator).
5+
Authentication Flow uses [json web tokens](https://jwt.io) via Passport library - `passport-jwt` startegy.
6+
7+
<br />
8+
9+
> Features:
10+
11+
- Simple, intuitive codebase - can be extended with ease.
12+
- Typescript
13+
- **Stack**: NodeJS / Express / SQLite / TypeORM
14+
- Auth: Passport / `passport-jwt` strategy
15+
- [API Interface Descriptor](https://github.com/app-generator/api-server-nodejs/blob/master/media/api.postman_collection.json): POSTMAN Collection
16+
17+
<br />
18+
19+
> Support:
20+
21+
- Github (issues tracker), Email: **support @ appseed.us**
22+
- **Discord**: [LIVE Support](https://discord.gg/fZC6hup) (registered AppSeed Users)
23+
24+
<br />
25+
26+
![Nodejs API Server - Open-source Nodejs Starter provided by AppSeed.](https://user-images.githubusercontent.com/51070104/124414813-142aa180-dd5c-11eb-9279-6b082dadc51a.png)
27+
28+
<br />
29+
30+
## Requirements
31+
32+
- [Node.js](https://nodejs.org/) >= 12.x
33+
- [SQLite](https://www.sqlite.org/index.html)
34+
35+
<br />
36+
37+
## How to use the code
38+
39+
**Clone the sources**
40+
41+
```bash
42+
$ git clone https://github.com/app-generator/api-server-nodejs.git
43+
$ cd api-server-nodejs
44+
```
45+
46+
**Install dependencies** via NPM or Yarn
47+
48+
```bash
49+
$ npm i
50+
// OR
51+
$ yarn
52+
```
53+
54+
**Run the SQLite migration**
55+
56+
```
57+
$ yarn typeorm migration:run
58+
```
59+
60+
**Start the API server** - development mode
61+
62+
```bash
63+
$ npm dev
64+
// OR
65+
$ yarn dev
66+
```
67+
68+
**Production Build** - files generated in `build` directory
69+
70+
```bash
71+
$ npm build
72+
// OR
73+
$ yarn build
74+
```
75+
76+
**Start the API server** - for production (files served from `build/index.js`)
77+
78+
```bash
79+
$ npm start
80+
// OR
81+
$ yarn start
82+
```
83+
84+
The API server will start using the `PORT` specified in `.env` file (default 5000)
85+
86+
<br />
87+
88+
## Codebase Structure
89+
90+
```bash
91+
< ROOT / src >
92+
|
93+
|-- config/
94+
| |-- config.ts # Configuration
95+
| |-- passport.ts # Define Passport Strategy
96+
|
97+
|-- migration/
98+
| |-- some_migration.ts # database migrations
99+
|
100+
|-- models/
101+
| |-- activeSession.ts # Sessions Model (Typeorm)
102+
| |-- user.ts # User Model (Typeorm)
103+
|
104+
|-- routes/
105+
| |-- users.ts # Define Users API Routes
106+
|
107+
|
108+
|-- index.js # API Entry Point
109+
|-- .env # Specify the ENV variables
110+
|
111+
|-- ************************************************************************
112+
```
113+
114+
<br />
115+
116+
## SQLite Path
117+
118+
The SQLite Path is set in `.env`, as `SQLITE_PATH`
119+
120+
## Database migration
121+
122+
##### generate migration:
123+
124+
yarn typeorm migration:generate -n your_migration_name
125+
126+
##### run migration:
127+
128+
yarn typeorm migration:run
129+
130+
<br />
131+
132+
## API
133+
134+
For a fast set up, use this POSTMAN file: [api_sample](https://github.com/app-generator/api-server-nodejs-pro/blob/master/media/api.postman_collection.json)
135+
136+
> **Register** - `api/users/register`
137+
138+
```
139+
POST api/users/register
140+
Content-Type: application/json
141+
142+
{
143+
"username":"test",
144+
"password":"pass",
145+
146+
}
147+
```
148+
149+
<br />
150+
151+
> **Login** - `api/users/login`
152+
153+
```
154+
POST /api/users/login
155+
Content-Type: application/json
156+
157+
{
158+
"password":"pass",
159+
160+
}
161+
```
162+
163+
<br />
164+
165+
> **Logout** - `api/users/logout`
166+
167+
```
168+
POST api/users/logout
169+
Content-Type: application/json
170+
authorization: JWT_TOKEN (returned by Login request)
171+
172+
{
173+
"token":"JWT_TOKEN"
174+
}
175+
```
176+
177+
<br />
178+
179+
## Credits
180+
181+
This software is provided by the core AppSeed team with an inspiration from other great NodeJS starters:
182+
183+
- Initial verison - coded by [Teo Deleanu](https://www.linkedin.com/in/teodeleanu/)
184+
- [Hackathon Starter](https://github.com/sahat/hackathon-starter) - A truly amazing boilerplate for Node.js apps
185+
- [Node Server Boilerplate](https://github.com/hagopj13/node-express-boilerplate) - just another cool starter
186+
- [React NodeJS Argon](https://github.com/creativetimofficial/argon-dashboard-react-nodejs) - released by **Creative-Tim** and [ProjectData](https://projectdata.dev/)
187+
188+
<br />
189+
190+
---
191+
Nodejs API Server - provided by AppSeed [App Generator](https://appseed.us)

jest.config.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
transform: {
3+
'^.+\\.ts?$': 'ts-jest',
4+
},
5+
setupFiles: ['dotenv/config'],
6+
testEnvironment: 'node',
7+
coveragePathIgnorePatterns: ['node_modules'],
8+
coverageReporters: ['text', 'lcov', 'clover', 'html'],
9+
};

ormconfig.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[
2+
{
3+
"name": "default",
4+
"type": "sqlite",
5+
"database": "./database.db",
6+
"autoSchemaSync": true,
7+
"entities": [
8+
"src/models/**/*{.js,.ts}"
9+
],
10+
"migrations": ["src/migrations/**/*{.js,.ts}"],
11+
"cli": {
12+
"migrationsDir": "src/migrations/"
13+
}
14+
}
15+
]

package.json

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"name": "api-server-nodejs",
3+
"version": "1.0.0",
4+
"description": "RESTful back-end for Node.js and Express.js",
5+
"license": "Commercial",
6+
"author": "AppSeed.us",
7+
"main": "src/index",
8+
"scripts": {
9+
"start": "pm2 start production.config.json",
10+
"start-no-daemon": "pm2 start production.config.json --no-daemon",
11+
"start-node": "node build/index.js",
12+
"dev": "ts-node-dev src/index.ts",
13+
"test": "jest -i --colors --verbose --detectOpenHandles",
14+
"lint": "eslint src --ext .ts",
15+
"build": "tsc -p tsconfig.build.json",
16+
"typecheck": "tsc --noEmit",
17+
"typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js"
18+
},
19+
"dependencies": {
20+
"bcrypt": "5.0.1",
21+
"compression": "^1.7.4",
22+
"cors": "^2.8.5",
23+
"cross-env": "^7.0.3",
24+
"dotenv": "^10.0.0",
25+
"express": "^4.17.1",
26+
"express-passport-logout": "^0.1.0",
27+
"joi": "^17.4.1",
28+
"jsonwebtoken": "^8.5.1",
29+
"passport": "^0.4.1",
30+
"passport-jwt": "^4.0.0",
31+
"sqlite3": "5.0.2",
32+
"pm2": "^5.1.0",
33+
"typeorm": "0.2.34"
34+
},
35+
"devDependencies": {
36+
"@types/bcrypt": "5.0.0",
37+
"@types/compression": "^1.7.1",
38+
"@types/cors": "^2.8.11",
39+
"@types/express": "^4.17.13",
40+
"@types/jest": "^26.0.24",
41+
"@types/node": "^16.3.3",
42+
"@types/passport-jwt": "^3.0.6",
43+
"@types/sqlite3": "3.1.7",
44+
"@types/supertest": "^2.0.11",
45+
"@typescript-eslint/eslint-plugin": "^4.28.3",
46+
"@typescript-eslint/parser": "^4.28.3",
47+
"eslint": "^7.31.0",
48+
"eslint-config-airbnb-typescript": "^12.3.1",
49+
"eslint-plugin-import": "^2.23.4",
50+
"jest": "^27.0.6",
51+
"supertest": "^6.1.3",
52+
"ts-jest": "^27.0.3",
53+
"ts-node": "10.1.0",
54+
"ts-node-dev": "1.1.8",
55+
"typescript": "^4.3.5"
56+
}
57+
}

0 commit comments

Comments
 (0)