https://github.com/app-generator/api-server-nodejs-mongo
Nodejs API Server - Express / SQLite / MongoDB | AppSeed
https://github.com/app-generator/api-server-nodejs-mongo
api-rest appseed appseed-sample nodejs typescript
Last synced: 7 months ago
JSON representation
Nodejs API Server - Express / SQLite / MongoDB | AppSeed
- Host: GitHub
- URL: https://github.com/app-generator/api-server-nodejs-mongo
- Owner: app-generator
- License: mit
- Created: 2021-07-20T13:46:03.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-12-02T15:47:49.000Z (almost 3 years ago)
- Last Synced: 2025-03-11T05:55:14.021Z (7 months ago)
- Topics: api-rest, appseed, appseed-sample, nodejs, typescript
- Language: TypeScript
- Homepage: https://appseed.us/boilerplate-code/nodejs-starter/
- Size: 80.1 KB
- Stars: 11
- Watchers: 2
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# [Nodejs API Server](https://appseed.us/boilerplate-code/nodejs-starter/) `Mongo`
Simple starter built with Typescrypt / Express / MongoDB and JWT Auth powered by **Passport** library - provided and actively supported by **AppSeed** [App Generator](https://appseed.us/app-generator). The authentication flow is based on [json web tokens](https://jwt.io) and `passport-jwt` strategy - Inspired by other great OSS starters mentioned in the [credits](#credits) section.
> Features:
- ✅ [API Definition](https://docs.appseed.us/boilerplate-code/api-unified-definition) - the unified API structure implemented by this server
- ✅ Simple, intuitive codebase - built for beginners (can be extended with ease)
- ✅ Node JS / Express / Typescript
- ✅ **Persistance**: `MongoDB`
- ✅ Auth: Passport / `passport-jwt` strategy
- ✅ `Docker`
> Can be used with other [React Starters](https://appseed.us/apps/react) for a complete **Full-Stack** experience:
| [React Node JS Berry](https://appseed.us/product/berry-dashboard/api-server-nodejs/react/) | [React Node Soft Dashboard](https://appseed.us/product/soft-ui-dashboard/api-server-nodejs/react/) | [React Node Horizon](https://appseed.us/product/horizon-ui/api-server-nodejs/) |
| --- | --- | --- |
| [](https://appseed.us/product/berry-dashboard/api-server-nodejs/react/) | [](https://appseed.us/product/soft-ui-dashboard/api-server-nodejs/react/) | [](https://appseed.us/product/horizon-ui/api-server-nodejs/)

## Requirements
- [Node.js](https://nodejs.org/) >= 10.x
- [MongoDB](https://www.mongodb.com/) server
## How to use the code
**Create** `.env` from `.env.sample`
Update the file with your data.
**Clone the sources**
```bash
$ git clone https://github.com/app-generator/api-server-nodejs-mongo.git
$ cd api-server-nodejs-mongo
```**Install dependencies** via NPM or Yarn
```bash
$ npm i
// OR
$ yarn
```**Start the API server** - development mode
```bash
$ npm dev
// OR
$ yarn dev
```**Start the API server** - for production (files served from `build/build/index.js`)
```bash
$ npm start
// OR
$ yarn start
```The API server will start using the `PORT` specified in `.env` file (default 5000)
## Codebase Structure
```bash
< ROOT / src >
|
|-- config/
| |-- config.ts # Configuration
| |-- passport.ts # Define Passport Strategy
|
|-- models/
| |-- activeSession.ts # Sessions Model (Mongo)
| |-- user.ts # User Model (Mongo)
|
|-- routes/
| |-- users.ts # Define Users API Routes
|
|
|-- index.js # API Entry Point
|-- .env # Specify the ENV variables
|
|-- ************************************************************************
```
## Mongo Settings
The Mongo URI lives in `config/keys.js`
```javascript
... = 'mongodb://localhost/api_server_nodejs'
```
## API
For a fast set up, use this POSTMAN file: [api_sample](https://github.com/app-generator/api-server-nodejs/blob/master/media/api.postman_collection.json)
> **Register** - `api/users/signup`
```
POST api/users/signup
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"
}
```
## License
MIT @ [AppSeed](https://appseed.us)
## Credits
This software is provided by the core AppSeed team with an inspiration from other great NodeJS starters:
- Initial verison - coded by [Teo Deleanu](https://www.linkedin.com/in/teodeleanu/)
- [Hackathon Starter](https://github.com/sahat/hackathon-starter) - A truly amazing boilerplate for Node.js apps
- [Node Server Boilerplate](https://github.com/hagopj13/node-express-boilerplate) - just another cool starter
- [React NodeJS Argon](https://github.com/creativetimofficial/argon-dashboard-react-nodejs) - released by **Creative-Tim** and [ProjectData](https://projectdata.dev/)
---
[Nodejs API Server](https://appseed.us/boilerplate-code/nodejs-starter/) `Mongo` - provided by AppSeed [App Generator](https://appseed.us)