Warnings in Bootstrap and Jade

Can someone help me understand why the colors for 'success' and 'danger' are not showing up in my flash messages? The messages themselves appear as expected, but the associated colors are missing. Here is a snippet of my package.json:

{
  "dependencies": {
    "body-parser": "^1.18.3",
    "bootstrap": "^4.1.3",
    "connect-flash": "^0.1.1",
    "cookie-parser": "^1.4.3",
    "express": "^4.16.4",
    "express-messages": "^1.0.1",
    "express-session": "^1.15.6",
    "express-validator": "^5.3.0",
    "mongoose": "^5.3.15",
    "pug": "^2.0.3"
  },
  "devDependencies": {
    "nodemon": "^1.18.7"
  }
}

In my app.js file, this is how I am setting up the sessions and flash messages:

const express = require('express');
const path = require('path');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const expressValidator = require('express-validator');
const flash = require('connect-flash');
const session = require('express-session');

// express session middleware

app.use(session({
    secret: 'keyboard cat',
    resave: true,
    saveUninitialized: true
}));

// express messages middleware

app.use(require('connect-flash')());
app.use(function (req, res, next) {
    res.locals.messages = require('express-messages')(req, res);
    next();
});

app.use(flash());

// routes setup

let quotes = require('./routes/quotes');
let subscribers = require('./routes/subscribers');
app.use('/quotes', quotes);
app.use('/subscribers', subscribers);

// Handling flash messages

router.post('/subscribe', function (req, res) 
{
// logic to handle subscription

req.flash('success', 'Subscription confirmed.');
res.redirect('back');
});

In my services.pug file, I have included the necessary stylesheets and scripts:

link(rel='stylesheet', href='/css/style.css')
    link(rel='stylesheet' href='/node_modules/bootstrap/dist/css/bootstrap.css')
// other code here...
                h1 Subscribe to our newsletter
                //- include subscribe.pug
                form(method='POST', action= '/subscribe')
                    input(name = 'email',type='email', placeholder='Enter email')
                    button.button1(type='submit') Subscribe
                    != messages('message',locals)

// at the bottom...

script(src='/node_modules/jquery/dist/jquery.js')
    script(src='/node_modules/bootstrap/dist/js/bootstrap.js')

In my message.pug file, I am looping through the messages to display alerts with appropriate styling based on the type:

.messages 
    each type in Object.keys(messages)
        each message in messages[type]
            div(class = "alert alert-"+ type) #{message}

Although the messages appear as expected, the colors related to success and danger are not displaying correctly. The messages seem to blend with the background color instead. Not sure what I am missing here.

UPDATE:

Upon checking the console in Chrome, I found some error messages related to the bootstrap.css and jquery.js files not being found by the application. Here is where I set up my public folder in app.js:

// set public folder
app.use(express.static(path.join(__dirname, 'public')));

https://i.sstatic.net/PHlm7.png https://i.sstatic.net/7JJla.png

The node_modules folder is available as well. https://i.sstatic.net/jIQAP.png

Any assistance would be greatly appreciated!

Answer №1

In addition to serving the public folder, remember to also include the bootstrap and jquery dist folders:

// set public folder
app.use(express.static(path.join(__dirname, 'public')));
// serve bootstrap and jquery
app.use(express.static(path.join(__dirname, 'node_modules', 'bootstrap', 'dist')));
app.use(express.static(path.join(__dirname, 'node_modules', 'jquery', 'dist')));

Include them in your HTML (ensure CSS files are in the head tag):

link(rel='stylesheet' href='/css/bootstrap.css')
link(rel='stylesheet' href='/css/style.css')

Also add these scripts:

script(src='jquery.js')
script(src='/js/bootstrap.js')

For production, consider using minified versions (e.g., bootstrap.min.js) or utilize a CDN for faster loading times.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Spin the text inside an <li> element generated by JavaScript

I am currently working on a unique script designed to create a custom number of slices for a circle. The items in the circle are being displayed as shown in this generated circle image. This is the Javascript code I have been using: for () { men ...

Unique and responsive grid styling with CSS

Is it possible to create a responsive grid like the one shown in the image below? I attempted to use absolute positioning for all blocks, but I'm having trouble making it responsive... I should note that the styling will be generated dynamically usi ...

Sometimes, CSS unicode characters may not render correctly and appear as jumbled symbols like "â–¾"

https://i.sstatic.net/eGvzJ.jpg Every now and then, about 1 in every 100 page refreshes, the unicode characters on my page turn into jumbled nonsense (you might need to zoom in to see it clearly). Specifically, the unicode characters are displayed as â ...

Generate an array of JavaScript objects by converting a batch of JSON objects into objects within a Node.js environment

I am working with a prototype class: function customClass(){ this.a=77; } customClass.prototype.getValue = function(){ console.log(this.a); } and I also have an array of JSON objects: var data=[{a:21},{a:22},{a:23}]; Is there a way to cre ...

Can you explain the purpose of connectMicroservice and startAllMicroservicesAsync functions in nestjs?

While looking through the codebase, I came across connectMicroservice and startAllMicroservicesAsync in an application using Nest. Could someone please clarify what these functions are used for? I attempted to research them in the official Nest documenta ...

Creating a unique-looking visual representation of progress with arcs

Looking to create a circular progress bar (see image below), with loading starting from the left bottom side up to the right bottom side. The empty state should be light-blue (#E8F6FD) and the progress color strong blue (#1CADEB). https://i.sstatic.net/VZ ...

How to Retrieve the ID Parameter in a Node.js Route

After working on my node.js code, I encountered a problem: router.get("/author-edit/:id", (req, res) => { res.render("author-edit"); }); router.post("/author-edit/:id", (req, res, next) => { let article_ID = req.par ...

The CastError occurred when trying to convert the value "0" (string type) to an ObjectId at the path "_id" for the model "Users" during the findOne operation and other related operations

Recently, I started exploring mongodb and nodejs. Unfortunately, I encountered an error when trying to retrieve a specific user using req.params.id from the database. app.get('/user/:id', (req,res) => { console.log(req.params.id) Users ...

Dealing with challenges in Jest mocking technology

I'm having trouble mocking the async function declared inside a class using jest.js in node.js. When I attempt to mock the function, it seems to bypass the mock and execute the actual implementation. Strangely, another user was able to successfully mo ...

What is preventing me from utilizing middleware in my express route?

I have a project in progress where I am developing an API. As part of this process, I need to implement a user system and ensure secure access to the API. Below is the middleware function used for validation: 'use strict' const jwt = require(& ...

I am seeing the object in req.body displayed in reverse order within my Node.js and Express backend application

I encountered an issue while developing a To-do list web application using the MERN stack with Redux. The problem arises when I try to send post data to the backend. In my form, the textfield area is named 'task' (e.g., ) and I input 'jonas& ...

Leverage the power of ssh2-promise in NodeJS to run Linux commands on a remote server

When attempting to run the command yum install <package_name> on a remote Linux server using the ssh2-promise package, I encountered an issue where I couldn't retrieve the response from the command for further processing and validation. I' ...

Issue resolved: Mysterious fix found for background images not displaying in NextJS React components

I am having trouble displaying a background image on an element in NextJs using Typescript and Tailwind. I do not believe it is a TypeScript issue since I am not receiving any errors or IntelliSense warnings. Below is the code I am working with: var classn ...

Error: The system encountered an issue that res.send function is not recognized

I encountered the error "TypeError: res.send is not a function" in my code snippet const express = require('express'); const bodyParser=require('body-parser'); const app=express(); app.use(bodyParser.urlencoded({ extended: true })); ap ...

Using grid-template-areas in ReactJS function components does not function as expected

REMINDER: Check out and customize the code in CodeSandbox. This is a parent component with 5 children elements. Among them, 3 are React components and the remaining 2 are regular HTML buttons: import "./App.css"; import React from "react&qu ...

Disable automatic playback of HTML video

There is an HTML video with an image that loads initially and then disappears to play the video. I would like the image to always be visible until I click on it. Once clicked, the video should start playing. You can view the code on JSFiddle: http://jsf ...

What is the best way to add flair to the HTML <title> tag?

Just a quick question - I'm wondering if there is a method to apply CSS styles to an HTML element. Here's an example declaration: title { color: red; font-family: 'Roboto', sans-serif; } ...

Twilio Group MMS feature experiencing technical difficulties

I currently have a Twilio Trial account with an active number that supports SMS/MMS. My goal is to use this number for group MMS chats, but I am facing some challenges. After following a tutorial on Tut, I attempted to create a basic test using the provid ...

What is the best way to prevent a blank page refresh in a multi-page electron application?

Exploring electron and its potential for native app development has piqued my interest. Currently utilizing Bootstrap, I aim to have each 'view' housed in its own file. Successfully achieved this with the following setup: <div class="masthea ...

Issue with Npm EACCESS error encountered while attempting to set up Firebase

After switching to a new m1 MacBook Pro, I encountered issues when trying to run and deploy my code using Firebase. When I attempted to deploy my code with the command firebase deploy, I received an error message stating zsh: command not found: firebase. T ...