Using Node.js with CouchCMS - javascript

I would like to use the features of Grunt and Gulp (preprocessing, compressing, watching etc.), but I don't want to abandon traditional PHP. I use CouchCMS which requires traditional PHP.
Can I use both CouchCMS with Grunt or Gulp? If not, why is that so, and is there any viable alternative?
Thanks

You can just create Gruntfile.js in your core folder with configs and run it from same folder where your project located by grunt <command>. To install grunt as application, you need to install node and npm and then by using npm(Node Packaged Modules) you can install grunt/gulp via npm install -g grunt or npm install -g gulp. By adding -g property, you force installing packages inside your execution folder bin and you can use those packages as standalone console application.

If you want a task runner for PHP you can use robo.li instead of Grunt, since grunt is meant for js.

Related

What's the difference between npm install and manual installation?

So i'm looking at requirejs. I can either install this package with npm install requirejs, or download it manually from the website. What's the difference? Are there tradeoffs to either one? Is npm install just a fancier way of manually installing? Thanks.
imagine you have 10 libraries in package.json, and you want to install all of them at once, you can just do "npm i" and it will take care of all, in just ~10sec. compare this with installing those 10 lib manually, it is indeed a good friend, to help you ease the process of downloading lib for you in no time.
Yes, npm install is just a fancier way to add package that help saving your precious time.
Base on the description here: npm install.
If the package has a package-lock, or an npm shrinkwrap file, or a yarn lock file, the installation of dependencies will be driven by that
Install the dependencies in the local node_modules folder.
In global mode (ie, with -g or --global appended to the command), it installs the current package context (ie, the current working directory) as a global package.
By default, npm install will install all modules listed as dependencies in package.json.
With the --production flag (or when the NODE_ENV environment variable is set to production), npm will not install modules listed in devDependencies. To install all modules listed in both dependencies and devDependencies when NODE_ENV environment variable is set to production, you can use --production=false.
Without a package manager like npm or yarn, it could take you a lot of time just for installing stuff. And while you are developing with node js, you'd have ton of things to install.
Every modern programming language has it's own package manager, so why you ever need to manually install them?

Is there a way to download all dependencies in a package-lock.json/yarn.lock file without installing them?

I am trying to stage dependencies from the NPM registry in a Nexus NPM proxy repository for any arbitrary JavaScript project. I can perform an npm install or yarn install which will cause all the dependencies to be staged, but I'd like to avoid that. The main reason is I want to avoid needing the necessary C/C++ libraries installed to compile the dependencies that are NodeJS C/C++ add-ons.
The only solution I can think of is by parsing the package-lock.json/yarn.lock file and running npm pack <dependency> for each dependency, which will cause npm to fetch the needed dependency and copy the tarball of the dependency to the current directory. I could then delete each downloaded tarball.
Is there a more elegant solution for either npm or yarn?
If you run npm install --ignore-scripts then the install scripts will be ignored and so any C/C++ files won't be built anymore.

Installing a library using npm

I've a question regarding how to use a js library that is installed via npm. I have a simple webapp that compiles using gulp, so I installed the library using --save to populate my package.json but now what? should I add it as a gulp task too? I am not clear about all this process. Thanks
Almost always, libraries installed using npm i --save are ready to be require()d right out of the box.
The gulp tasks you might see on a library's source in GitHub is for developers of that library to build and test the library locally.
npm has utilities for running all of the build tools automatically before the library is published (with npm publish) and while the consumer's (yours) npm install is running.

Unexpected NodeJS and NPM behavior

Does npm install only install packages in the directory you run it from? Because that's my current experience with it. At first, I ran npm install xml in a command prompt at C:/Users/ME. Running require("xml"); in a node instance that was run from C:/Users/ME works, and running npm ls lists the xml package...
But if I move to any other directory, neither of them do.
Is this the expected behavior (doesn't sound right), a Windows thing, or am I missing some kind of install option?
Yes, this is normal behavior.
npm install (in package directory, no arguments):
Install the dependencies in the local node_modules folder.
In global mode (ie, with -g or --global appended to the command), it
installs the current package context (ie, the current working
directory) as a global package.
By default, npm install will install all modules listed as
dependencies. With the --production flag (or when the NODE_ENV
environment variable is set to production), npm will not install
modules listed in devDependencies.
NPM Install Docs
npm installs modules either below the current directory (in a node_modules sub-directory) or if you use the -g flag when running it, it install modules in the global location which is determined via OS and configuration and then node.js will be able to find the module no matter where it is being loaded from.
So, this will install a module globally:
npm install -g xml
When using require(), if you want require to look in the current directory to load a module, then you have to do it like require("./module");, otherwise it will not look for the modules install in the current directory.
You need to do npm install -g xml. This would install the packages globally.
'-g' represents global. Then when you check on other directories, you could list the same package
Note the way you install node is important as well!
You can install node with:
chocolatey (https://chocolatey.org/packages?q=nodejs)
nodeJS website (https://nodejs.org/)
*Knowing where to set your user variables is essential know how for windows developers! The reason I mention this is that the list of chocolatey, and node USER : PATH variables gets so large at one point nodejs and with it npm will just stop working. You need to work within your env. variables in one scenario where that happens. (Can typically happen with multiple versions of SQL Server installed)
If you want an excellent free, offline-available resource on node and npm I suggest devdocs (http://www.devdocs.io) and as well GentlNode's cheat sheets (https://gentlenode.com/journal/cheatsheet) *GentleNode not avail. offline FYI.
There's some key information you haven't received yet. See below:
npm install xml - installs "xml" package and required modules to the local folder you are in when you run the command. Files exist for you to work on in this folder alone(and thus commands only work in this folder) and "xml" cannot be called in cmd/terminal outside of this folder(without rerunning with "-g" param) "xml" is NOT written to package.json file. When and if project is uploaded to github will upload in full if you don't add node_modules to your .gitignore file.
npm install -g xml - install "xml" to your global npm folder, which is referenced to your "user environment variables" (what allows you to call specific functions, methods, and executables from within the command line) Files are NOT installed to your project folder, not recorded in "package.json" file. Will NOT upload anything to github.
npm install --save xml - using "--save" allows you to "install" to this folder, but also to write the package you've included into your project's "package.json" file. Here, your aim is to distribute your software and you want as little files on github/source control as possible that npm knows how to install like jQuery, XML, body-parser, etc. etc.
You would typically use a regular "npm install XML" command for a lightweight, rapid release mini-tool to support a key feature or process improvement you just want to keep on your local machine. In addition, you could npm install "packages" to a folder, and use that as a backup "node folder" mapped to your environment variables.
You would typically use a global "npm install -g XML" command for something like middleware, express, node updates installed VIA npm, and other processes you wish to have access to in cmd/terminal from "anywhere." Once this is established for your core development packages in node, you often just use the proceeding command, read the explanation for more detail.
Lastly, you would use "npm install --save" to write into the "package.json" file the required module(s) you've installed to your project. This would be for those who have worked heavily in node and have used "npm install -g" to already globally install their most common core nodeJS. This will write to the package.json the packages and versions being leveraged in your software currently so that your end-user can download the lightweight version and use npm package management to install all of the module dependencies so the app works correctly on other people's computers.
*Note, this leads to the last command "npm install" which you can run in a given folder where you've downloaded the file directly from github.
Hope that helps a bit more for the given facets of installation using npm!

How do I use GruntFile.coffee and package.json to extract/make/fetch/?? the Lungo.js example files?

I am wanting to try out the Lungo.js examples from here : https://github.com/tapquo/Lungo.js,
however the index.html in the example directory is expecting files in the components and package directories and, while those directories do exist as part of this bundle, they are empty of any files.
I have a GruntFile.coffee and a package.json and I believe that together these are some kind of make file that perhaps should make/pull/create the files that the example needs to run, but I don't know how to make them do that.
I have installed the following:
sudo npm install -g grunt-cli
sudo npm install -g grunt
sudo npm install -g coffee-script
I can now run "coffee GruntFile.coffee" successfully, but it does nothing I can see, certainly it is not creating the missing files.
And the "grunt" command simply says "Fatal error: Unable to find local grunt."
How do I tell this bundle of code that I have to get the other files I require?
And, bonus question, what's going on here?
(I understand javascript, and pulling code from github, but not these other frameworks)
package.json has devDependencies field. They need to be installed before you may use grunt command. First you need execute
npm install
in directory wich contains it.
There is definitely bug in this line of Gruntfile
You should change it to:
pkg: grunt.file.readJSON "package.json"
Then, after local grunt is installed, you may run
grunt
which will execute default task. This is well known practice last time.
You need to install grunt locally, not globally. Only grunt-cli should be installed globally.
So instead of
npm install -g grunt
Navigate to your project root folder and execute
npm install grunt
There's a getting started guide on the Grunt homepage.
The package.json file is a descriptor file for your application. More information on this file can be found in this interactive guide. You normally use grunt together with this file so you can list your grunt plugins as dependencies of your application. I suggest reading a tutorial on grunt to learn how it works.

Categories