Idk why this happen, i've readed the code 5x and i cant see the mistake. (im used requireDir)
server.js code:
//chamando
const express = require('express');
const mongoose = require("mongoose");
const requireDir = require('require-dir');
//iniciando app
const app = express();
//iniciando o DB
mongoose.connect(
"mongodb://localhost:27017/nodeapi",
{ useNewUrlParser: true }
);
requireDir('.src/models');
//first rote
app.get('/', (req, res) => {
res.send('hello worlldd');
});
app.listen(3001); //porta
//NODEMON - LIVE
/* "dev": "nodemon server.js" no package
npm run dev no terminal */
Product.js code:
const mongoose = require('mongoose');
const ProductSchema = new mongoose.Schema({
title:{
type: String,
required: true,
},
description:{
type: String,
required: true,
},
url:{
type: String,
required: true,
},
createdAt:{
type: Date,
default: Date.now,
},
});
mongoose.model('product', ProductSchema);
The server just dont run. Everything was normal before I put the "mongoose".
im used docker and robot3T too.
The whole error
The provided path path to requireDir()
has a typo. You are including the path .src/models
instead of ./src/models
.
Fixed server.js
:
//chamando
const express = require('express');
const mongoose = require("mongoose");
const requireDir = require('require-dir');
//iniciando app
const app = express();
//iniciando o DB
mongoose.connect(
"mongodb://localhost:27017/nodeapi",
{ useNewUrlParser: true, useUnifiedTopology: true }
);
requireDir('./src/models');
//first rote
app.get('/', (req, res) => {
res.send('hello worlldd');
});
app.listen(3001); //porta
//NODEMON - LIVE
/* "dev": "nodemon server.js" no package
npm run dev no terminal */