node.js - How to access constant variable in controller in nodejs -


i have define constant variable in model file , try access constant variable @ time of inserting data table shows undefined. using sequlaize orm , nodejs. want define 3 value status active = 1, inactive = 2, deleted = 3, or there other solution define this. using sequelize orm 4+ version.

model code here  var sequalize = require('sequelize'); var sequalize = require('../../config/db_config');  const active = '1'; const inactive = '2'; const deleted = '3';  const user = sequalize.define('user',{     user_id_pk : {         type : sequelize.integer,         allownull : false,         primarykey : true,         autoincrement : true     },     user_type : sequelize.integer,     first_name : sequelize.string,     middle_name : sequelize.string,     last_name : sequelize.string,     password : sequelize.string,     email : sequelize.string,     mobile_no : sequelize.string,     is_email_verified : {         type:sequalize.integer,         defaultvalue : 0     },     gender : sequelize.string,     profile_image: sequelize.string,     dob : sequelize.date,     is_active : sequelize.string,     created_date : sequelize.date,     created_by : sequelize.integer,     updated_date : sequelize.date,     updated_by : sequelize.integer, },{     timestamps: false,     paranoid: true,     underscored: true,     freezetablename: true,     tablename: 'user',     createdat:'created_date',     updatedat:'updated_date' });  user.sync({force:false}).then(() => {     console.log('table created!');     }).catch(err => {     console.log('an error occur when table created!'); }); module.exports = user;  controller code here   usercontroller.saveuser = function(req,res){     console.log(user.active);return false;     user.findorcreate({         where:{             first_name: req.body.first_name,             email: req.body.email,             boltt_code: req.body.boltt_code         },         defaults:{             first_name: req.body.fihhrst_name,             middle_name : 'rajeev',             last_name : 'varshney',             email: req.body.email,             boltt_code: req.body.boltt_code,             is_active : '1',         }     })     .spread( function(user, created) {         var msg = '';         if(created){             msg = 'user inserted successfully!';         }else{             msg = 'user exist!';         }         res.status(200).send({error : false,message : msg2, data : user });     })     .catch((err) => {         console.log('oops wrong! ' + err);     }); }; 

if want use these variables in same file, have declare them , use it. if want access them file, have export variables:

const active = '1'; const inactive = '2'; const deleted = '3'; exports.active = active; exports.inactive = inactive; exports.deleted = deleted; 

now can make require of file , access variables.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -