简体   繁体   English

如何在不进入终端并键入 node app.js 的情况下重新加载 node.js 应用程序

[英]How to reload node js application without going to terminal and typing node app.js

--------------This code is written in app.js-------------- --------------这段代码是用app.js写的----------------

const Anime_Images = require("anime-images-api");
const API = new Anime_Images();
getNSFWImg();
async function getNSFWImg() {
  let { image } = await API.nsfw.hentai();
app.get("/hent", function (req, res) {
    res.render("list", {
      Ejs: image,
    });
  });
}

-------------This is my list.ejs file--------------- --------------这是我的list.ejs文件----------------

<body>
    <img src="<%=Ejs%>">

</body>

This is the code I want to run.这是我要运行的代码。

When I write node app.js in terminal it shows me a Image on web at http://localhost:3000/hent.当我在终端中编写 node app.js 时,它会在 web 上显示一个图像,地址为 http://localhost:3000/hent。

But to see new Image I need to write node app.js in terminal again and again.但是要查看新图像,我需要在终端中一次又一次地编写 node app.js。

Is there any other way or a button on webpage I can set and when I tap the button it show me new image without me typing node app.js in terminal.我可以设置网页上的任何其他方式或按钮吗?当我点击按钮时,它会显示新图像,而无需在终端中键入 node app.js。

Note:I have already required all the modules in app.js注意:我已经需要 app.js 中的所有模块

to do this you can use a command line tool called "Nodemon" https://www.npmjs.com/package/nodemon .为此,您可以使用名为“Nodemon”的命令行工具https://www.npmjs.com/package/nodemon Once you have installed it you just run $ Nodemon this will run like running $ node.一旦你安装了它,你只需运行$ Nodemon这将像运行$ node. however when there is a chaange to a file in the current directory it will restart the app.但是,当当前目录中的文件发生变化时,它将重新启动应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM