express

Sequelize hasMany is working fine but the inverse relation is not working

血红的双手。 提交于 2021-02-11 15:52:48
问题 I am trying to work with mysql relations in Node Js(express Js) using Sequelize. User.hasMany(Post); work just fine, but when i try to inverse it in Post model like: Post.belongsTo(User); got this error: throw new Error(${source.name}.${_.lowerFirst(Type.name)} called with something that's not a subclass of Sequelize.Model); Error: post.belongsTo called with something that's not a subclass of Sequelize.Model User model like: const Sequelize = require('sequelize'); const db = require('..

run pm2 logs error SyntaxError: Unexpected token

别等时光非礼了梦想. 提交于 2021-02-11 15:49:54
问题 I want to see logs of my project Steps : I clone a socket app. Then I run npm install pm2 -g to install pm2 I run pm2 start It works. It display a table of my socket app But if I run pm2 logs to see logs, there exist error like this : 1|mycompany | C:\PROGRAM FILES\NODEJS\NPM.CMD:1 1|mycompany | (function (exports, require, module, __filename, __dirname) { :: Created by npm, please don't edit manually. 1|mycompany | ^ 1|mycompany | 1|mycompany | SyntaxError: Unexpected token : 1|mycompany |

Disable middleware when redirecting

让人想犯罪 __ 提交于 2021-02-11 15:31:14
问题 I have a isAdmin middleware, and there's a page in my website where I want to disable this isAdmin middleware and let the user go to the page /admin/register, how can I disable the isAdmin middleware in a redirect? return res.redirect('/admin/register'); Midlleware : router.all('/admin/*', isAdmin, (req, res, next) => { res.render('validatePassword', {message: 'Please re-enter your password to get access to ' + req.originalUrl, redirectRoute: req.originalUrl}); // next(); }); router.get('

How to download files from node express server?

只愿长相守 提交于 2021-02-11 15:23:40
问题 I have a file on my server (Node.js + Express). I need to download file from server to computer of user. in React app I call the function which would download file: downloadFileFromServer(file) { // file -- name of file fetch(`${Config.baseUrl}/download-file/${this.props.params.idEvent}/${file}`, { method: 'GET' }) .then((response) => { if (response.status >= 400) { throw new Error('Bad response from server'); } return response; }); } On backend I have this route: app.route('/download-file/

Cookie set on root domain not available to subdomain - what am I doing wrong?

戏子无情 提交于 2021-02-11 15:14:29
问题 Client hosted on subdomain.example.com makes api call to example.com to fetch a cookie. The response has a Set-cookie header and I see the cookie as being returned alright: However, I don't see the cookie saved in the Browser (Chrome, Firefox, Edge) and, as a result, is not sent as a header in subsquent API requests: Set-cookie domain attribute is set to .example.com , but as I read in MDN I think the trailing dot gets ignored. The cookie in question, by the way, is the csrf token secret set

Express Route (Optional parameters)

☆樱花仙子☆ 提交于 2021-02-11 15:14:28
问题 I have a problem getting my route to work. I have based the route organisation on : Organizing your app routes with the Express 4 Router Here is app.js : var express = require('express'); var router = express.Router(); express.use('/object-settings', require("./route/object-settings"); express.use('/object-settings-edit', require("./route/object-settings-edit"); Now the file object-settings var express = require('express'); var router = express.Router(); router.get('/', function (req, res) {

Mongo Call does not remove parameters

守給你的承諾、 提交于 2021-02-11 15:06:25
问题 Im using node with mongo, and I want for the mongo get call to stop returning some values, such as _id and uid. Everything that ive read says that this call should work, but when I print the json value on my UI, it still has those values. app.get('/users', async function(req, res){ console.log("Getting User Info!"); await client.connect(); const db = client.db('database'); var uidparam = req.header("uid"); db.collection("users").findOne({"uid": uidparam}, { _id: 0, uid: 0, }, function(err,

Mongo Call does not remove parameters

假如想象 提交于 2021-02-11 15:04:22
问题 Im using node with mongo, and I want for the mongo get call to stop returning some values, such as _id and uid. Everything that ive read says that this call should work, but when I print the json value on my UI, it still has those values. app.get('/users', async function(req, res){ console.log("Getting User Info!"); await client.connect(); const db = client.db('database'); var uidparam = req.header("uid"); db.collection("users").findOne({"uid": uidparam}, { _id: 0, uid: 0, }, function(err,

Node.JS Firebase Auth - Is there a way to keep a user session like with client side Firebase Auth?

[亡魂溺海] 提交于 2021-02-11 14:59:52
问题 I am learning Node.JS and I am trying to bring Firebase Auth into my application. With client-side firebase auth, you can just do firebase.auth().currentUser but in node, as the script is not run on the client, but once on the server, you cannot use firebase.auth().currentUser . Is there a way involving sessions or cookies (I think) to get user data and use normal Firebase Auth operations from node just like client side Firebase Auth? (I am using express with Node) 回答1: As you've found there

Using `mongoose transactions` when saving message in two collections in mongodb

我是研究僧i 提交于 2021-02-11 14:54:36
问题 If the student sends a message to the teacher, the message is saved in the teachers and students collections. The same situation is when a teacher sends a message to the student, they are also save in the two collections teachers and students . How can I apply mongoose transaction in the following code so that the message is saved in two collections.I don' want a situation that the message will be saved in one collection and in the other collection will not be saved due to an error. I am