如何运行多个js服务器 [英] How to run multiple js servers

查看:57
本文介绍了如何运行多个js服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在为 discord 开发一个 discord bot,为了运行该 bot,我有几个不同的文件.在此过程中,我遇到了一些问题,但最终都得到了相同的修复,或者至少是我能想到的唯一修复.解决方法是,我可以使用 nodemon ( 如果没有显示,请不要知道如何格式化这些东西)每当我在 Visual Studio 中保存代码时,它都会重新启动并加载新代码.

我对编码和类似的东西还是有点陌生​​,所以如果我的术语不合适,我深表歉意.如果我确实错误地使用了一个术语并且您对此感到困惑/有疑问,请发表评论,我会尽力解释我的意思.

感谢您花时间阅读本文.

解决方案

您可以同时使用parallel 以使其跨平台

并发示例:

package.json

<代码>{脚本":{"serve": "nodemon index.js","logs": "nodemon logs.js","start": "同时\"npm:serve\" \"npm:logs\""},开发依赖":{"同时": "^5.0.0",}}

您可能需要查看 VSCode 复合任务

这是一个示例设置

I'm developing a discord bot for discord at the moment, and to run the bot, I have a few different files. I've run into some problems along the way that all ended up having the same fix, or at least the only fix that I could come up with. That fix would be, instead of running them in my main file (index.js), I could just run 3 separate batch files using nodemon (https://www.npmjs.com/package/nodemon). I currently have 3 batch files to do so. Those batch files look like this:

nodemon index.js
pause

This would be for the main file.

nodemon logs.js
pause

This would be for the file that logs messages.

nodemon welcome and goodbye.js
pause

And this would be for the welcome and goodbye logs.

The only issue is, is that it clutters up my desktop with 3 different prompts, making it confusing as to what does what. I was wondering if it'd be possible with nodemon (or any other npm like this) for me to run all 3 of those batch files in one single command prompt.

And of course I'm open to other npms, but if I'd have to use another one, please include a way for it to automatically restart the server when I save the file in it as well (if possible). Since that's the main reason I like nodemon. I'd also like to be able to use a command prompt/batch file rather than the Visual Studio Code terminal.

If you're wondering what I mean when I say, "...automatically restart the server when I save the file," . (https://imgur.com/a/rw2Qagp if it doesn't show, don't know how to format this stuff) Whenever I save my code in Visual Studio it will restart and load the new code.

I'm still a little new to coding and stuff like that, so if my terminology is off I do apologize. If I did use a term incorrectly and you are confused/have a question about it, leave a comment and I will do my best too explain what I mean.

Thank you for taking time to read this.

解决方案

You can use concurrently or parallel in order to make it cross platform

example with concurrently:

package.json

{
  "scripts": {
    "serve": "nodemon index.js",
    "logs": "nodemon logs.js",
    "start": "concurrently \"npm:serve\" \"npm:logs\""
  },
  "devDependencies": {
    "concurrently": "^5.0.0",
  }
}

Edit: you may want to take a look at the VSCode Compound tasks

Here's an example setup

这篇关于如何运行多个js服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆