英文:
How can I launch node server and open localhost in the browser after there?
问题
以下是翻译好的部分:
我有一个简单的Node.js项目和在Bash中的脚本。在启动服务器之前,我使用了一些命令,之后我需要在本地打开浏览器。
Bash脚本:
nodemon server.js
xdg-open https://localhost:3007
我该如何在启动Node服务器后打开本地主机中的浏览器?
英文:
I have the simple node.js project and script on the bash. I use a few commands before launching the server and after there I need to open browser on the localhost.
bash script:
nodemon server.js
xdg-open https://localhost:3007
How can I launch node server and open localhost in the browser after there?
答案1
得分: 0
安装 open 模块:
npm install open
在 server.js 中添加:
const open = require('open');
open('http://localhost:3007');
启动项目:
npm start
Node 服务器已启动,并在 http://localhost:3007 上打开浏览器。
英文:
Install open module:
npm install open
Add to the server.js:
const open = require('open');
open('http://localhost:3007');
Launch project:
npm start
Node server was started and open browser on the http://localhost:3007
答案2
得分: 0
你可以在后台打开 nodemon
,然后打开浏览器:
nodemon server.js &
xdg-open https://localhost:3007
或者作为一行,没有任何区别:
nodemon server.js & xdg-open https://localhost:3007
英文:
You can open nodemon
in the background and then open the browser:
nodemon server.js &
xdg-open https://localhost:3007
Or as a single line, it doesn't make any difference:
nodemon server.js & xdg-open https://localhost:3007
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论