Posts

Showing posts with the label Sequelize

NodeJS Standard Way to Write Models with Sequelize

Image
As we all know in our node js project there is one main file which is generally index.js or app.js . so if we put all code related to models file load so that is not an standard way of coding so for solving this problem we can create model directory , inside this directory we can create one index.js file in which we load all the models then call in models/index.js file in our main file.  Node JS Here is our app.js file: "use strict" require ( 'dotenv' ). config (); //for calling process.env.VAR_NAME globally const server = require ( './config/server' ), express = require ( 'express' ), app = express (), port = server . port ; require ( './src/models' ); // all routing app . get ( '/' , ( req , res ) => { res . send ( server . appName ) }) app . use ( '/api' , require ( './src/routes/index' )); //listen server on mentioned port app . listen ( port , "0.0.0.0" , () => { console . log ( ` ...