我需要这样的东西:
节点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 配置。我正在修复我继承的这个遗留 node 7 项目,并试图让开发过程变得有点痛苦。首先,一个适当的重启和转换过程(因为它是使用 ES6 模块语法构建的)。
这是我的文件夹结构:
- src
|- index.js
- dist
|- index.js
- index.js
- nodemon.js
Run Code Online (Sandbox Code Playgroud)
我运行 nodemon 作为 "start:dev": "nodemon index.js"
这是它的内容:
// index.js
if (process.env.NODE_ENV === 'production') {
require('./dist/index.js');
} else {
require('babel-register')({});
require('babel-polyfill');
require('./src/index.js');
}
Run Code Online (Sandbox Code Playgroud)
这个想法是代码在运行时被转换,这样我就不必像以前那样手动停止服务器、重新转换、启动服务器。
最后但并非最不重要的是,nodemon 配置
// nodemon.js
{
"restartable": "rs",
"ignore": [
".git",
"node_modules/**/node_modules"
],
"verbose": true,
"watch": [
"src"
],
"env": {
"NODE_ENV": "development"
},
"ext": "js json"
}
Run Code Online (Sandbox Code Playgroud)
我从MERN获得了这个设置,我认为它应该可以工作。但是,当我进行更改并保存时,它会显示:
[nodemon] files triggering change …Run Code Online (Sandbox Code Playgroud) Heroku与Node.js使用Mac我的问题:
State changed from starting to crashed &&
sh: 1: nodemon: not found &&
Failed at...start script &&
status 1...code=H10
Run Code Online (Sandbox Code Playgroud)
After creating my front-end, with React, back-end server, with node.js/express.js, and database, with PostgreSQL, I attempted to deploy my server on Heroku with Git. Since I already had Git, I moved onto Heroku CLI
First, from the terminal in my server...
brew install heroku/brew/heroku
heroku create
git …Run Code Online (Sandbox Code Playgroud) 可以使用这样的调试参数运行节点
$ node --debug src/file.js
Run Code Online (Sandbox Code Playgroud)
我也可以通过这样的咖啡脚本二进制传递该参数
$ coffee --nodejs --debug src/file.coffee
Run Code Online (Sandbox Code Playgroud)
哪个有效.但是当我让主管参与时,事情变得更加困难.运行咖啡脚本没问题:
$ supervisor -w src src/file.coffee
Run Code Online (Sandbox Code Playgroud)
但是我想调试我和主管一起运行的咖啡脚本.我如何--debug通过主管发送论据?我尝试将可执行文件设置为带有如下参数的字符串:
$ supervisor -w src -x "coffee --nodejs --debug" src/server.coffee
Run Code Online (Sandbox Code Playgroud)
这产生了无限重复的错误信息
DEBUG: Starting child process with 'coffee --nodejs --debug src/server.coffee' DEBUG: execvp(): No such file or directory
这很奇怪,因为coffee --nodejs --debug src/server.coffee在终端中运行起作用.
那么如何通过主管发送论据呢?
编辑:我想扩展我的问题,提到我现在也尝试使用 nodemon.似乎 nodemon被认为比 node-supervisor更受欢迎,所以我会接受任何解释--debug当通过 nodemon启动coffee脚本时如何传递给节点进程的答案
编辑:这是 nodemon的输出.显然,参数不会以相同的顺序传递:-( …
我已经开始玩Koa,但到目前为止一直无法找到一个合适的解决方案,可以在代码更改时自动重新加载应用程序.
我的理解是nodemon是Node宇宙中的首选解决方案,但由于--harmony标志(Koa要求)我得到错误:
$ node_modules/.bin/nodemon /path/to/node-unstable/bin/node app.js
/path/to/node-unstable/bin/node --harmony $@
^^^^^^^
SyntaxError: Unexpected identifier
[nodemon] app crashed - waiting for file changes before starting...
Run Code Online (Sandbox Code Playgroud) 在我正在使用的package.json中
"scripts": {
"start": "node app.js"
},
Run Code Online (Sandbox Code Playgroud)
但是如果我使用nodemon替换为node app.js
"scripts": {
"start": "nodemon app.js"
},
Run Code Online (Sandbox Code Playgroud)
那会发生什么呢?因为当我在服务器端遇到任何错误时,其他API也会关闭。因此,我认为发生这种情况是因为如果我使用nodemon app.js,那么我将使用node app.js,那么服务器是否会重启。
在我的package.json中,我有一个启动脚本,我正用于我的开发环境.它看起来像这样:
"scripts": {
"dev": "NODE_PATH=src nodemon --watch src/ --exec babel-node src/app.js"
}
Run Code Online (Sandbox Code Playgroud)
当我击中npm run dev一切时,一切正常,巴贝尔正在发现应有的一切,并且nodemon开始观看.我看到了这个:
[nodemon] 1.11.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: /Users/Jonathan/Documents/swissnet/src/**/*
[nodemon] starting `babel-node src/app.js`
Run Code Online (Sandbox Code Playgroud)
当我在src/-folder节点中保存文件时,将重新启动服务器.但这是我的问题,它重启2-3次......每次我保存一个文件,它看起来像这样:
[nodemon] restarting due to changes...
[nodemon] starting `babel-node src/app.js`
[nodemon] restarting due to changes...
[nodemon] starting `babel-node src/app.js`
[nodemon] restarting due to changes...
[nodemon] starting `babel-node src/app.js`
Run Code Online (Sandbox Code Playgroud)
如果我输入"rs",那么nodemon会按预期重启一次.
我不知道如何解决这个问题,甚至不知道在哪里寻找答案.我试过去谷歌吧.我一直在访问github上的软件包的bug部分...(也许我只是在google搜索).
这是我为同一个问题找到的唯一链接,但它似乎没有答案:Nodemon在使用babel时多次运行保存.
无论如何我尝试了他的脚本,NODE_PATH=src nodemon src --exec babel -w src/ --out-dir build/ --source-maps …
跑步nodemon --inspect index.js还是nodemon --debug index.js不行.
节点版本:8.9.1
Nodemon版本:1.12.6
我试过这些没有运气:
nodemon --inspect-brk index.js
nodemon -- --inspect index.js
nodemon index.js -- --inspect index.js
nodemon index.js -- --debug index.js
nodemon -- --debug index.js
nodemon --inspect --debug index.js
nodemon --debug-brk index.js
但是node --inspect index.js还是node --inspect-brk index.js有效的.我好奇怎么样?如果任何替代方案或某种形式的解决方案也会很棒.
如果您需要进一步说明,请评论.
我是 Web 开发的新手,我有一个托管服务,我想在其上部署 reactjs/node 项目。为了之前部署它,我只是上传了从运行npm run build. 从那以后,我使用 MERN 堆栈添加了到 mongodb 数据库的连接。
使用create-反应,应用该项目最初创建,然后设置我的后端节点/ MongoDB的下面这个教程:https://appdividend.com/2018/11/11/react-crud-example-mern-stack-tutorial / . 我的所有服务器代码都包含在 api 文件夹中的项目文件夹中。
我可以通过运行npm start, nodemon server.js(来自 api 文件夹)并连接到终端中的 mongodb 在本地主机上运行该项目。当我尝试以与之前相同的方式从托管服务运行它时,它说它无法连接到数据库,我认为这是由于连接未在我的机器上打开。
目前,所有 API 调用都使用 axios post 到http://localhost:4000/,我也假设它在服务器上不起作用。我在网上查找了有关部署 MERN 堆栈的信息,但我发现的所有信息都在 AWS EC2 上进行了托管,这不是我将要做的。
我如何能够部署到我的托管服务?是否有任何参考资料或我应该寻找此信息的地方?
编辑:我已经使用 MongoAtlas 连接到数据库,所以我使用的是 SRV 地址。我认为问题是使用本地主机地址的 axios 帖子,因为服务器上的应用程序只有在我的本地机器上运行 nodemon 时才有效。我应该使用什么地址而不是这个地址?
大家好,我是 Node js 新手,当我尝试在 Node js 中附加我的文件时,我收到错误,不知道出了什么问题,请尝试修复我的错误,并告诉我应该做什么?
console.log("Starting app.js");
const fs = require('fs');
const os = require('os');
const notes = require('../notes-node/notes.js');
var user = os.userInfo();
fs.appendFile('message.txt', `Hello ${user.username}! You are ${notes.age}`)
console.log(user);
Run Code Online (Sandbox Code Playgroud) node.js ×10
nodemon ×10
debugging ×2
javascript ×2
babel ×1
babel-node ×1
coffeescript ×1
deployment ×1
express ×1
heroku ×1
koa ×1
macos ×1
mern ×1
npm ×1
reactjs ×1
typescript ×1