我正在使用本教程为我的项目学习 GraphQL:https : //www.youtube.com/watch?v= ZQL7tL2S0oQ&ab_channel=WebDevSimplified
我得到错误:
TypeError: expressGraphQL is not a function
at Object.<anonymous>
Run Code Online (Sandbox Code Playgroud)
我已经尝试过:
现在的代码如下所示:
const express = require ('express')
const { expressGraphQL } = require('express-graphql')
const app = express();
app.use('/graphql', expressGraphQL({
graphiql: true,
})
)
app.listen(5000., () => console.log('Server Running'))
Run Code Online (Sandbox Code Playgroud)
如果我注释掉这一部分:
app.use('/graphql', expressGraphQL({
graphiql: true,
})
)
Run Code Online (Sandbox Code Playgroud)
无论使用 {} 括号还是不使用括号,代码都可以正常工作。
我可以使用nodemon来lint我的javascript吗?我没有使用任何构建工具,例如gulp或grunt,并且想要最大化节点和npm的使用.
nodemon的输出可以通过管道输出.我想使用它来使用eslint来修改已更改的文件.
这是我的package.json
{
"name": "app",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "nodemon server.js",
"lint": "eslint"
},
"dependencies": {
"MD5": "*",
"clean-css": "*",
"express": "~4.9.0",
"express-handlebars": "~2.0.1",
"express-redis-cache": "*",
"foundation-sites": "~5.5.3",
"fs-extra": "~0.8.1",
"node-rest-client": "~1.5.1",
"node-sass": "*",
"path": "*"
},
"devDependencies": {
"babel-eslint": "^4.1.6",
"eslint": "^1.10.3",
"eslint-config-airbnb": "^2.1.1",
"eslint-config-airbnb-es5": "^1.0.8",
"eslint-plugin-react": "^3.13.1",
"nodemon": "~1.8.1",
"parallelshell": "~2.0.0",
"watch": "~0.17.1"
}
}Run Code Online (Sandbox Code Playgroud)
我试过这个.但它不起作用.它给出了错误.
"scripts": {
"start": "nodemon({ script: 'server.js' }).on('restart', function () {console.log('nodemon started');}).on('crash', function () {console.log('script crashed for some …Run Code Online (Sandbox Code Playgroud) 我正在尝试改善我的节点中的DEV体验.为此,我想:
a)在更改服务器端代码时重新启动服务器
b)在客户端代码更改时刷新浏览器.
为了实现这一目标,我开始将nodemon和browserSync集成到我的gulp脚本中.
在我的gulp脚本中,我有以下任务:
gulp.task('startDevEnv', function(done) {
// Begin watching for server-side file changes
nodemon(
{ script: input.server, ignore:[input.views] })
.on('start', function () {
browserSync.init({
proxy: "http://localhost:3002"
});
})
;
// Begin watching client-side file changes
gulp.watch([ input.css, input.js, input.html ], function() { browserSync.reload(); });
done();
});
Run Code Online (Sandbox Code Playgroud)
运行上述任务后,我的浏览器将打开http:// localhost:3000 /.我的应用程序按预期显示.但是,在控制台窗口中,我注意到:
Error: listen EADDRINUSE :::3002
Run Code Online (Sandbox Code Playgroud)
我在某种程度上理解.我有app.set('port', process.env.PORT || 3002);我的server.js文件.然而,我认为这是设置代理值的目的.不过,每当我进行代码更改时,我在控制台窗口中都会看到以下相关错误:
[07:08:19] [nodemon] restarting due to changes...
[07:08:19] [nodemon] starting `node ./dist/server.js` …Run Code Online (Sandbox Code Playgroud) 在通用Javascript应用程序中,我希望nodemon忽略客户端目录更改.
我尝试过以下方法:
"devStart": "nodemon server/server.js --ignore 'client/*' --exec babel-node",
"devStart": "nodemon server/server.js --ignore 'client/' --exec babel-node",
"devStart": "nodemon server/server.js --ignore client/ --exec babel-node",
"devStart": "nodemon --ignore 'client/*' server/server.js --exec babel-node",
"devStart": "nodemon --ignore 'client/' server/server.js --exec babel-node",
"devStart": "nodemon --ignore client/ server/server.js --exec babel-node",
Run Code Online (Sandbox Code Playgroud)
这些都不起作用.
文件结构:
+-server
+-client
+-package.json <------- where nodemon script is
Run Code Online (Sandbox Code Playgroud)
但这不起作用.很确定这是一个模式问题.
有任何想法吗?
在使用webpack配置Web应用程序以创建最佳开发体验时,我仍然是一个新手.我参加了两个不同的Node-React课程; 我们使用nodemon跟踪更改的另一个,以及我们实现热重新加载的另一个.
当谈到这两个依赖关系时,它是一个还是另一个?它们应该一起使用,还是有点多余?
另外,如果我在客户端使用带有React的快速服务器,我是否使用react-hot-loader,webpack-hot-middleware或两者兼而有之?我对使用热重新加载采用哪种方法感到困惑,因为似乎有很多方法可以做到这一点.
此外,当我使用nodemon作为包装器(nodemon --exec babel-node server.js)时,我的热模块重新加载不起作用,但我仍然发现自己想要一种轻松重启服务器的方法.
多谢你们.
我希望在使用命令保存的每个文件上编译我的打字稿文件tsc。
如何将 tsc 命令与 nodemon 在build:live脚本中运行的命令结合使用
"scripts": {
"start": "npm run build:live",
"build:live": "nodemon --watch '*.ts' --exec 'ts-node' app.ts",
}
Run Code Online (Sandbox Code Playgroud)
此脚本会导致 nodemon 调用自身两次或三次:
"build:live": "nodemon --watch '*.ts' --exec 'ts-node app.ts & tsc'",
Run Code Online (Sandbox Code Playgroud) 在本地处理 NodeJS 项目时,需要使用 nodemon 来简化编码。我经常看到仅作为开发依赖项安装的情况,所以我想知道:部署时正确的方法是什么?我们应该仅将其作为开发依赖项包含在内,还是也应该将其包含到服务器中?
在这个项目中,我看到 nodemon 作为常规依赖项安装,然后在 package.json 配置中:
"scripts": {
"start": "nodemon src/app.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
Run Code Online (Sandbox Code Playgroud)
但我想仅将其安装为开发依赖项,然后重新配置配置,例如:
"scripts": {
"start-prod": "node src/app.js",
"start-dev": "nodemon src/app.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
Run Code Online (Sandbox Code Playgroud)
所以我想知道这是否是正确的方法?我不明白为什么在服务器上我会用 nodemon 观察文件更改,所以我想知道我是否做对了?如果有时需要的话,什么情况下可能会需要呢?
使用package.json中的行为Windows 10上的nodejs项目运行测试:
"test": "nodemon --exec 'mocha -R min'"
Run Code Online (Sandbox Code Playgroud)
我明白了:
> nodemon --exec 'mocha -R min'
[nodemon] 1.11.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `'mocha -R min'`
''mocha' is not recognized as an internal or external command,
operable program or batch file.
[nodemon] app crashed - waiting for file changes before starting...
rs
[nodemon] starting `'mocha -R min'`
''mocha' is not recognized as an internal or external command,
operable program or batch …Run Code Online (Sandbox Code Playgroud) 我需要这样的东西:
节点mon.json:
[{
"watch": ["src/api-gateway"],
"ext": "ts",
"ignore": ["src/**/*.spec.ts"],
"exec": "ts-node ./src/api-gateway/main.ts"
},
{
"watch": ["src/services/ping-service"],
"ext": "ts",
"ignore": ["src/**/*.spec.ts"],
"exec": "ts-node ./src/services/ping-service/ping-service.ts"
}]
Run Code Online (Sandbox Code Playgroud)
这可能吗,或者是否有其他方法可以做到这一点?
nodemon ×10
node.js ×9
javascript ×5
typescript ×2
browser-sync ×1
eslint ×1
graphql ×1
graphql-js ×1
gulp ×1
mocha.js ×1
module ×1
npm ×1
reactjs ×1
reload ×1