Search code examples
node.jsconfigproduction

node.js production settings


I made a small app in node.js for windows,

i followed a few guides and tips and i downloaded the 'config', and 'cross-env" packages.

I added this part to my 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"
    }

I also added 3 json files under the config folder, default.json, production.json and qa.json.

An example which i am planning to use the config package for is :

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

Now i scanned quite a few posts about a solution but nothing seem to help so far, when i am trying to run "npm prod" or "npm qa" i am getting the following message :

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

[email protected] E:\Program Files\nodejs\node_modules\npm

So far i failed to figure out the root of the problem.


Solution

  • As the error message is trying to tell you, npm has no such command; custom scripts do not directly become npm commands.

    Instead, use npm run to run a script.