This project is an express server template that is a good solution for production environments that need users' authentication.
- Registration/Login. There are four types of authentication methods implemented:
- With email: uses the email-verification library.
- Facebook: passport-facebook.
- Google: passport-google.
- Twitter: passport-twitter.
Note that Facebook, Google and Twitter registration/login processes uses passport.
- Authentication: JSON Web Token.
- Data validation: all the database collections have their corresponding mongoose schema in a models module.
- Good code styling: eslint and eslint-plugin-node are included.
- Changelog: automatic features and bugfixes tracking in a changelog file.
This server has a great folders structure. Tree command output tree -d
:
.
├── src
│ ├── config
│ ├── routes
│ └── models
└── test
- config: contains 3 JSONs to differenciate the different environments: dev (development), stg (staging) and pro (production).
- routes: have all the routes splitted in different files by functionality (users, authentication, socialNetworksAuth, ...).
- models: exports a factory containing all the models of the application.
- Clone repository
git clone https://github.com/NachoJusticia/express-restful-api-template
cd express-restful-api-template
- Install dependencies
npm install
- Set up the configuration requred
- Social networks authentication: you will need to create a developer account in Facebook, Google and Twitter respectively.
- Node-email-verification: it is required to add a valid email and password to use the SMTP service (Remember not to upload sensitive information to github).
Note that you have to provide all the required environment variables: BASE_URL, DB_URL, JWT_TOKEN, NEV_EMAIL, NEV_PASSWORD, NODE_ENV, PORT.
- Server launching options:
- In a production and staging environment.
npm run start
- Development environment: restart server when modifying any file and save.
npm run start-dev
- Development environment: debuggin. After using the following command attach to the proces in the port 9229 for being able to inspect the code.
npm run start--dev-debug
Ignacio Justicia Ramos
: ignaciojusticia@gmail.com
Contributions are welcome, please fork this repository and send Pull Requests! If you have any ideas on how to make this project better then please submit an issue.