js path in html code example

Example 1: how to link javascript to html

<script src = "index.js"></script>

Example 2: html bind js file

<script type="text/javascript" src="path-to-javascript-file.js"></script>

Example 3: app.use public

app.use(express.static('public'))
app.use(express.static('files'))

Example 4: use static with expres

app.use(express.static('directoryName'))
#store the files in the directory as if you were making a website without express

Example 5: path in html

/   = Root directory
   .   = This location
   ..  = Up a directory
   ./  = Current directory
   ../ = Parent of current directory
   ../../ = Two directories backwards

Example 6: How to add js file to a site through url

var jsFile = document.createElement("script");
jsFile.src = "homePage.js";  // it can be path also  "{themes('/scripts/homePage.js')}"
document.body.appendChild(jsFile);  //append it as src to body

Tags:

Misc Example