express

TypeError: Cannot read property 'findAll' of undefined (expressjs)

一笑奈何 提交于 2020-01-13 05:09:31
问题 TypeError: Cannot read property 'findAll' of undefined (expressjs). All functions (sequelize) are not working. All errors: Cannot read property 'sequelize method' ... module.exports = function (sequelize, DataTypes) { var User = sequelize.define('user', { email: {type: DataTypes.STRING(32), unique: true, allowNull: false}, }); return User; }; Controller: models = require('./../models'); exports.index = function (request, response, next) { models.User.findAll({attributes: ['id', 'username']});

Redirect page after post request [Express 4]

萝らか妹 提交于 2020-01-13 05:06:29
问题 /** * @api {post} /logout Logout from system * @apiName Logout * @apiGroup Login */ router.post("/logout", function (req, res) { req.logout(); req.session.destroy(); return res.redirect("/"); }); I've read Node.js Express : How to redirect page after processing post request? but could not figure out the answer. I recently changed logout to POST instead of GET. After doing so, redirect does'nt work POST /logout 307 4.912 ms - 36 POST / 302 3.922 ms - 23 GET / 200 7.519 ms - - I can manually do

How and when do I generate a Node/Express cookie secret?

痞子三分冷 提交于 2020-01-13 04:55:06
问题 I'm building a node/express app and am using the express-session and mongo-connect modules to store my sessions and persist them on restart. However, a new cookie ID is still generated every time I restart the server. I've narrowed the problem down to my session secret, which is a randomly generated string of 16 chars Here is my session code: app.use(session({ secret: dbops.randomString(16), // generate a 16 random char string saveUninitialized: false, resave: true, store: new MongoStore({ db

express cookie return undefined

左心房为你撑大大i 提交于 2020-01-13 03:11:08
问题 I'm trying to set cookie on express.js but it return undefined. I've searched many web pages and put express.cookieParser() above app.use(app.router) but it still can't return the right value. app.js app.configure(function(){ var RedisStore = require('connect-redis')(express); app.use(express.logger()); app.set('view options', { layout: false }); app.set('views', __dirname + '/views'); app.set('view engine', 'jade'); app.use(express.bodyParser({uploadDir: './uploads/tmp'})); app.use(express

Node-sass is not auto-compiling in latest node/express

巧了我就是萌 提交于 2020-01-12 19:25:49
问题 Using node (0.10.15) and express (3.3.4), along with the latest node-sass, and I can't get my scss files to compile. My app.js file looks like this: var express = require('express') , routes = require('./routes') , user = require('./routes/user') , http = require('http') , path = require('path') , sass = require('node-sass'); var app = express(); // all environments app.set('port', process.env.PORT || 3000); app.set('views', __dirname + '/views'); app.set('view engine', 'ejs'); app.use

Global scope for every request in NodeJS Express

杀马特。学长 韩版系。学妹 提交于 2020-01-12 19:03:54
问题 I have a basic express server that needs to store some global variables during each request handling. More in depth, request handling involves many operation that need to be stored in a variable such as global.transaction[] Of course if I use the global scope, every connection will share information of its transaction and I need a global scope because I need to access the transaction array from many other modules, during my execution. Any suggestion on this problem? I feel like is something

NodeJS won't serve static files, even when using express.static

一笑奈何 提交于 2020-01-12 17:50:11
问题 I have something along the lines of the following: var request = require('request'), express = require('express'); var app = express.createServer(); var port = process.env.PORT || 8080; app.configure(function(){ app.set("view options", { layout: false, pretty: true }); app.use(express.favicon()); app.use("/public", express.static(__dirname + '/public')); } ); app.listen(port); // Routes app.get('/', function(req, resp){ resp.render('index.jade', {pageTitle: 'Some title'}); }); Yet, when I

The difference between <%=, <% and <%- in ejs [duplicate]

点点圈 提交于 2020-01-12 10:11:09
问题 This question already has answers here : EJS: <%= versus <%- (3 answers) Closed 2 years ago . As I wrote in the title. In Ejs what's the difference between <%= , <% and <%- ? for example I saw this code <% include ../partials/header.ejs %> , and then there is this code <%= title %> . I also saw <%- somewhere but cannot find a code example anywhere. So what's the difference? When do I use which? I found this but it's for ruby on rails Difference between <% %> and <%= %> in RoR 回答1: The

Sequelize findAll is not a function

断了今生、忘了曾经 提交于 2020-01-12 07:51:07
问题 I'm making a project with Sequelize and I'm stucked in this step. The problem is that when I try to log in and the passport-local code is executed, when it reaches the User.findAll(...) it throws that findAll is not a function . If I make console.log(User) it shows [function]. My structure: /config/config.js /config/passport.js /models/index.js /models/nuke_users.js (generated by sequelize-auto) /index.js config.js: //Setting up the config var Sequelize = require('sequelize'); var sequelize =

How to share the same variable between modules?

核能气质少年 提交于 2020-01-12 07:46:09
问题 I'm using Node.JS with Express.js and I need to share a variable between modules, I have to do that because this variable is a pool of mysql connections, This pool creates 3 Mysql connections at the start of Node.js and then I would like that the other modules will use those connections without recreate other pools. Is this possible? Thanks 回答1: There are 2 options: make that variable a global one, for ex: global.MySQL_pool = ... . This way you can access it everywhere by using MySQL_pool as