node.js

Gatsby StaticQuery and Rendered HTML

£可爱£侵袭症+ 提交于 2021-02-11 04:30:43
问题 I'm struggling to find out how <StaticContent> behaves. If I disable javascript in my app, everything inside a <StaticContent> will not be rendered. Is this the intended behavior? There is a way to workaround it? A partial code sample: const Sample = (props: any) => ( <StaticQuery query={graphql` query { site { siteMetadata { siteTitle siteTitleShort } } } `} render={(data) => ( // THIS CODE WILL NOT BE RENDERED IF JAVASCRIPT IS DISABLED // YOU'LL NOT BE ABLE TO FIND IT BY LOOKING INTO THE

Typescript & Mongoose - “this” not available in instance methods

久未见 提交于 2021-02-11 04:29:32
问题 I am currently converting my API from JS to TS. However, I'm having some difficulties with mongoose & typescript. Specifically, this is not available inside my instance methods. My code: AccountSchema.methods.comparePassword = async function (candidatePassword: string) { const isMatch = await bcrypt.compare(candidatePassword, this.password); return isMatch; }; Which generates the following error as this refers to the function rather than the actual document: Argument of type 'Function' is not

Get all data asynchronously using node sqlite3

醉酒当歌 提交于 2021-02-11 02:25:58
问题 I need to get all data using db.all() asynchronously. I do not want to run other functionality/code within the call back. I would like to "export" the results. Is that ok? * Im new to SQLite 😬 * const sqlite3 = require('sqlite3').verbose() const db = new sqlite3.Database('./db/subscribers.db') const createSQLStatement = `CREATE TABLE IF NOT EXISTS subscriptions (id INTEGER PRIMARY KEY AUTOINCREMENT, subscriber TEXT)` db.run(createSQLStatement) exports.getAllSubscribers = async () => { const

Get all data asynchronously using node sqlite3

吃可爱长大的小学妹 提交于 2021-02-11 02:25:08
问题 I need to get all data using db.all() asynchronously. I do not want to run other functionality/code within the call back. I would like to "export" the results. Is that ok? * Im new to SQLite 😬 * const sqlite3 = require('sqlite3').verbose() const db = new sqlite3.Database('./db/subscribers.db') const createSQLStatement = `CREATE TABLE IF NOT EXISTS subscriptions (id INTEGER PRIMARY KEY AUTOINCREMENT, subscriber TEXT)` db.run(createSQLStatement) exports.getAllSubscribers = async () => { const

Python和Java二选一该学啥?

倾然丶 夕夏残阳落幕 提交于 2021-02-11 01:44:10
Java和python犹如北乔峰南慕容,竞争不相上下。如果有能力同时学习那再好不过了,但很多刚刚接触IT行业的小伙伴在学习初期学习困难较大,还是要两者择其优。 下面是对python和Java两个编程语言的对比分析,大家可以酌情参考一下,依据自己的需求来定夺自己要学习哪一门语言。 1、运行速度 Java是静态语言静态编译的,速度上要比Python快的很多,而Python动态类型语言,一边执行一边编译,速度要上慢一些。 2、对Legacy代码的支持 对于legacy代码的支持,由于Java大量的用于电商,互联网后端,银行等大型系统,所以对于legacy的代码的数量要远大于Python。而Python要更轻量级一些,没有那么多legacy的问题。尤其是Py3即将全面推广,Py2要退出历史舞台。 3、代码开发效率 Python代码开发效率非常高,同样的函数功能,Java需要十几行,Python只要几行,代码数量要远小于Java,这样开发的时间和效率比Java高很多。 4、数据库的支持 Java跟数据库结合更紧密一些,有大量的数据库支持Java,类似JDBC这样的封装,使得的Java使用数据库更容易。Python虽然没有他俩关系那么铁,但是目前支持Python的数据库也非常多,而且很多主流数据库SQL,Mongodb,Redis都有API支持Python, 可以说Python不缺的就是库。

NODE_PATH no effect

家住魔仙堡 提交于 2021-02-11 01:11:54
问题 I would like that ~ $ npm install express" will not install express in my home folder, but instead in ~/apps/node_modules . So I inserted this export NODE_PATH=/home/a/apps/node_modules in .bashrc and than I did source .bashrc . Unfortunately, npm install express still installs it in /home/a/node_modules and npm install -g express require root/Administrator. How is it possible that npm install packages in /home/a/apps/node_modules ? 回答1: NODE_PATH is used to find modules, but not to install

“npx create-react-app appname” not working

可紊 提交于 2021-02-10 23:59:26
问题 When I run npx create-react-app appname I get the following error message: You are running `create-react-app` 4.0.0, which is behind the latest release (4.0.1). We no longer support global installation of Create React App. Please remove any global installs with one of the following commands: - npm uninstall -g create-react-app - yarn global remove create-react-app The latest instructions for creating a new app can be found here: https://create-react-app.dev/docs/getting-started/ npm ERR! code

jwt.verify not throwing error for expired tokens

雨燕双飞 提交于 2021-02-10 23:30:12
问题 I'm using JWT - jsonwebtokens in Nodejs. I'm creating a token and want to throw an error if the token expires. My token is created successfully and I'm checking the token expiry in middleware of Apis in Expressjs. Then token is sent from Angular in headers and the expiration is checked in middleware. This is how I'm creating the token: var token = jwt.sign({ id: id, expiresIn: '2m' }, 'mysecretkey' ); This is how my middlware looks like: var token = req.headers['authorization'] var idToken =

jwt.verify not throwing error for expired tokens

余生长醉 提交于 2021-02-10 23:28:55
问题 I'm using JWT - jsonwebtokens in Nodejs. I'm creating a token and want to throw an error if the token expires. My token is created successfully and I'm checking the token expiry in middleware of Apis in Expressjs. Then token is sent from Angular in headers and the expiration is checked in middleware. This is how I'm creating the token: var token = jwt.sign({ id: id, expiresIn: '2m' }, 'mysecretkey' ); This is how my middlware looks like: var token = req.headers['authorization'] var idToken =

Download zip with axios and unzip with adm-zip in memory (electron app)

安稳与你 提交于 2021-02-10 23:28:00
问题 I need to download a file with axios and unzip it in memory in an electron app. I read in some SO threads (e.g.), that adm-zip supports byte buffer constructor, but I can not see this in the docs. When I extract the content, it behaves like the array is empty, but it is not. It just does create a file and does not throw any errors I do not want to use request , as the api is marked deprecated. My code is this: const axios = require("axios"); const AdmZip = require('adm-zip'); const url =