Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express=require('express');
- const app = express();
- var fs = require("fs");
- var jsdom = require('jsdom');
- var db
- app.set('view engine','ejs');
- app.use(express.static('public'));
- app.get('/',function(req, res){
- var htmlSource = fs.readFileSync(__dirname + '/views/index.ejs', "utf8");
- call_jsdom(htmlSource, function (window) {
- var $ = require('jquery')(window);
- console.log($('body').html()); // THIS CONTAINS HTML WITH jQUERY ADDED
- db.collection('quotes').find().toArray(function(err,result){
- if(result.length>0)
- res.render('index.ejs', {quotes:result})
- else
- res.render('index.ejs')
- })
- });
- function call_jsdom(source, callback) {
- jsdom.env(
- source,
- jquery-1.10.2.js, // (*)
- function(errors, window) { // (**)
- process.nextTick(
- function () {
- if (errors) {
- throw new Error("There were errors: "+errors);
- } callback(window);
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement