# install packages
npm i express sequalize cors pg
Configurar servidor el servidor
const express = require("express");
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(express.json());
// parse requests of content-type - application/x-www-form-urlencoded
app.use(express.urlencoded({ extended: true }));
// simple route
app.get("/", (req, res) => {
res.json({ message: "Welcome to application." });
});
// set port, listen for requests
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}.`);
});
# para acceder a las variables de .env a traves de process.env en js
npm install --save dotenv
# used for helping us to set the NODE_ENV in any command line, without worrying about the operating system
npm install --save-dev cross-env
# a middleware used with express to get request’s body as an Object.
npm install --save-dev body-parser