1.0.0 • Published 4 years ago
satyaminfo_node_crud_mysqli v1.0.0
satyaminfo crun in node.js useing mysql!
This package is used to create CRUD operation in node js, this package is easy to use and operate also you can modify table or fields as per your requirement using the following step
Install
# with npm
npm install node_crud_mysql
# with npm
npm install express mysql dotenv sequelize
Usage
Create a .env
file in the root directory of your project. Add
environment-specific variables on new lines in the form of NAME=VALUE
.
For example:
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=s1mpl3
DB_NAME=demo_db
Create a config/config.js
file in the root directory of your project.
Your config.js
file like this
const mysql=require('mysql');
const dotenv=require('dotenv').config();
var con={
host: process.env.DB_HOST,
user:process.env.DB_USER,
password:process.env.DB_PASSWORD,
database: process.env.DB_NAME,
dialect: "mysql",
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
}
};
var db_con=mysql.createConnection({
host: process.env.DB_HOST,
user:process.env.DB_USER,
password:process.env.DB_PASSWORD,
database: process.env.DB_NAME
});
module.exports.con=con;
module.exports.db_con=db_con;
Create a crud_request/app.js
file in the root directory of your project.
Your app.js
file is like this
const {mysqlCrudNode}=require('satyaminfo_node_crud_mysqli');
const {db_con} = require('../config/config');
mysqlCrudNode({
table_name:'user',
table_fields:{
name:'STRING',
email:'STRING',
password:'TEXT',
phone:'INTEGER'
},
valid_fields:{
name:"required|min:2",
email:"email|required",
password:"required"
},con:db_con
});
$ node crud_request/app.js
Options
In this package 3 Options are there
- table_name here is your table name
- table_fields here is your table fields name list
- valid_fields here is your table fields multiple vaidation list / (default to false)
1.0.0
4 years ago