jquery - (NodeJS + Express) Server isn't reading linked javascript file(s) from html -


i'm stuck, managed server on webhost working on aws + else in express.js have error:

root@ip(censored):/home/ubuntu/(censored)# /home/ubuntu/(censored)/routes/index.js:15 $(document).ready(function() {   ^  referenceerror: document not defined     @ object.<anonymous> (/home/ubuntu/(censored)/routes/index.js:15:3)     @ module._compile (module.js:570:32)     @ object.module._extensions..js (module.js:579:10)     @ module.load (module.js:487:32)     @ trymoduleload (module.js:446:12)     @ function.module._load (module.js:438:3)     @ module.require (module.js:497:17)     @ require (internal/module.js:20:19)     @ object.<anonymous> (/home/ubuntu/forbiddenground/app.js:12:14)     @ module._compile (module.js:570:32)     @ object.module._extensions..js (module.js:579:10)     @ module.load (module.js:487:32)     @ trymoduleload (module.js:446:12)     @ function.module._load (module.js:438:3)     @ module.runmain (module.js:604:10)     @ run (bootstrap_node.js:394:7) ^c 

and here html file loading jquery (isn't supposed know included jquery defines $ variable?)

<link rel="stylesheet" href="styles.css"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"></link> <link href="owl-carousel/owl.carousel.css" rel="stylesheet"> <link href="owl-carousel/owl.theme.css" rel="stylesheet"> <link rel="stylesheet" href="css/style.css">  <link href="css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen"> <link rel="stylesheet" href="font-awesome-4.4.0/css/font-awesome.min.css"  type="text/css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <script type="text/javascript" src="scripts.js"></script> 

and app.js firing:

var express = require('express'); var app = express(); var path = require('path'); var logger = require('morgan'); var cookieparser = require('cookie-parser'); var bodyparser = require('body-parser'); var favicon = require('serve-favicon'); var cons = require('consolidate'); const port = 9000; var swig = require('swig');  var routes = require('./routes/index'); var users = require('./routes/users');  var app = express();   app.engine('html', swig.renderfile);  app.use(express.static('public')); app.use(express.static('forbiddendirectory')); app.set('view engine', 'html'); app.set('views', __dirname + '/views');     //////////////////////////////////////////////////////////////////////////////////// app.get('/', function (err, req, res) {     req.render('index'); });       app.listen(port); console.log(`server started! port:  ${port}`); 

this index.js:

var express = require('express'); var router = express.router();  /* home page. */ router.get('/', function(req, res, next) {   res.render('index', { joo }); });  module.exports = router;   // navbars $(document).ready(function() {     const apod = $("#apod").attr("href","apod.html");     const home = $("#home").attr("href","home.html");     const animedb = $("#animedb").attr("href","animedb.html");     const birthdays = $("#birthdays").attr("href","birthdays.html");     const holidays = $("#holidays").attr("href","holidays.html");     const events = $("#events").attr("href","events.html");     const contacts = $("#contacts").attr("href","contacts.html");     $("#importantdates").click(function(e) {         e.preventdefault();     });  }); 

it looks you're using jquery + dom things in 1 of routes.

routes aren't place that, run in node.js context , such not have access dom. you'll need move code (i.e. $(document).ready(function(){ ... });) js file included browser.

edit: add that, const apod = $("#apod").attr("href","apod.html"); not effective way set href attribute on navigation links. should modify template links occur , set href attribute in there.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -