Awesome
Node.JS - Scaffolding API
Hello, and welcome! This Node.JS sample application that demonstrates an architecture for building a complete production API with Node.JS, Express.JS and MongoDB It features an architectural demonstration of these features:
- Built with Node.js and Express
- REST API with authentication scheme
Express Router and Routes
Route | HTTP Verb | Route Middleware | Description |
---|---|---|---|
/api/users | GET | Get list of users | |
/api/users | POST | Creates a new user | |
/api/users/:id | GET | isAuthenticated | Get a single user |
/api/users/:id | DELETE | hasRole('admin') | Deletes a user, restriction: 'admin' |
/api/users/me | GET | isAuthenticated | Get my info |
/api/users:id/password | PUT | isAuthenticated | Change a users password |
Usage
Basic example Create USER /api/users
:
Request Body:
{
"name": "CRISTIAN MORENO",
"email": "khriztianmoreno@myemail.com",
"password": "my-secret-password"
}
Response:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1OWFiNzkyMWQ1Yzk3NjJlZGQzZmUwZDgiLCJpYXQiOjE1MDQ0MDk4ODksImV4cCI6MTUwNDQyNzg4OX0.2gZPXZ-dQc3kQ1fcIDryHm4gIqWLvcw6guAOnP0ueGU"
}
Getting Started
Prerequisites
- Git
- Node.js and npm Node >= 4.x.x, npm >= 2.x.x
- MongoDB - Keep a running daemon with
mongod
Developing
-
Run
npm install
to install server dependencies. -
Run
mongod
in a separate shell to keep an instance of the MongoDB Daemon running -
Run
npm run dev
to start the development server. It should automatically open the client in your browser when ready. -
Open browser
http://localhost:3030/api/helloworld
.
Contributors
Thanks goes to these wonderful people (emoji key):
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --><img src="https://avatars1.githubusercontent.com/u/1481964?v=4" width="100px;"/><br /><sub>Khriztian Moreno</sub><br />💻 📖 💡 |
---|
This project follows the all-contributors specification. Contributions of any kind welcome!