// Include Sequelize module.
const Sequelize = require('sequelize')
// Import sequelize object,
// Database connection pool managed by Sequelize.
const sequelize = require('../utils/database')
// Define method takes two arguments
// 1st - name of table
// 2nd - columns inside the table
const User = sequelize.define('user', {
// Column-1, user_id is an object with
// properties like type, keys,
// validation of column.
user_id:{
// Sequelize module has INTEGER Data_Type.
type:Sequelize.INTEGER,
// To increment user_id automatically.
autoIncrement:true,
// user_id can not be null.
allowNull:false,
// For uniquely identify user.
primaryKey:true
},
// Column-2, name
name: { type: Sequelize.STRING, allowNull:false },
// Column-3, email
email: { type: Sequelize.STRING, allowNull:false },
// Column-4, default values for
// dates => current time
myDate: { type: Sequelize.DATE,
defaultValue: Sequelize.NOW },
// Timestamps
createdAt: Sequelize.DATE,
updatedAt: Sequelize.DATE,
})
// Exporting User, using this constant
// we can perform CRUD operations on
// 'user' table.
module.exports = User
const express = require("express");
const bodyParser = require("body-parser");
const cors = require("cors");
const app = express();
var corsOptions = {
origin: "http://localhost:8081"
};
app.use(cors(corsOptions));
// parse requests of content-type - application/json
app.use(bodyParser.json());
// parse requests of content-type - application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: true }));
// simple route
app.get("/", (req, res) => {
res.json({ message: "Welcome to esparkinfo application." });
});
// set port, listen for requests
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}.`);
});
const express = require(“express”);
const bodyParser = require(“body-parser”);
const cors = require(“cors”);
const app = express();
Var corsOptons = {
origin: “http://localhost:8080/”
};
app.use (cors(corsOptions));
// parse requests of content-type - application/json
app.use (bodyParser.json());
// parse requests of content-type - application/x-www-form-urlencoded
app.use (bodyParser.urlencoded({extended:true}));
//simple route
app.get (“/”, (req, res) => {
res.json({message: “Welcome to Turing.com”});
});
// set port, listen for requests
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log (‘Server is running on port $(PORT).’ );
});