npm is two things: first and foremost,
1. it is an online repository for the publishing of open-source Node.js projects;
2. second, it is a command-line utility for interacting with said repository
that aids in package installation, version management, and
dependency management.
npm install moment # Install a package
npm install eslint --save-dev # tool for validating standard in code
#equivalent to: npm install eslint -D. Into Dependencies in package.json
npm install react --save # stored as dependency
# equivalent to: npm install reac -S. Into devDependencies in package.json
npm install -g cowsay #install as a global package
npm list # list pacakges
npm list -g #list global packages
npm install package-name -o #install optional dependency
npm install react-dom --dry-run #simulate installation without actually adding it
npm install json-server@0.15.0 #Install specific version
npm install json-server@latest #Install latest version
npm install # Install packages in package.json
var express = require('express')
var cors = require('cors')
var app = express()
var whitelist = ['http://example1.com', 'http://example2.com']
var corsOptions = {
origin: function (origin, callback) {
if (whitelist.indexOf(origin) !== -1) {
callback(null, true)
} else {
callback(new Error('Not allowed by CORS'))
}
}
}
app.get('/products/:id', cors(corsOptions), function (req, res, next) {
res.json({msg: 'This is CORS-enabled for a whitelisted domain.'})
})
app.listen(80, function () {
console.log('CORS-enabled web server listening on port 80')
})
npm install - Install all plugins and dependencies, this step is mandatory.
npm run dev - Start it in Development mode, be aware this mode is only for developing, it can take a while before starting, also this mode include hot reloading and other cool stuff.
Or for production mode:
npm install - Install all plugins and dependencies, this step is mandatory.
npm run build - This step is mandatory before starting in production mode.
npm start - Start in production mode.
// npm install inquirer(Gitbash)
// outline
var inquirer = require('inquirer');
inquirer
.prompt([
/* Pass your questions in here */
])
.then((answers) => {
// Use user feedback for... whatever!!
})
.catch((error) => {
if (error.isTtyError) {
// Prompt couldn't be rendered in the current environment
} else {
// Something else went wrong
}
});