express

req.flash() requires sessions

夙愿已清 提交于 2020-01-04 04:04:05
问题 I have a problem with flash at views. I am using connect-flash. there is my configuration app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(express.cookieParser('secret')); app.use(express.session()); app.use(passport.initialize()); app.use(passport.session()); app.use(flash()); app.use(function(req, res, next){ res.locals.flash = req.flash next() }) here I set flash message at controller action exports.new = function(req, res){ req.flash('info', 'test') res.render(

Set the lookup path of view folder of ejs in express

99封情书 提交于 2020-01-04 04:01:09
问题 I have app.js in Express_server folder.Full location of aap.js is I:\WEB Development\Node\Express_server\ and I made views folder at the location I:\WEB Development\Node\ How can I set the lookup path of views folder to above location(I:\WEB Development\Node)? code of my app.js const express = require('express'); const app = express(); app.set('view engine', 'ejs'); app.get('/',function(req, res){ res.render('index'); }); 回答1: You can change your views default path: app.set('views', path.join

express multer Cannot read property 'profileimage' of undefined

无人久伴 提交于 2020-01-04 03:49:08
问题 I am trying to submit a form which has a file input within it with a name of profileimage , i am using express 4, express generator and multer. In my app.js I added multer like so: var multer = require('multer'); var upload = multer({ dest: './uploads' }); The tutorial i am following actually sets up multer like so (after requiring it) but it gives me an error: app.use(multer({dest: './uploads'})); And in my routes folder inside the respective file I have the following: router.post('/register

server rendering with react-router v4 and express.js

狂风中的少年 提交于 2020-01-04 03:45:05
问题 I'm trying to set up server-side rendering with the newest version of react-router v.4. I followed this tutorial https://react-router.now.sh/ServerRouter. I get following error when I refresh browser: Invariant Violation: React.Children.only expected to receive a single React element child. my routes.jsx file: export default () => <div> <Header /> <Match pattern="/" component={Home} /> <Match pattern="/about" component={About} /> <Miss component={NotFound} /> </div>; and in index.jsx I'm

NodeJS + expressJS: server-side vs. client-side html rendering [closed]

五迷三道 提交于 2020-01-04 03:19:28
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . I am new to nodejs and a little confused about the distinction between the server and client side html pages. My goal is to build an e-commerce web store for practice. The stack that I want to try is NodeJS + Express + MongoDB + AngularJS. The basic structure I have right now is

Deploy to heroku : Uncaught SyntaxError: Unexpected token <

五迷三道 提交于 2020-01-04 02:53:10
问题 I have deployed mean stack api angular 6 to heroku , when I open the app on browser its displays brank page , In my server.js this is what i have const express = require('express'); const path = require('path'); const flash = require('connect-flash'); const bodyParser = require('body-parser'); const cors = require('cors'); const mongoose = require('mongoose'); const db = require('./app/config/database'); // Connect To Database mongoose.connect(db.database); // On Connection mongoose

Cannot get browser to initiate download from express

馋奶兔 提交于 2020-01-04 02:28:06
问题 Following on from this question, I cannot get the browser to initiate a download from express. Backend code: app.get('/download', (req, res) => { res.download('./textfile.txt', (err) => { if (err) { console.log('error: ' + err); } else { console.log('success'); } }); }) I have changed from a .gpx file to text file to ensure its nothing to do with that, and I have tried playing with the headers as below, to no avail: res.header('Content-Type', 'text/plain') res.header('Content-Security-Policy'

How to get the value on url in pug

不打扰是莪最后的温柔 提交于 2020-01-04 02:09:27
问题 I have an url like this: http://localhost/editblog/58a5da1df3ec9614fc9893d3 and code in pug like this: input.form-control(type='hidden', name='id', value='') The question is how to get the value on the url and pass it to value='' I've known about req.params.id but it is not what could solve my issue 回答1: When you render your pug template you could send any variable as res.locals property so it will send to template: app.get('/editblog/:id', function(req, res) { res.render('editblog', { title:

trying to render html files using jade but it still adresses it as a jade

隐身守侯 提交于 2020-01-04 01:58:09
问题 i have read theses two posts regrading my issue: http://stackoverflow.com/questions/4529586/render-basic-html-view-in-node-js-express http://stackoverflow.com/questions/12046421/how-to-configure-express-js-jade-to-process-html-files and my code is as follows: app.engine('.html', require('jade').__express); app.set('views', __dirname + '/app/views'); app.set('view engine', 'html'); it is clear that for some reason it is trying to read index as if it was still a jade file and thus i am getting

expressjs bind all routes except 2 folders?

て烟熏妆下的殇ゞ 提交于 2020-01-03 19:33:49
问题 In expressjs, how do I bind a route to all urls except /static and /fail For example, it sound bind to: /users /books /books/anything but not bind to /static /fail /fail/anything /static/anything 回答1: If you are saying you want to create one route for everything but /static* then here is the command for creating the GET route: app.get(/^((?!\/static).)*$/, function(req, res){ //Do your thing in here... }); 回答2: My question was just slightly different and this was the best question/answer