- Getting Started
- Create new Student API using MongoDB
- Create new Student API using SqlServer
- All Commands
- Configuration
-
Clone the repo in your working directory
-
Run service with development environment
yarn start
We will follow the instructions by adding a Student registartion API which will connect to mongodb
-
Create mongodb collection model under
api\modelsfolder -
Import model created in
step(1)inapi\models\index -
Add new validator file under
api\validators\student.validators.jsto implement request validation usingJoia. Export a method named as
validateRegisterStudent -
Add new controller under
api\controllersfolder with file name asstudent.controller.jsa. Export a method named as
registerStudentb. Before processing request, validate request object by importing validator method created in
step (3)c. If valid request, process request with required logic
-
Define API route path for new method under
api\app.constants.jsas belowexports.studentController = { routeName: '/students', routeMethods: { registerStudentRoute: '/registerStudent', }, }; -
Create new route file under
api\routes\student.route.js. Attach route path(defined instep-5) and controller method(defined instep-4) as belowimport express from 'express';import studentCtrl from '../controllers/student.controller';import appConstants from '../app.constants';const router = express.Router();router.route(appConstants.studentController.routeMethods.registerStudentRoute).post(studentCtrl.registerStudent); -
Import route file(defined in
step-6) inapi\routes\index.route.jsfile and attach routeimport studentRoutes from './student.route';router.use(appConstants.studentController.routeName, studentRoutes);
We will follow the instructions by adding a Student registartion API which will connect to mongodb
-
Add new
student.dal.jsfile underapi\dalfoldera. Export a method named as
registerStudent -
Add new validator file under
api\validators\student.validators.jsto implement request validation usingJoia. Export a method named as
validateRegisterStudent -
Add new controller under
api\controllersfolder with file name asstudent.controller.jsa. Export a method named as
registerStudentb. Before processing request, validate request object by importing validator method created in
step (3)c. If valid request, process request with required logic by consuming method created in
step-1 -
Define API route path for new method under
api\app.constants.jsas belowexports.studentController = { routeName: '/students', routeMethods: { registerStudentRoute: '/registerStudent', }, }; -
Create new route file under
api\routes\student.route.js. Attach route path(defined instep-5) and controller method(defined instep-4) as belowimport express from 'express';import studentCtrl from '../controllers/student.controller';import appConstants from '../app.constants';const router = express.Router();router.route(appConstants.studentController.routeMethods.registerStudentRoute).post(studentCtrl.registerStudent); -
Import route file(defined in
step-6) inapi\routes\index.route.jsfile and attach routeimport studentRoutes from './student.route';router.use(appConstants.studentController.routeName, studentRoutes);
- Start service in development environment
yarn run start
- Transpile service from ES6 to ES5 for devQA Or prodQA or prodRelease environments
yarn run build
- Start/Stop service in
devQAenvironment. Naviagate todistfolder created in step (2) and execute below commands to start/stop serviceyarn run startdevqa yarn run stopdevqa
- Start/Stop service in
prodQAenvironment Naviagate todistfolder created in step (2) and execute below commands to start/stop serviceyarn run startprodqa yarn run stopprodqa
- Start/Stop service in
prodReleaseenvironment Naviagate todistfolder created in step (2) and execute below commands to start/stop serviceyarn run startprodrelease yarn run stopprodrelease
- Get outdated packages information
yarn run getoutdatedpackages
- There is different configuration file for every environment which can be found under
configfolder. - Below attributes can be configured in every
configfile- port - In which port we are interested to start service
- secureCommunication - Whether to use SSL for service or not
- mongoConnectionString - MongoDB connection string
- sqlConnectionString - SQL Server connection string