Hi! I'm Daniel Avellaneda, I'm an open source enthusiast and devote my free time to building projects in this field.
These projects are a "starter web app kit" for any developer who wants to build their own app without starting from scratch: API + Frontend
Both projects have been downloaded thousands of times by web developers around the world.
I'm doing my best to provide you a good experience when using my apps, so if you like what I'm doing and wish to say "thanks!", please buy me a coffee ☕️
Feel free to send me a tweet https://twitter.com/davellanedam, share this with others or make a pull request
cf-ipcountrythat CloudFlare creates when protecting your website).
Authorizationheader with value
yourTokenis the signed and encrypted token given in the response from the login process.
A demo of this API is located at: https://api-demo.daniel-avellaneda.com
IMPORTANT: Database resets every 30 mins like "12:00am, 12:30am, 1:00am" and so on. So anything you do with the API will be lost after a short time.
Demo is also linked to a VueJS project that shows how this API can be integrated to a frontend that is able to consume an API.
Repo is here: https://awesomeopensource.com/project/davellanedam/vue-skeleton-mvp
Running demo is here: https://vue-demo.daniel-avellaneda.com
git clone https://github.com/davellanedam/node-express-mongodb-jwt-rest-api-skeleton.git ./myproject
cd myproject npm install npm update
.envis already ignored, so you never commit your credentials.
.envto your environment server(development or production)
serveron your environment to the url of your server, for development mode use http://localhost:3000
IMPORTANT: By default token expires in 3 days (4320 minutes set in .env.example). You can refresh token at endpoint GET /token. If everything it´s ok you will get a new token.
To ensure the deliverability of emails sent by this API,
Mailgun is used for mailing users when they sign up, so if you want to use that feature go sign up at their website https://www.mailgun.com
If you want to try a different method it´s ok, I used https://nodemailer.com for this API and they have different transport methods like: smtp.
Language is automatically detected from
Accept-Language header on the request. So either you send locale manually on the request or your browser will send its default, if
Accept-Language header is not sent then it will use
en locale as default.
There are 3 available commands for this:
npm run command
freshcleans and then seeds the database with dynamic data.
cleancleans the database.
seedseeds the database with dynamic data.
npm run dev
You will know server is running by checking the output of the command
npm run dev
**************************** * Starting Server * Port: 3000 * NODE_ENV: development * Database: MongoDB * DB Connection: OK ****************************
It´s a good practice to do tests at your code, so a sample of how to do that in
mocha/chai is also included in the
npm run test
Format your code with prettier by typing:
npm run format
Format all your markdown files with remark by typing:
npm run remark
Lint your code with ESLint by typing:
npm run lint
Once everything is set up to test API routes either use Postman or any other api testing application. Default username/password combination for login is
You can import the example collection to Postman. To import, click the import button located and select
postman-example.json located within the root directory.
manage environments to create environments for development, production, etc. On each of the environments you create you will need to:
Create a new key
authToken and within the
/login request this value is automatically updated after a successfull login through a script located in the
tests tab. Each time you make a request to the API it will send
Authorization header with the
token value in the request, you can check this on the headers of users or cities endpoints in the Postman example.
Create a second key
server with the url of your server, for development mode use http://localhost:3000
This is a REST API, so it works using the following HTTP methods:
If you need to add more models to the project just create a new file in
/app/models/ and it will be loaded dynamically.
If you need to add more routes to the project just create a new file in
/app/routes/ and it will be loaded dynamically.
When you create a new controller, try to also create another folder with validations and helpers. Ex.
/countries/helpers. An example of this is included in the repository.
Feel free to report any bugs or improvements. Pull requests are always welcome.
This project is open-sourced software licensed under the MIT License. See the LICENSE file for more information.