express

Expressjs passport-local can't logout

大城市里の小女人 提交于 2021-02-07 14:22:40
问题 I copy pasted the app passport-local on my app, The fun is I can log in users, but I can't make them logout, app.get('/logout', function(req, res){ req.logout(); res.redirect('/'); }); this is not doing nothing, nothing on the logfiles, and I I have its a link to /logout this is the main route examples app.get('/page1', function(req, res){ res.render('page1', {user: req.user}); }); app.get('*', function(req,res){ res.render('root', {user: req.user}); }); Why the logout its not working ????

mongoose objectid to number

血红的双手。 提交于 2021-02-07 13:47:56
问题 How can I cast an ObjectId to a number? In my app I'm using the latest mongoose version and backbone on the clientside. My problem is that the ObjectId always ends up being put in between quotes which results in double quotes like ""233453452534"" in my jade templates and on my client. edit: I'm querying mongodb with this.users.find({},function(err,docs){ cb(null,docs) }) console.log(docs) shows { name: 'test', _id: 5220bc207f0c866f18000001, __v: 0 } in my template option(data-id=val._id) #

How to print cookie in .ejs view engine

六眼飞鱼酱① 提交于 2021-02-07 12:47:23
问题 How do I print cookie value in form attribute? Here is the code I have so far. if(req.body.remember_me){ res.cookie("cookie_email_id", req.body.email); res.cookie('password', req.body.password); }else{ res.clearCookie("cookie_email_id"); res.clearCookie("password"); } And I have check My Cookie in console cookie is set document.cookie : cookie_email_id=abc%40gmail.com; password=123456789 回答1: To pre-fill form inputs through ejs, first of all you need to set the cookies via res.cookie() .To

A Sapper-compatible setup to serve multiple apps from a single Express/Polka entry point

五迷三道 提交于 2021-02-07 12:45:15
问题 I need to set up a Polka (or Express) server so that it can serve multiple applications (one per hostname) from a single server.js entry point. It can be done using the vhost middleware (https://github.com/expressjs/vhost). Each app is exported as a middleware, and the one that corresponds to each request is added in the middleware chain in server.js . However, some (not all) of these apps will be Sapper applications so the setup must be compatible with Sapper. So far as I am aware, Sapper

Inject javascript code into html with Express

本秂侑毒 提交于 2021-02-07 12:21:26
问题 I am writing a web application using Express framework to generate Impress.js presentations and apply a visual editor on them. I have set up the app.js for only getting the .html file but I want to inject a javascript code from a separate file before the body closing tag of the .html file. For example, I will have a route handler /edit and then the script will be triggered after it have been injected into the html code. var express = require('express'); var app = express(); app.configure

Inject javascript code into html with Express

安稳与你 提交于 2021-02-07 12:18:58
问题 I am writing a web application using Express framework to generate Impress.js presentations and apply a visual editor on them. I have set up the app.js for only getting the .html file but I want to inject a javascript code from a separate file before the body closing tag of the .html file. For example, I will have a route handler /edit and then the script will be triggered after it have been injected into the html code. var express = require('express'); var app = express(); app.configure

Insert MongoDB document with React.js

不问归期 提交于 2021-02-07 10:55:20
问题 I was wondering if there's a way to insert documents into a MongoDB collection directly from a React component. My current personal project (for training purpose) is a little chat web application. So for example, when my user wants to post a new message in a room, the input component should look something like this: var NewMessageInput = React.createClass({ postMessage: function(value) { db.collection.insert({ content: value }); }, render: function() { return ( <div> <input onSubmit={() =>

How to extract zip from client in node

会有一股神秘感。 提交于 2021-02-07 10:54:58
问题 I'm having a node app which needs to get some zip file from client Postman and extract it to a folder in my fileSystem,Im using express I did the following which doesnt work, what am I missing here? I've created sample node app to simulate the issue. var express = require('express'); var upload = require('multer')({ dest: 'uploads/' }); var admZip = require('adm-zip'); var app = express(); app.post('/',upload.single('file'),function(req,res){ debugger; var zip = new admZip(req.file); zip

Node.js upload to Azure Blob Storage issues

北战南征 提交于 2021-02-07 10:54:36
问题 I am newer to Node.js/Express and am attempting a simple file upload to Azure blob storage. I am using AngularJS for the front end form. When I attempt to upload a file I receive the following error: TypeError: Cannot read property 'myfile' of undefined I have seen some examples where they are leveraging a node module named multiparty but am unsure if it applies to this basic upload need. Coming from the jQuery/front end JavaScript world, I would need to base64 encode my file for upload in

React POST requests with Express/Node and MongoDB

允我心安 提交于 2021-02-07 10:29:59
问题 I'm writing program that uses React as front-end, and an Express/Node API for the backend which then does CRUD operations in a MongoDB database. Right now, I'm using the native JS fetch() API to perform GET/POST operations on my front end. The GET requests work just fine, but my POST requests seem to not be working. On my front end, I have a form and a handler for form submission like so: handleSubmit(){ let databody = { "name": this.state.nameIn, "quote": this.state.quoteIn } return fetch(