├── .gitignore ├── package.json └── app.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mysqlnode", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "nodemon app.js", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "express": "^4.17.1", 14 | "morgan": "^1.10.0", 15 | "mysql": "^2.18.1", 16 | "nodemon": "^2.0.4" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | //load app server 2 | const express=require('express'); 3 | const app=express(); 4 | const morgan=require('morgan'); 5 | // app.use(morgan('combined')); 6 | const mysql=require('mysql'); 7 | 8 | //connection 9 | const db=mysql.createConnection({ 10 | host:"localhost", 11 | user :'root', 12 | port: '3306', 13 | password:'Devil@123', 14 | database :'nodesql', 15 | insecureAuth: true, 16 | }); 17 | //create 18 | 19 | app.get('/employee', (req, res) => { 20 | db.connect(function (err){ 21 | if(err) throw err; 22 | console.log("DB CONNECTed"); 23 | }); 24 | // var sql = `CREATE TABLE Employees(EmpId int AUTO_INCREMENT, EmpName VARCHAR(100), DOB datetime, Mobile VARCHAR(10), Email VARCHAR(100), PRIMARY KEY(EmpId))`; 25 | // db.query(sql, (err, result) => { 26 | // if (err) throw err; 27 | // console.log(result); 28 | // res.send('Employees table created...'); 29 | // }); 30 | }); 31 | 32 | 33 | 34 | 35 | //ping local server at 300 36 | app.listen(3000,()=>{ 37 | console.log('Server is set at port 3000'); 38 | }); --------------------------------------------------------------------------------