0% found this document useful (0 votes)
10 views2 pages

Express App for MySQL Employee CRUD

This document contains a Node.js application using Express and MySQL to manage employee data. It defines two endpoints: a GET request to retrieve all employees and a POST request to add a new employee. The application listens on port 9999 and uses middleware to parse JSON request bodies.

Uploaded by

not.rajdeep22
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Express App for MySQL Employee CRUD

This document contains a Node.js application using Express and MySQL to manage employee data. It defines two endpoints: a GET request to retrieve all employees and a POST request to add a new employee. The application listens on port 9999 and uses middleware to parse JSON request bodies.

Uploaded by

not.rajdeep22
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

const express = require('express');

const mysql = require('mysql');

const app = express();

const connectionString = {
host: "localhost",
port: 3306,
database: "sameerdb",
user: "root",
password: "manager"
};

//This is middleware function which will get request stream into [Link]
[Link]([Link]());

[Link]("/emps", (request, response)=>{


var connection = [Link](connectionString);

[Link]();

let queryText = `select * from Emp`;

[Link](queryText, (err, result)=>{


[Link]("Content-Type", "application/json");
if(err==null)
{
[Link]([Link](result));
[Link]();
[Link]();
}
else
{
[Link]([Link](err));
[Link]();
[Link]();
}
});
})

[Link]("/emps", (request, response)=>{


var No = [Link];
var Name = [Link];
var Address = [Link];

var connection = [Link](connectionString);


[Link]();

let queryText =
`insert into Emp values(${No},'${Name}','${Address}')`;

[Link](queryText);
[Link](queryText, (err, result)=>{
[Link]("Content-Type", "application/json");
if(err==null)
{
[Link]([Link](result));
[Link]();
[Link]();
}
else
{
[Link]([Link](err));
[Link]();
[Link]();
}
});
})

[Link](9999, ()=>{[Link]("server started ...")})

You might also like