load infinity nodejs

Asked

Viewed 43 times

0

Hello, I am doing a small application in Ode and I am facing the following problem, my routes are not loading in the browser. I’m new to nodejs, so it might be something I still don’t understand, anyway, I need your help, please. Note: no error is being shown in the terminal.

app js.

require('dotenv').config();
const express = require('express');
const app = express();
const mongoose = require('mongoose');
const routes = require('./src/routes/routes');
const flash = require('connect-flash');
mongoose.connect(process.env.DATABASE_KEY, {useNewUrlParser: true, useUnifiedTopology: true})
    .then(() => {
        console.log('Connected to the database');
    })
    .catch((err) => console.log(err));

//app.use(helmet());

app.use(express.urlencoded({ extended: true}));
app.use(express.json());

app.set('views', './src/views');
app.use(express.static('public'));
app.set('view engine', 'ejs');

app.use(flash);
app.use(routes);

app.listen(3000);

Routes.js

const express = require('express');
const route = express.Router();
const homeController = require('../controllers/homeController');
const loginCotroller = require('../controllers/loginController');
const registerController = require('../controllers/registerController');

//rota principal
route.get('/', homeController.index);

//rotas de login
route.get('/login/index', loginCotroller.index);

//rotas de cadastro
route.get('/register/index', registerController.index);
route.post('/register/index', registerController.register);

module.exports = route;

homeController.js

exports.index = (request, response) => response.render('mainPage');

userModel.js

const mongoose = require('mongoose');
const bcrypt = require('bcryptjs');

const UserSchema = new mongoose.Schema({
    name: {
        type: String,
        required: true
    },
    email: {
        type: String,
        required: true
    },
    password: {
        type: String,
        required: true
    }
});

UserSchema.pre('save', async function (next) {
    const hash = await bcrypt.hash(this.password, 10)
    this.password = hash

    next();
})

const user = mongoose.model('user', UserSchema);

module.exports = user;

If I try to access the main route ('/'), my browser is as follows: inserir a descrição da imagem aqui

files

inserir a descrição da imagem aqui

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.