|
| 1 | + |
| 2 | +# Nodejs API Server (Mongo) |
| 3 | + |
| 4 | +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. |
| 5 | + |
| 6 | +<br /> |
| 7 | + |
| 8 | +> Features: |
| 9 | +
|
| 10 | +- Simple, intuitive codebase - built for beginners (can be extended with ease) |
| 11 | +- Node JS / Express / MongoDB |
| 12 | +- Typescript |
| 13 | +- Auth: Passport / `passport-jwt` strategy |
| 14 | +- [API Interface Descriptor](https://github.com/app-generator/api-server-nodejs/blob/master/media/api.postman_collection.json): POSTMAN Collection |
| 15 | +- Docker |
| 16 | +- Full-stack Samples that uses this backend |
| 17 | + - [React Node JS Datta](https://appseed.us/product/react-node-js-datta-able) - open-source full-stack sample |
| 18 | + - [React Node JS Berry](https://appseed.us/product/react-node-js-berry-dashboard) - open-source full-stack sample |
| 19 | + |
| 20 | +<br /> |
| 21 | + |
| 22 | +> Support: |
| 23 | +
|
| 24 | +- Github (issues tracker), Email: **support @ appseed.us** |
| 25 | +- **Discord**: [LIVE Support](https://discord.gg/fZC6hup) (registered AppSeed Users) |
| 26 | + |
| 27 | +<br /> |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | +<br /> |
| 32 | + |
| 33 | +## Requirements |
| 34 | + |
| 35 | +- [Node.js](https://nodejs.org/) >= 10.x |
| 36 | +- [MongoDB](https://www.mongodb.com/) server |
| 37 | + |
| 38 | +<br /> |
| 39 | + |
| 40 | +## How to use the code |
| 41 | + |
| 42 | +**Clone the sources** |
| 43 | + |
| 44 | +```bash |
| 45 | +$ git clone https://github.com/app-generator/api-server-nodejs-mongo.git |
| 46 | +$ cd api-server-nodejs-mongo |
| 47 | +``` |
| 48 | + |
| 49 | +**Install dependencies** via NPM or Yarn |
| 50 | + |
| 51 | +```bash |
| 52 | +$ npm i |
| 53 | +// OR |
| 54 | +$ yarn |
| 55 | +``` |
| 56 | + |
| 57 | +**Start the API server** - development mode |
| 58 | + |
| 59 | +```bash |
| 60 | +$ npm dev |
| 61 | +// OR |
| 62 | +$ yarn dev |
| 63 | +``` |
| 64 | + |
| 65 | +**Start the API server** - for production (files served from `build/build/index.js`) |
| 66 | + |
| 67 | +```bash |
| 68 | +$ npm start |
| 69 | +// OR |
| 70 | +$ yarn start |
| 71 | +``` |
| 72 | + |
| 73 | +The API server will start using the `PORT` specified in `.env` file (default 5000) |
| 74 | + |
| 75 | +<br /> |
| 76 | + |
| 77 | +## Codebase Structure |
| 78 | + |
| 79 | +```bash |
| 80 | +< ROOT / src > |
| 81 | + | |
| 82 | + |-- config/ |
| 83 | + | |-- config.ts # Configuration |
| 84 | + | |-- passport.ts # Define Passport Strategy |
| 85 | + | |
| 86 | + |-- models/ |
| 87 | + | |-- activeSession.ts # Sessions Model (Mongo) |
| 88 | + | |-- user.ts # User Model (Mongo) |
| 89 | + | |
| 90 | + |-- routes/ |
| 91 | + | |-- users.ts # Define Users API Routes |
| 92 | + | |
| 93 | + | |
| 94 | + |-- index.js # API Entry Point |
| 95 | + |-- .env # Specify the ENV variables |
| 96 | + | |
| 97 | + |-- ************************************************************************ |
| 98 | +``` |
| 99 | + |
| 100 | +<br /> |
| 101 | + |
| 102 | +## Mongo Settings |
| 103 | + |
| 104 | +The Mongo URI lives in `config/keys.js` |
| 105 | + |
| 106 | +```javascript |
| 107 | +... = 'mongodb://localhost/api_server_nodejs' |
| 108 | +``` |
| 109 | + |
| 110 | +<br /> |
| 111 | + |
| 112 | +## API |
| 113 | + |
| 114 | +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) |
| 115 | + |
| 116 | +> **Register** - `api/users/signup` |
| 117 | +
|
| 118 | +``` |
| 119 | +POST api/users/signup |
| 120 | +Content-Type: application/json |
| 121 | +
|
| 122 | +{ |
| 123 | + "username":"test", |
| 124 | + "password":"pass", |
| 125 | + "email":"test@appseed.us" |
| 126 | +} |
| 127 | +``` |
| 128 | + |
| 129 | +<br /> |
| 130 | + |
| 131 | +> **Login** - `api/users/login` |
| 132 | +
|
| 133 | +``` |
| 134 | +POST /api/users/login |
| 135 | +Content-Type: application/json |
| 136 | +
|
| 137 | +{ |
| 138 | + "password":"pass", |
| 139 | + "email":"test@appseed.us" |
| 140 | +} |
| 141 | +``` |
| 142 | + |
| 143 | +<br /> |
| 144 | + |
| 145 | +> **Logout** - `api/users/logout` |
| 146 | +
|
| 147 | +``` |
| 148 | +POST api/users/logout |
| 149 | +Content-Type: application/json |
| 150 | +authorization: JWT_TOKEN (returned by Login request) |
| 151 | +
|
| 152 | +{ |
| 153 | + "token":"JWT_TOKEN" |
| 154 | +} |
| 155 | +``` |
| 156 | + |
| 157 | +<br /> |
| 158 | + |
| 159 | +## License |
| 160 | + |
| 161 | +MIT @ [AppSeed](https://appseed.us) |
| 162 | + |
| 163 | +<br /> |
| 164 | + |
| 165 | +## Credits |
| 166 | + |
| 167 | +This software is provided by the core AppSeed team with an inspiration from other great NodeJS starters: |
| 168 | + |
| 169 | +- Initial verison - coded by [Teo Deleanu](https://www.linkedin.com/in/teodeleanu/) |
| 170 | +- [Hackathon Starter](https://github.com/sahat/hackathon-starter) - A truly amazing boilerplate for Node.js apps |
| 171 | +- [Node Server Boilerplate](https://github.com/hagopj13/node-express-boilerplate) - just another cool starter |
| 172 | +- [React NodeJS Argon](https://github.com/creativetimofficial/argon-dashboard-react-nodejs) - released by **Creative-Tim** and [ProjectData](https://projectdata.dev/) |
| 173 | + |
| 174 | +<br /> |
| 175 | + |
| 176 | +--- |
| 177 | +[Nodejs Starter](https://appseed.us/boilerplate-code/nodejs-starter) - provided by AppSeed [App Generator](https://appseed.us) |
0 commit comments