Node.js 生产设置

标签 node.js config production

我用node.js为Windows制作了一个小应用程序,

我遵循了一些指南和提示,并下载了“config”和“cross-env”包。

我将此部分添加到我的 package.json -

"scripts": {
        "start": "cross-env SET NODE_ENV=development& nodemon server.js",
        "qa": "cross-env SET NODE_ENV=qa& nodemon server.js",
        "prod": "cross-env SET NODE_ENV=production& nodemon server.js"
    }

我还在config文件夹下添加了3个json文件,default.json、Production.json和qa.json。

我计划使用配置包的一个示例是:

var config = require('config');
var connectionString = config.get('connectionString');

现在我扫描了很多有关解决方案的帖子,但到目前为止似乎没有任何帮助,当我尝试运行 "npm prod""npm qa" 时,我收到以下消息:

F:\MeanApp>npm prod

Usage: npm <command>

where <command> is one of:
    access, adduser, bin, bugs, c, cache, completion, config,
    ddp, dedupe, deprecate, dist-tag, docs, doctor, edit,
    explore, get, help, help-search, i, init, install,
    install-test, it, link, list, ln, login, logout, ls,
    outdated, owner, pack, ping, prefix, profile, prune,
    publish, rb, rebuild, repo, restart, root, run, run-script,
    s, se, search, set, shrinkwrap, star, stars, start, stop, t,
    team, test, token, tst, un, uninstall, unpublish, unstar,
    up, update, v, version, view, whoami

npm <command> -h     quick help on <command>
npm -l           display full usage info
npm help <term>  search for help on <term>
npm help npm     involved overview

Specify configs in the ini-formatted file:
    C:\Users\me\.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config

npm@5.5.1 E:\Program Files\nodejs\node_modules\npm

到目前为止我没能找出问题的根源。

最佳答案

正如错误消息试图告诉你的那样,npm 没有这样的命令;自定义脚本不会直接成为npm命令。

相反,请使用npm run运行脚本。

关于Node.js 生产设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47226862/

相关文章:

javascript - Node 的 q.fcall 返回一个空对象

java - 我可以在 Spring JUnit 测试中使用 @Import 吗?

mysql - mysql 数据库的 Node.js 配置文件

ruby-on-rails - Rails - 查询在开发中的 View 和 Controller 中工作,但仅在生产中的 View 中工作

node.js - 直接使用 chromedriver 而不是使用 selenium 服务器运行 webdriver.io

node.js - findOneAndUpdate,回调必须是一个函数,得到 [object Object] ,NodeJs,mongoose 错误

azure - Azure 中的生产环境与暂存环境

ruby-on-rails - 无法在生产服务器上启动 Rails 4 控制台

javascript - Node.js 中的 ES6 风格子进程

Python configparser 从一个部分获取所有内容并写入新文件