I am very new to Javascript and NodeJS.
Here is my website's code structure:
|source
| | stylesheets
| | | index.styl
| | templates
| | default.jade
| | homepage.jade
|static
| | [.css generated]
|
|server.js
|package.json
|file.js
And here is server.js
:
var express = require('express')
, logger = require('morgan')
, app = express()
, templateHome = require('jade').compileFile(__dirname + '/source/templates/homepage.jade')
app.use(logger('dev'))
app.use(express.static(__dirname + '/static'))
app.get('/', function (req, res, next) {
try {
var html = templateHome({ title: 'Home' })
res.send(html)
} catch (e) {
next(e)
}
})
app.listen(process.env.PORT || 3000, function () {
console.log('Listening on http://localhost:' + (process.env.PORT || 3000))
})
My second .js
file contains a simple function that should be accessed once my user clicks a button in my home page defined in Jade
like such:
block content
button(onclick='downloadFile()') Click me
But it seems that the function is not defined in the current scope, even though it is defined in file.js
. What do I have to add in order to take my other .js
files into account?