pug

Jade URL Routing in Node Express

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 07:15:53
I am building a Node Express application using Jade, and I am confused about how to route my views to the specific requests the browser will make. I understand that in order to get URLs to work in the browser, we need to use Node's routes; however, from looking online, I have discovered that Express has its own router. I used PHPStorm to start up my project, and the index.jade will load... but how do I load the others? Here is my existing code: var express = require('express'), routes = require('./routes'), http = require('http'), path = require('path'); var app = express(); app.configure

sending mail with nodemailer - email from field incorrect

一笑奈何 提交于 2019-12-06 06:04:56
问题 Trying to set up a contact form with nodemailer. Here's what's in my app.js: // EMail configuration var smtpTransport = nodemailer.createTransport("SMTP",{ service: "Gmail", auth: { user: "myemailaddress", pass: "xxx" } }); // CONTACT FORM app.get('/contact', function (req, res) { res.render("contact"); }); app.post('/contact', function (req, res) { var mailOptions = { from: req.body.email, // sender address to: "myemailaddress", // list of receivers subject: req.body.subject, // Subject line

Can I set gulp livereload to run after all files are compiled?

喜你入骨 提交于 2019-12-06 05:39:59
问题 I've got a gulp set up to work with Stylus, Jade and tiny-lr. My problem is that when I save one jade file, it start's compiling them all, therefore live reloading fires on the first file copied to the destination, before the file I am working on currently is compiled, resulting in me having to refresh manually. I have fixing this issue using "gulp-changed" but I don't seem to be able to configure it or something. Anyone had this problem before? I am posting my Gulp file so you can take a

Express displaying mongodb documents in Jade

淺唱寂寞╮ 提交于 2019-12-06 05:18:50
I'm learning Node, Express, Jade & Mongodb. I'm unable to display my mongodb documents in jade. I'm unable to figure it out on my own. I'm successfully logging all documents using console.log and it display all the documents correctly. Please no mongoose or other solutions. Just how to build on this code. I already connected to the db, displayed all documents in terminal. How to be able to pass it to Jade and display it in view.jade? Thanks. Here is my app.js code var express = require('express'); var app = express(); var path = require('path'); var favicon = require('serve-favicon'); var

Preserving newlines in Jade

我的梦境 提交于 2019-12-06 05:16:50
问题 Whenever I render a JADE template, I get all HTML in a single line. This makes it difficult to read in view-source mode. How can I tell JADE to create HTML which is properly indented? Here is my template: #application p#docs a(href='/docs/index.html') Documentation p#user-input input#msg(name='msg', size='50') input#submit(name='submit', type='submit', value='Send a Message') ul#messages 回答1: In Jade's compiling options set pretty to true. Which can be done in multiple ways depending of how

Express.js: How can I get the ip Address and render a view?

非 Y 不嫁゛ 提交于 2019-12-06 04:56:56
问题 I really think this should be easy. But when I render a jade template, I also want to grab the ip address. My code look like this. app.js app.get('/', index.home) index.js exports.home = function(req, res) { res.render('index'); }; Where can I add something like: var ip = req.header('x-forwarded-for') || req.connection.remoteAddress; //or console.log(req.connection.remoteAddress); 回答1: Just use req.ip and make sure you have app.enable('trust proxy'); if your app is deployed behind a reverse

Express image upload and view in jade

佐手、 提交于 2019-12-06 04:29:50
I'm trying to upload an image and show it in express. I configured my app to upload in 'public/images' app.use(express.bodyParser({ keepExtensions: true, uploadDir: './public/images' })); The upload goes great but I can't find how to show uploaded images in my jade template. The image path I get from the req.files object is something like 'public/images/imagename.jpg' but the only way I can see images is in a url like this: http://localhost:3000/images/imagename.jpg Is there a way to maybe remove the 'public' parameter from req.files, or are there other solutions?? Thanks everyone! EDIT: Ok,

Pass an object to angularjs template from jade

隐身守侯 提交于 2019-12-06 03:33:12
问题 I am trying to pass an object from the node to the client like below render: function(req,res){ res.render('auth',{ userData : req.session.user }); } In my auth.jade the code is as below script. var data = !{JSON.stringify(userData)} console.log(data) window.top.location='/profile' So I am redirecting the application to a new route which I have defined in the routeProvider using angularjs app.config(['$routeProvider','$locationProvider', function($routeProvider,$locationProvider) {

Error installing jade on heroku

╄→尐↘猪︶ㄣ 提交于 2019-12-06 01:47:02
I get an error when pushing my node.js-app to Heroku. It used to work, but now, for some reason, it's failing. When I push to Heroku I get the following: -----> Node.js app detected -----> Resolving engine versions Using Node.js version: 0.6.13 Using npm version: 1.1.4 -----> Fetching Node.js binaries -----> Vendoring node into slug -----> Installing dependencies with npm npm http GET https://registry.npmjs.org/express/2.5.9 npm http GET https://registry.npmjs.org/jade/0.15.4 npm http 200 https://registry.npmjs.org/jade/0.15.4 npm http GET https://registry.npmjs.org/jade/-/jade-0.15.4.tgz npm

Status code 304 (Jade, Node, Express)

可紊 提交于 2019-12-06 01:46:07
I'm linking bootstrap and jquery in my jade file, link(rel='stylesheet', href='/stylesheets/bootstrap.css') and script(src='/javascripts/jquery-3.1.1.js') script(src='/javascripts/bootstrap.js') This Jade file is in my views folder. The boostrap css is in my public/stylesheets folder and the javascript is in the public/javascripts folder. When I run my application using nodemon, it says GET / 200 80ms - 1.65kb GET /stylesheets/bootstrap.css 304 1ms GET /javascripts/jquery-3.1.1.js 304 3 GET /javascripts/bootstrap.js 304 2ms The javascript and css files do not load up. Suggestions? Aruna 304