草庐IT

global_env

全部标签

node.js - process.cwd() 与 process.env.PWD 有什么区别?

Both"returnthecurrentworkingdirectoryoftheprocess".您似乎可以覆盖process.env.PWD的值,但它不会更改process.cwd()的返回值。 最佳答案 PWD是进程启动时的当前工作目录,但它是常量。process.cwd()向底层系统询问进程的当前目录,可以通过process.chdir()更改。PWD也是一个POSIX环境变量,这意味着它不能在Windows上工作。process.cwd()另一方面,会。 关于node.js-

node.js - Node : use eventEmitter object globally

假设我有3个公开的功能:用户、帖子、文章所有这些都需要将消息发送到一个名为mediator的文件,其中设置了所有事件。目前我在这样做时遇到了麻烦在中介文件中我有这样的东西:varEventEmitter=require('events').EventEmitter;,pubsub=newEventEmitter();exports.pubsub=newEventEmitter()pubsub.on('loggedIn',function(msg){console.log(msg);});在用户、帖子和文章功能中。像这样:varmediator=require('../config/me

node.js - Node : use eventEmitter object globally

假设我有3个公开的功能:用户、帖子、文章所有这些都需要将消息发送到一个名为mediator的文件,其中设置了所有事件。目前我在这样做时遇到了麻烦在中介文件中我有这样的东西:varEventEmitter=require('events').EventEmitter;,pubsub=newEventEmitter();exports.pubsub=newEventEmitter()pubsub.on('loggedIn',function(msg){console.log(msg);});在用户、帖子和文章功能中。像这样:varmediator=require('../config/me

node.js - 将 ApolloClient 与 node.js 一起使用。 "fetch is not found globally and no fetcher passed"

我正在尝试在node.js服务器上使用Apollo客户端来使用以下代码与另一个GraphQLAPI进行交互:importfetchfrom'node-fetch'import{createHttpLink}from'apollo-link-http'importApolloClientfrom'apollo-boost'import{API_URL}from'...'constclient=newApolloClient({link:createHttpLink({uri:API_URL,fetch:fetch,}),})这会产生以下错误:moduleinitializationerr

node.js - 将 ApolloClient 与 node.js 一起使用。 "fetch is not found globally and no fetcher passed"

我正在尝试在node.js服务器上使用Apollo客户端来使用以下代码与另一个GraphQLAPI进行交互:importfetchfrom'node-fetch'import{createHttpLink}from'apollo-link-http'importApolloClientfrom'apollo-boost'import{API_URL}from'...'constclient=newApolloClient({link:createHttpLink({uri:API_URL,fetch:fetch,}),})这会产生以下错误:moduleinitializationerr

node.js - Node 脚本可执行文件在 Mac : env: node\r: No such file or directory 上不起作用

我已经创建了我的Node脚本可执行文件来执行一些任务。在Windows上,我的Node脚本运行良好。但在MacOSX(Yosemite)上,它不起作用。我的Node脚本已在Windows上发布。我的Node脚本是通过npm命令安装的:npminstall-gtask-app我的Node脚本有这第一行:#!/usr/bin/envnode我尝试了许多解决方案来解决我的问题,但我仍然卡住了。这是我使用的这些解决方案:卸载并重新安装Node.js执行此命令为Node创建链接:sudoln-s/usr/bin/nodejs/usr/local/bin/node使用以下命令设置我的路径:expo

node.js - Node 脚本可执行文件在 Mac : env: node\r: No such file or directory 上不起作用

我已经创建了我的Node脚本可执行文件来执行一些任务。在Windows上,我的Node脚本运行良好。但在MacOSX(Yosemite)上,它不起作用。我的Node脚本已在Windows上发布。我的Node脚本是通过npm命令安装的:npminstall-gtask-app我的Node脚本有这第一行:#!/usr/bin/envnode我尝试了许多解决方案来解决我的问题,但我仍然卡住了。这是我使用的这些解决方案:卸载并重新安装Node.js执行此命令为Node创建链接:sudoln-s/usr/bin/nodejs/usr/local/bin/node使用以下命令设置我的路径:expo

node.js - 错误 : Couldn't find preset "react" when installed using npm install --global babel-preset-react but works without global flag

我使用npminstall--globalbabel-cli安装了BabelCLI(版本6)。然后我使用npminstall--globalbabel-preset-react安装react预设。然后我将项目目录中的.babelrc文件设置为{"presets":["react"]}当我尝试构建JSX文件时,它失败了Error:Couldn'tfindpreset"react"atOptionManager.mergePresets(/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformat

node.js - 错误 : Couldn't find preset "react" when installed using npm install --global babel-preset-react but works without global flag

我使用npminstall--globalbabel-cli安装了BabelCLI(版本6)。然后我使用npminstall--globalbabel-preset-react安装react预设。然后我将项目目录中的.babelrc文件设置为{"presets":["react"]}当我尝试构建JSX文件时,它失败了Error:Couldn'tfindpreset"react"atOptionManager.mergePresets(/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformat

javascript - Mongoose - 为什么我们在设置 mongoose 模块时会生成 "mongoose.Promise = global.Promise"?

我正在与Mongoose合作。我见过很多开发者发出以下命令:mongoose.Promise=global.Promise;然后我很好奇mongoose.Promise的原始值是什么。我在编辑器中输入了以下命令:constmongoose=require("mongoose");console.log("promise:",mongoose.Promise);我的控制台返回了我:promise:functionPromise(){[nativecode]}好的,既然Mongoose的promise已经返回了本地代码,为什么还要创建命令mongoose.Promise=global.Pr