Question: Javascript not linking properly with node app

Question

Javascript not linking properly with node app

Answers 2
Added at 2016-12-30 20:12
Tags
Question

Using Node/Express/EJS and I havent included any js files yet, well im starting to and cannot get my alert("working"); to work! Ironic huh.

The goal is to get learnJs.js to load in the browser to show the alert so I know things are working.

Here is node including the directory:

// Static Resource Inclusions
app.use(express.static(__dirname +"/styles"));
app.use(express.static(__dirname +"/img"));
app.use(express.static(__dirname +"/js"));
app.set("views", path.join(__dirname, "/views"));
app.set("view engine", "ejs");

Here is the file structure I have:

[enter image description here

Here is the learnJs.js:

enter image description here

Here is the front end template, header.ejs and it gets called on every page:

<head>
<title>Memento</title>

<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha256-/SIrNqv8h6QGKDuNoLGA4iret+kyesCkHGzVUUV0shc=" crossorigin="anonymous"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<link rel="stylesheet" type="text/css" href="/styles.css">
<script type="text/javascript" src="/js/scripts/learnJs.js"></script>

Answers to

Javascript not linking properly with node app

nr: #1 dodano: 2016-12-30 20:12

Make sure that your learnJs file has been loaded into your browser by checking the developer console in the browser.

nr: #2 dodano: 2016-12-30 20:12

You need to load script like below , /js/ is not required

 <script type="text/javascript" src="scripts/learnJs.js"></script>
Source Show
◀ Wstecz