A RESTful API generated by generator-rest.
See the API's documentation.
Then, you can use yo
to generate your project.
yo rest # generate a new project
yo rest:api # generate a new api endpoint inside your project
After you generate your project, these commands are available in package.json
.
npm test # test using Jest
npm run test:unit # run unit tests
npm run test:integration # run integration tests
npm run coverage # test and open the coverage report in the browser
npm run lint # lint using ESLint
npm run dev # run the API in development mode
npm run prod # run the API in production mode
npm run docs # generate API docs
Here is an example on how to deploy to Heroku using Heroku CLI:
# start a new local git repository
git init
# create a new heroku app
heroku apps:create my-new-app
# add heroku remote reference to the local repository
heroku git:remote --app my-new-app
# add the MongoLab addon to the heroku app
heroku addons:create mongolab
# set the environment variables to the heroku app (see the .env file in root directory)
heroku config:set MASTER_KEY=masterKey JWT_SECRET=jwtSecret
# commit and push the files
git add -A
git commit -m "Initial commit"
git push heroku master
# open the deployed app in the browser
heroku open
The second time you deploy, you just need to:
git add -A
git commit -m "Update code"
git push heroku master
You can customize the src
and api
directories.
src/
├─ api/
│ ├─ user/
│ │ ├─ controller.js
│ │ ├─ index.js
│ │ ├─ index.test.js
│ │ ├─ model.js
│ │ └─ model.test.js
│ └─ index.js
│
├─ assets/
│ ├─ css/
│ ├─ fonts/
│ ├─ img/
│ ├─ js/
│
├─ html/
│
├─ services/
│ ├─ express/
│ ├─ facebook/
│ ├─ mongoose/
│ ├─ passport/
│ ├─ sendgrid/
│ └─ your-service/
│
│
├─ app.js
├─ config.js
└─ index.js
Here is the execution of the AWS S3 code, and also you should write here your events with socket (Example at line 50).
Here is your mailing configuration, at line 29, then replace your DATABASE name at lines 43, 51 and 61.
If you wanna create views from server side, you have to put your view here, JUST THE HTML, if you are going to use a front end framework as VueJS, ReactJS or AngularJS (Just inlife compiled) you should implement it at src/assets
Here is where the API endpoints are defined. Each API has its own folder.
It defines the Mongoose schema and model for the API endpoint. Any changes to the data model should be done here.
This is the API controller file. It defines the main router middlewares which use the API model.
This is the entry file of the API. It defines the routes using, along other middlewares (like session, validation etc.), the middlewares defined in the some-endpoint.controller.js
file.
Here you can put helpers
, libraries
and other types of modules which you want to use in your APIs.
Put your whole list of variables here in a file with name .env<