Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //server.js
- // MEAN Stack RESTful API Tutorial - Contact List App
- var express = require('express');
- var app = express();
- var mysql = require('mysql');
- var bodyParser = require('body-parser');
- var DBconnectionString = {
- host: '107.170.169.80',
- user: 'david',
- password: 'david!102',
- database: 'NCD'
- };
- app.use(express.static(__dirname + '/public'));
- app.use(bodyParser.json());
- app.get('/degreelist', function(req, res){
- console.log('I received a GET request');
- var connection = mysql.createConnection(DBconnectionString);
- connection.connect();
- connection.query('SELECT DegreeID, Description FROM DEGREE WHERE DegreeID > 0', function (err, docs) {
- // console.log(docs);
- res.json(docs);
- });
- connection.end();
- });
- app.get('/degreelist/:id', function (req, res) {
- var id = req.params.id;
- var connection = mysql.createConnection(DBconnectionString);
- console.log(id);
- connection.connect();
- connection.query('SELECT * FROM UNIVERSE where DegreeID = ' + id, function (err, doc) {
- console.log(doc);
- res.json(doc);
- });
- connection.end();
- });
- // app.get('/contactlist', function (req, res) {
- // console.log('I received a GET request');
- // var connection = mysql.createConnection({
- // host: '107.170.169.80',
- // user: 'david',
- // password: 'david!102',
- // });
- // connection.connect;
- // connection.query('SELECT * FROM NCV.contactlist', function (err, docs) {
- // console.log(docs);
- // res.json(docs);
- // });
- // connection.end();
- // });
- // app.post('/contactlist', function (req, res) {
- // console.log(req.body);
- // var connection = mysql.createConnection({
- // host: '107.170.169.80',
- // user: 'david',
- // password: 'david!102',
- // });
- // connection.connect;
- // connection.query('Insert INTO NCV.contactlist SET ?', req.body , function (err, doc) {
- // res.json(doc);
- // });
- // connection.end();
- // });
- // app.delete('/contactlist/:id', function (req, res) {
- // var id = req.params.id;
- // var connection = mysql.createConnection({
- // host: '107.170.169.80',
- // user: 'david',
- // password: 'david!102',
- // });
- // console.log(id);
- // connection.connect;
- // connection.query('DELETE FROM NCV.contactlist where id = ' + id, function (err, doc) {
- // res.json(doc);
- // });
- // connection.end();
- // });
- // app.get('/contactlist/:id', function (req, res) {
- // var id = req.params.id;
- // var connection = mysql.createConnection({
- // host: '107.170.169.80',
- // user: 'david',
- // password: 'david!102',
- // });
- // console.log(id);
- // connection.connect;
- // connection.query('SELECT * FROM NCV.contactlist where id = ' + id, function (err, doc) {
- // console.log(doc[0]);
- // res.json(doc[0]);
- // });
- // connection.end();
- // });
- // app.put('/contactlist/:id', function (req, res) {
- // var id = req.params.id;
- // var connection = mysql.createConnection({
- // host: '107.170.169.80',
- // user: 'david',
- // password: 'david!102',
- // });
- // console.log(req.body.name);
- // connection.connect;
- // connection.query('UPDATE NCV.contactlist SET ? WHERE id = ' + id, req.body,function (err, doc) {
- // console.log(doc);
- // res.json(doc);
- // });
- // connection.end();
- // });
- app.listen(3000);
- console.log("Server running on port 3000");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement