Click here to Skip to main content
15,881,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am so confused that I have just moved two routers from my server file to controller file to follow the MVC format. Now I can not see logo image on that routers. I can see other pictures that are in view files(addMovies.handlebars) Logo(png file) is located in my main.handlebars file and I am using addMovie.handlebars as a view to render with content of main.handlebars.

This my main.handlebars file that has logo image that is not being rendered:
HTML
<head>  
// some code
</head>
<body>
    <header>
        <nav>
        <ul class="menu">
            <li class="logo"><img src="./images/logo/logof.png" alt="STREAMDOG"></li>
            <li class="item"><a href="/">Home</a></li>
            <li class="item"><a href="/allMovieTV">Movies</a></li>
            </li>
            <li class="item button"><a href="/login">Log In</a></li>
            <li class="item button secondary"><a href="/signup">Sign Up</a></li>
            <li class="toggle"></li>
        </ul>
    </nav>
    </header>

    <main>
    {{{body}}}
    </main>

    <footer class="footer">
       // some code
    </footer>
</body>


this is my controller file(movies.js)

JavaScript
const express = require("express");
const router = express.Router();
const movieModel = require("../models/movieDB");

router.get("/add", (req, res) => {
    res.render("addMovie", {

    })
});

router.post("/add", (req, res) => {
    const newMovie = {
        movieName: req.body.name,
        about: req.body.about,
        imdb: req.body.imdb,
        length: req.body.length,
        tags: req.body.tags,
        releaseDate: req.body.releaseDate,
        directors: req.body.directors,
        // featured: req.body.featured,
        type: req.body.type,
        Rprice: req.body.Rprice,
        Bprice: req.body.Bprice,

    }

    const movie = new movieModel(newMovie);
    movie.save()
    .then(() => {
        res.redirect("/allMovieTV");
    })
    .catch(err=>console.log(`error occured while saving the movie ${err}`));
})
module.exports = router;


This is how I am referring to those routes in server.js file


JavaScript
const express = require("express");
const exphbs  = require('express-handlebars');

const app = express();
var hbs = exphbs.create({ /* config */ });

// Defining static folder
app.use(express.static('public'));

//Importing controllers
const moviesController = require("./controllers/movies.js");

app.use("/new/",moviesController);


I do not understand how the front-end is being changed when I am moving code of back-end!

Please explain if I need to add more information here.

What I have tried:

I tried replacing routs in server file it worked but when I moved them into another file it is not working.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900