I have a JavaScript file and a stylesheet that I am trying to link in order to use a cipher website that I created.
Here is my File Path:
website/
(contains app.js/html files and package json)
website/public/css
(contains CSS files)
website/public/scripts
(contains my JavaScript file)
When viewed statically, everything functions as intended. The JavaScript and CSS work fine.
However, when using node.js to run it dynamically, they do not work even though I believe I have added the correct syntax for linking them.
app.get('/public/scripts/script.js',function(req,res){
res.sendfile(path.join(__dirname+'/public/scripts/script.js'));
});
app.get('/public/css/styles.css',function(req,res){
res.sendfile(path.join(__dirname+'/public/css/style.css'));
});
And here are the link tags in my HTML file:
<link rel="stylesheet" type="text/css" href="css/styles.css">
I am new to node.js and express, so any help in figuring out what's wrong would be appreciated.
Below are all relevant files:
app.js file
const express = require('express');
const app = express();
var fs = require('fs');
var path = require('path');
app.listen(8080), () => console.log('listening on port 8080');
// Rest of the routes defined here
HTML
Your HTML code goes here...
my Script file
Your JavaScript code goes here...