npm install
npm run server o nodemon index.js
npm init -y
npm i express --save
npm i express-validator
npm i bcryptjs
npm i cors
npm i jsonwebtoken
npm i express-fileupload
npm install uuid
npm i dontenv
Crear un archivo .env
y especificar las siguientes variables:
- PORT=3000
- DB_CNN=mongodb+srv://
<username>
:<password>
@cluster0.o7ft6.mongodb.net/<testbd>
Ejemplo: models/users.js
const { Schema, model } = require("mongoose");
const userSchema = new Schema({
name:{ type: String, require: true },
})
module.exports = model("Users", userSchema);
Ejemplo: controllers/user.js
const getUsers = (req, res) => {
res.json({
ok: true,
users: [],
});
};
module.exports = { getUsers };
Ejemplo: routes/users.js
const { Router } = require("express");
const { getUsers } = require("../controllers/users");
const router = Router();
router.get("/", getUsers);
module.exports = router;