Azure "Web apps" service: auto-install npm modules from package.json - node.js

I deployed a node.js app in an azure "web apps" container. I added the "node_modules" folder to .gitignore and let azure install modules from package.json.
However, most modules do not get automatically installed and i have to open the instance's command line and install them manually using "npm install".
I am using node v0.12.0 and here is my package.json:
{
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"devDependencies": {
"body-parser": "^1.12.4",
"cors": "^2.6.1",
"express": "*",
"gulp": "^3.8.11",
"gulp-jshint": "^1.11.0",
"gulp-nodemon": "^2.0.3",
"moment": "^2.10.3",
"mongoose": "^4.0.3"
},
"engines": {
"node": "0.12.0"
}
}
How can I enable automatic installation of modules through azure web apps and not be obliged to push the "node_modules" folder with each commit?

Azure does not install the devDependencies.
If you need them on production, it is not devDependencies but dependencies
In your package.json, devDependencies should be renamed to dependencies
This kind of thing appens when you npm install --save-dev.
Production dependency (needed to run): npm install --save
Otherwise (build tools, jshint, etc.): npm install --save-dev

Related

Install custom npm package in another custom npm package

I have create a npm package to install "gulp" & "nunjucks" and some other features of gulp. and published it in NPM repository named (package name: xdnunjucks-test).
Now I have created new project and trying to install "xdnunjucks-test" then it is added to my new project but all the dependencies in xdnunjucks-test are not added to new project.
command: npm install xdnunjucks-test
-- I should create a custom NPM package to install all dependencies in my new projects. This will helps me to avoid run all the commands in xdnunjucks-test everytime.
single command to run multiple commands.
here are my package.json file content.
Published Custom NPM command - package.json:
{
"name": "xdnunjucks-test",
"version": "1.0.5",
"description": "Custom npm command creation",
"main": "index.js",
"scripts": {
"test": "XDNunjucks",
"start": "npm install gulp",
"bootstrap-gulp": "npm i bootstrap-gulp",
"gulp-uglify": "npm install gulp-uglify",
"gulp-sass": "npm install node-sass gulp-sass",
"gulp-imagemin": "npm install gulp-imagemin",
"gulp-minify": "npm install gulp-minify",
"gulp-livereload": "npm install gulp-livereload",
"gulp-data": "npm install gulp-data",
"browser-sync": "npm install browser-sync"
},
"keywords": [
"npm",
"test"
],
"author": "Anil",
"license": "ISC",
"devDependencies": {
"browser-sync": "^2.26.7",
"gulp": "^4.0.2",
"gulp-data": "^1.3.1",
"gulp-imagemin": "^7.1.0",
"gulp-livereload": "^4.0.2",
"gulp-minify": "^3.1.0",
"gulp-nunjucks-render": "^2.2.3",
"gulp-sass": "^4.0.2",
"gulp-uglify": "^3.0.2",
"node-sass": "^4.13.1"
},
"dependencies": {
"bootstrap-gulp": "^2.2.5"
}
}
new project package.json:
{
"name": "n-test-2",
"version": "1.0.0",
"description": "",
"main": "gulpfile.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"xdnunjucks-test": "^1.0.5"
}
}
After installing the "xdnunjucks-test" command. I didn't get the features of "xdnunjucks-test" in new project.
Please help in in this.
Thank you.
All the dependencies in you package xdnunjucks-test is only "bootstrap-gulp" "^2.2.5"
all other dependency from devDependency will not be installer in package.
For example if you need to use gulp-uglify in installed package xdnunjucks-test - you should move it to dependency
devDependencies are:
installed on npm install on a directory that contains package.json, unless you pass the --production flag (go upvote Gayan Charith's answer).
not installed on npm install "$package" on any other directory, unless you give it the --dev option.
are not installed transitively.
You can find more about npm dependency on stackoverflow and npm documentation

Include package json dependencies for npm install global

I only know npm install locally particular plugin into the dependencies object in the package.json. Been doing npm install -g on many packages manually, but how do I include it inside the package.json?
eg. my current package:
{
"name": "mypackage",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"axios": "^0.19.0",
"lodash": "^4.17.15",
"react": "16.8.3",
}
}
To include my global install modules into mypackage
├── expo-cli#3.0.8
├── npm#6.9.0
├── npm-check-updates#3.1.20
├── react-devtools#4.1.0
├── react-native-cli#2.0.1
└── typescript#3.6.3
Go to your project root directory and execute,
npm install your-package-name
Or you can put the package-name manually in your package.json file and run,
npm install
But your package is already globally installed on your machine.
When you install an npm package, globally, using npm install -g my-package, then the package is globally available in your machine. You can use it anywhere in your machine.
But without global flag -g when you install a package, it only available inside the project scope.
So when a package is available globally, you do not need to install it in your project scope. It's a code redundant.
just type
$ npm install name-of-the-dependency
This is going to install the dependency in the package.json
The package will be added to your package.json when you install it from the project directory without -g
npm install --save package
you can also save the developer dependencies by
npm install --save-dev package
when you want to download a package for developers, such as grunt, gulp, then use this option
when you are distributing your code to production, these dependencies will not be available.
If you want to include packages like angular-cli you can install it as normal package and access it by referring the path inside the node_modules. like node_modules/.bin/ng build --prod
Appreciate with the guidance guys, just updated my question. So to add my global modules into mypackage gonna be like as per below?
{
"name": "mypackage",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"axios": "^0.19.0",
"lodash": "^4.17.15",
"react": "16.8.3",
"expo-cli": "3.0.8",
"npm": "6.9.0",
"npm-check-updates": "3.1.20",
"react-devtools": "4.1.0",
"react-native-cli": "2.0.1",
"typescript": "3.6.3"
}
}

Hi. I am new to react and have a query re optimum setup procedures

The following package.json contains a lot of dependencies and a few devDependencies stuff but barring a few files it seems to have all I need excepting a few npm install commands for reactstrap, bootstrap, react-bootstrap
{
"name": "react-tutorials",
"version": "0.0.0",
"description": "",
"main": "webpack.config.js",
"dependencies": {
"babel-core": "^6.18.2",
"babel-loader": "^6.2.0",
"babel-plugin-add-module-exports": "^0.1.2",
"babel-plugin-react-html-attrs": "^2.0.0",
"babel-plugin-transform-class-properties": "^6.3.13",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"babel-preset-stage-0": "^6.3.13",
"flux": "^2.1.1",
"history": "^1.17.0",
"react": "^0.14.6",
"react-dom": "^0.14.6",
"react-router": "^1.0.3",
"webpack": "^1.12.9",
"webpack-dev-server": "^1.14.1"
},
"devDependencies": {},
"scripts": {
"dev": "webpack-dev-server --content-base src --inline --hot"
},
"author": "",
"license": "ISC"
}
// Additional dependencies and devDependencies
npm install --save reactstrap react-addons-transition-group react-addons-css-transition-group react react-dom
npm install react react-dom bootstrap react-bootstrap babel-preset-react webpack webpack-dev-server --save
npm install webpack css-loader style-loader file-loader url-loader babel-core
What is the optimal way to create a file tree for your react project via npm and what react-*** setup packages are not too difficult for a novice such as myself? Please don't suggest create-react-app - I love it but its limited. Also, can all dependencies and devDependencies be installed via npm all at once or with some files interfere with others which I've noticed before I think.
When you run each of the commands npm install --save package-here it will add that package to your package.json automatically. When you're ready to install your project from the root directory you run npm install only and it will install everything in your package.json into a node_modules folder. Other than that you should not have to change anything with your packages as far as file structure.
In addition, when you want to add a package to your dev-devependencies run npm install --save-dev or just dependencies npm install --save.

"npm install" insall nothing to node_modules folder but a .staging folder centos 7

I have this package.json
{
"name": "jangkoo",
"version": "0.0.0",
"private": true,
"dependencies": {
"keystone": "^0.3.19",
"async": "^1.5.0",
"lodash": "^4.13.1",
"node-sass": "^3.3.2",
"node-sass-middleware": "^0.9.7",
"dotenv": "^2.0.0"
},
"devDependencies": {
"eslint": "^2.12.0",
"eslint-config-keystone": "^2.3.1",
"eslint-plugin-react": "^5.1.1",
"gulp": "^3.7.0",
"gulp-shell": "^0.5.0",
"gulp-watch": "^4.3.5",
"gulp-sass": "^2.0.4"
},
"scripts": {
"lint": "eslint .",
"start": "node keystone.js"
}
}
When i run npm install, it created a node_modules with a .staging folder inside. No other modules installed. What's the problem here? The OS is Centos 7 .
npm install temporarily adds all node_modules into a .staging folder during install. If something goes wrong during install, like you run out of memory, you could be stuck with this weird node_modules install containing the .staging folder.
https://github.com/npm/npm/issues/12540
for install npm for centos
yum update
yum install npm
I found it out. It failed to install keystone then it stopped. That's why nothing has been installed.
How about remove the node_modules folder and run npm install again

Grunt error: Cannot find module 'time-grunt'

I try to install time-grunt local and global, clear npm cache, update npm, but nothing helps.
I get:
Loading "Gruntfile.js" tasks...ERROR
Error: Cannot find module 'time-grunt'
Warning: Task "default" not found. Use --force to continue.
My version of packages:
node: '0.10.31',
npm: '1.4.23'
After run:
npm install --save-dev time-grunt
in package.json state:
"devDependencies": {
"grunt": "^0.4.5",
...
"time-grunt": "^1.0.0"
}
This is part of my grunfile.js:
module.exports = function( grunt ) {
require('time-grunt')(grunt);
grunt.initConfig({
// grunt tasks here
});
// load tasks here
// register task here
}
Other grunt tasks running without error.
I'm not understand what is wrong.
How I can test correctly installation of time-grunt by CLI?
You need to add it inside dependencies and not within devDependencies. This way you don't need to separately run $ npm install --save-dev time-grunt
{
"name": "grunt-build",
"version": "0.1.0",
"private": true,
"dependencies": {
"time-grunt": "^1.3.0"
},
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-clean": "~0.7.0",
"grunt-contrib-compress": "~0.5.0",
"grunt-contrib-concat": "~0.5.0",
"grunt-contrib-copy": "^0.8.0",
"grunt-contrib-uglify": "~0.5.0",
"grunt-remove-logging": "~0.2.0"
}
}
use npm install or sudo npm install in the folder with package.json
I ended up installing all grunt dependencies manually.
npm install time-grunt
npm install load-grunt-config
and then all modules listed here:
Note: you can install all of the dependencies in the photo above in one go with npm install.
Finally I ran the grunt command and it worked!

Resources