I looked an a few similar questions on stack (like this)but none of them seem to help me, even though my issue seems similar.
I am new to node and server side scripting and would prefer to not use more frameworks/components.
I have a drawing app written fully in javascript (jquery) and I want to host it using node as my backend.
My folder structure is like this:
├── README.md
├── app.js
├── css
├── db.js
├── model.js
├── package.json
├── public
│ ├── css
│ │ └── simple.css
│ └── js
│ ├── jquery.min.js
│ └── testjs.js
├── route.js
├── schema.sql
├── schema_macaronic.sql
├── node_modules +
└── views
├── 404.jade
├── index.jade
├── signin.jade
└── signup.jade
All of my code is in public/js/testjs.js
. testjs.js uses jquery, underscore and some other js libraries. I would like to call functions in this file in my views index.jade
, signin.jade
etc.
I have the following line in my app.js
app.use(express.static(path.join(__dirname, 'public')));
app.use('/jquery', express.static(path.join(__dirname, '/public/js')));
and in signin.jade
I looks like this:
doctype html
html(lang='en')
head
link(rel='stylesheet', href='/css/simple.css')
script(type="type/javascript",src="/jquery/jquery.min.js")
//script(type="type/javascript",src="js/testjs.js")
title #{title}
body
script.
$(document).ready(function() {
console.log('hello form js and jquery')
});
h2 Sign In Form
form(method='post', action='/signin')
p
label(for='username') username
input#username(type='text', name='username', placeholder='username', required='true')
p
label(for='password') password
input#password(type='text', name='password', placeholder='password', required='true')
p
input#signin(type='submit', name='signin', value='sign in')
a(href='/signup', title='register') register
When i reach the index page I see a Uncaught ReferenceError: $ is not defined
at line 10 ($(document).ready(function()
)
What am I doing wrong? The entire project is here on github.
Note: the css is working (color changes to red based on css in public/css/simple.css
.
Also, I need more that just jquery on the client side, I have around 2-3 js files that are meant to be run on client side, how can I make them also visible to the client side views?