I'm having trouble getting the CSS and JS to apply within routing of my nodejs project. I've tried the following lines:
app.use(express.static(__dirname + '/public'));
app.use(express.static(__dirname, '/public'));
app.use('/static', express.static(__dirname, '/public));
Am I forgetting to do something? My client console says this: Refused to apply style from 'http://localhost:3000/users/css/styles.css' My CSS file is not in the users folder though. Its in a folder called 'public' in the same directory as my 'server.js' file.
const express = require('express');
const port = 3000;
const app = express();
app.set('view engine', 'pug');
app.use(express.static('public'));
app.get('/', (req, res) => {
res.render('pages/home');
});
// This code works, but I want to apply different routing
app.get('/register', (req, res) => {
res.render('pages/register');
});
// This code will render the page, however CSS and JS files don't apply
app.get('/users/register', (req, res) => {
res.render('pages/register');
});
app.listen(port, () => {
console.log('Server is currently running on port ' + port);
});