`npm start` & 之间的区别`node app.js`,当启动应用程序时? [英] Difference between `npm start` & `node app.js`, when starting app?

查看:33
本文介绍了`npm start` & 之间的区别`node app.js`,当启动应用程序时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用命令 express new 'filename' 安装了一个应用程序.我刚刚了解到您可以使用以下方法启动应用程序:

I have installed an application using the command express new 'filename'. I have just learned that you can start an application using:

npm start

到目前为止我已经使用过:

Thus far I have used:

node app.js

启动我的服务器.有谁知道这两者有什么区别?谢谢.

to start my server. Anyone know what the difference is between the two? Thanks.

推荐答案

来自手册页, npm 启动:

From the man page, npm start:

运行包的启动"脚本(如果提供).如果未指定版本,则启动活动"版本.

runs a package's "start" script, if one was provided. If no version is specified, then it starts the "active" version.

诚然,该描述完全没有帮助,仅此而已.至少它比 socket.io 有更多的文档.

Admittedly, that description is completely unhelpful, and that's all it says. At least it's more documented than socket.io.

无论如何,真正发生的是 npm 在您的 package.json 中查找文件,如果你有类似的东西

Anyhow, what really happens is that npm looks in your package.json file, and if you have something like

"scripts": { "start": "coffee server.coffee" }

"scripts": { "start": "coffee server.coffee" }

然后它就会这样做.如果 npm 找不到您的启动脚本,则默认为:

then it will do that. If npm can't find your start script, it defaults to:

节点 server.js

node server.js

 

这篇关于`npm start` & 之间的区别`node app.js`,当启动应用程序时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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