embedded-javascript

node ejs reference error data not defined at eval when handing data to view

前提是你 提交于 2021-02-19 07:54:06
问题 i've been closing in on a node application using express and ejs, but when i try to hand data to my view from the controller like so var myData = { theData: data }; res.render(path.join(__dirname + '/../views/index'), myData); i get a nice error ReferenceError:.. myData is not defined eval (from ejs lib) when trying to access myData in the view like so var data = <%-myData%>; or in any other way basically, i've tried stringifying the data, wrapping it in another object and stuff like that but

Nodejs - How to show qr-image result in view

拈花ヽ惹草 提交于 2020-01-01 10:28:13
问题 I use qr-image plugin for Nodejs to generate a QR code and it works pretty good. The problem is showing result image in ejs. var express = require('express'); var router = express.Router(); var qr = require('qr-image'); router.get('/', function(req, res) { var code = qr.image("text to show in qr", { type: 'png', ec_level: 'H', size: 10, margin: 0 }); res.type('png'); code.pipe(res); // res.render('index', { title: 'QR Page', qr: code }); }); When i uncomment last line, nodejs crashs. How to

Express + Node.js Can't get Image to load

白昼怎懂夜的黑 提交于 2019-12-24 09:49:45
问题 Very new to MEAN Stack and I'm using Brackets to edit .ejs views for a simple form app using Express tutorial. I'm trying load a static image and it just won't load. I'm getting GET /public/ggcbear.jpg 404 from app.js (terminal). I also created a image.ejs views to handle the load...but thats not working. My .jpg is listed in the folder: public. What syntax is wrong in my code/.ejs files? Part of my app.js var http = require("http"); var path = require("path"); var express = require("express"

how to format a date in embeddedjs

喜欢而已 提交于 2019-12-12 12:14:29
问题 app.js app.get('/user.html', function(req, res){ dbConnect.collection("users").find().toArray(function(err, docsData) { res.render('user', { data: docsData, title: "EJS example", header: "Some users" }); }); }); user.html <% data.forEach(function(user){ %> <tr> <td> <%= user.date %> </td> </tr> <% }) %> output is 2014-12-24T09:47:07.436Z this is the value coming from mongodb. I want to format this to Dec-24-2014. How to format it in embeddedjs. 回答1: You can use toDateString() to better format

How to include a JS script in a ejs file, nodeJS app?

非 Y 不嫁゛ 提交于 2019-12-10 19:57:16
问题 I'm doing the nodeJS tuto on openclassroom. I use the template engine ejs . I try to run a simple JS script but I can't. Here is my app structure: App_toDoList/ │ ├──app.js ├──package-lock.json ├──package.json │ ├── js/ ├── node_modules/ └── views/ ├── modify.ejs └── todo.ejs I run my server with app.js : var express = require('express'); var session = require('cookie-session'); // Charge le middleware de sessions var bodyParser = require('body-parser'); // Charge le middleware de gestion des

Nodejs - How to show qr-image result in view

ぃ、小莉子 提交于 2019-12-04 08:29:37
I use qr-image plugin for Nodejs to generate a QR code and it works pretty good. The problem is showing result image in ejs. var express = require('express'); var router = express.Router(); var qr = require('qr-image'); router.get('/', function(req, res) { var code = qr.image("text to show in qr", { type: 'png', ec_level: 'H', size: 10, margin: 0 }); res.type('png'); code.pipe(res); // res.render('index', { title: 'QR Page', qr: code }); }); When i uncomment last line, nodejs crashs. How to send code to view as a variable? Update: This code returns [object Object] in result page. var code = qr