node.js

Angular 10 SSR and expressjs sessions

前提是你 提交于 2021-02-11 13:09:05
问题 I have a component in Angular where I'm using HttpClient to do a GET request to the server to get the currently signed in user. Since this is an SSR app the code runs both on the client and the server. The problem is that when it runs on the server, the session data is not available, which means that the request to the backend can't be authenticated, so it fails. On the client the session data is available so the request succeeds. I use express-session with the following session options:

How to catch “access error” when publish inaccessible topic in mqtt.js?

爷,独闯天下 提交于 2021-02-11 13:07:54
问题 I am creating a project using node.js with mqtt.js and mosquitto broker. In mosquitto config file, I have setup a pwfile, aclfile to control which topic can be accessed by which user. Everything works fine, if the username, password, publish topic and subscribe topic are correct. But if I change the publish topic to an inaccessible topic, it seems successfully publish the topic without any error in mqtt.js, but the message is never been publish. Is there anyway to catch error when publish or

I want to take out the result from mysql's connection.query and save it in global scope chain in nodejs

非 Y 不嫁゛ 提交于 2021-02-11 13:02:14
问题 I tried bringing out result by storing in variable current product. But I cant use it outside the function, so my array returns empty var connection = mysql.createConnection({ host: config.config.mysql.opencart_local.host, user: config.config.mysql.opencart_local.user, password: config.config.mysql.opencart_local.password, database: config.config.mysql.opencart_local.database }) var query_current_products = 'select * from table;'; var current_products = []; connection.connect(function(err) {

JS Can't query MySQL database. ERROR: connection.query is not a function

血红的双手。 提交于 2021-02-11 12:56:58
问题 Trying to query my mySQL database but I can't because i get a TypeError: connection.query is not a function error. Does anyone have any idea why? I don't have any clue as to why this is happening. database.js const fs = require('fs'); // node.js file system module require('dotenv').config(); // stores tokens, keys, passwords and other info const Discord = require('discord.js'); // links discord.js api to file const database = require('./database.js'); const client = new Discord.Client(); //

Dynamically export a module by reading all files in a directory in Node.js

狂风中的少年 提交于 2021-02-11 12:53:28
问题 So today i was trying read all default exports from some directory which has index.js . Try to wrap it inside one object and export it back again. Is there a better way to handle this ? export default (() => require('fs') .readdirSync(__dirname) .filter(fileName => !!/.js$/ig.test(fileName)) .map(fileName => fileName.split('.')[0]) .reduce((defaultExportObj, nextFileName) => { try { return { ...defaultExportObj, [nextFileName]: require(__dirname + `/${nextFileName}`), }; }catch(err) { throw

How to install lastest version of Node and NPM for Linux Debian?

只谈情不闲聊 提交于 2021-02-11 12:50:32
问题 I have a Debian Jessie and latest Node version available with apt is 8.9.0. What's the easy way to install the latest version aka 11.3.0 ? (and the latest NPM also) 回答1: I think easiest way to manage Node.js versions is to use n Installation $ curl -L https://git.io/n-install | bash Usage $ n 11.3.0 #Install node 11.3.0 version $ n latest #Install or activate the latest node release $ n stable #Install or activate the latest stable node release 回答2: The easier way seems to be : INSTALLATION

npm: When to use `--force` and `--legacy-peer-deps`

我是研究僧i 提交于 2021-02-11 12:49:00
问题 I'm new to npm and am trying to understand how recreating the node_modules directory for deployment works. We're using npm ci instead of npm install to ensure a clean slate during deployment. However, when we run it without any flags, we get the following error: Fix the upstream dependency conflict, or retry this command with --force, or --legacy-peer-deps to accept an incorrect (and potentially broken) dependency resolution. The documentation for npm install for --force is as follows (there

Trying to access FirestoreAdminClient from Cloud Run service using firebase-admin. ERROR: 7 PERMISSION_DENIED: The caller does not have permission

╄→尐↘猪︶ㄣ 提交于 2021-02-11 12:47:29
问题 I've got the following code for a an API endpoint that is supposed to trigger a Firestore backup using firebase-admin . This is how I'm initializing firebase-admin ; import * as admin from "firebase-admin"; admin.initializeApp({ credential: admin.credential.cert( SERVICE_ACCOUNT as admin.ServiceAccount )}); The service account key is a JSON I've downloaded using the default firebase-admin service account: This is the backup.ts API request handler. export const backupData: RequestHandler =

Something went wrong installing the “sharp” module, using node-loader in webpack

狂风中的少年 提交于 2021-02-11 12:47:08
问题 I use sharp and webpack with node-loader but I got this error: D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:150011 throw new Error(error); ^ Error: Something went wrong installing the "sharp" module node-loader: Error: The specified module could not be found. D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server/33c1e48f049ce3285905e286d212a201.node - Remove the "node_modules/sharp" directory then run "npm install --ignore-scripts=false -

How to delete user from Auth0 on Next.js?

烂漫一生 提交于 2021-02-11 12:47:01
问题 I can login and logout users on Next.js after reading these resources amongst others: The Ultimate Guide to Next.js Authentication with Auth0 @auth0/nextjs-auth0 library API Call Example SPA + API: Node.js Implementation for the API But nowhere could I find out if I can delete users using the auth0/nextjs-auth0 library. I also looked into the module's handlers here. Am I right to think there is no way to delete a user using the @auth0/nextjs-auth0 library? If yes, what is the most preferred