WordPress and NODE
Which is why I love combining these two technologies. I'm currently working on a CMS system called PAM, which is PHP, Angular and Mongodb. But this is still a work in progress and I'm not ready to release this code just yet. However, if you want to be a contributor to PAM, please do contact me.
In the meantime, I love using newer technologies that node provides, in my WordPress sites that I build for clients.
Here's a quick primer for anyone wanting to combine WordPress or even Drupal with node js.
I'm assuming that you're on a MAC OSX system with Homebrew installed. The line below will install Homebrew for Mac in case you don't have it.
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)";
brew install node;
Check your node version and make sure you have the latest version of NPM, the node.js package manager.
npm install npm@latest -g;
Finally, we want to make sure that brew is updated and upgraded since node.js is updated frequently.
brew update; brew upgrade;
Using Node with WordPress
Now that node is installed, we are ready to work add node.js to our wordpress installation. Many people to choose to install node modules in their theme directories, but I prefer to install node on a global level in the root WordPress directory so that all themes can use installed node modules.
Our first step should be to initialize our node project and creating a package.json file.
Answer the questions at the prompt to automatically create a package.json file.
Our next step is to install a task runner, and gulp is much better than grunt if you ask me. The first line below with the "g" flag installs gulp globally, so that you can use it while in any directory.
The second line will add gulp to your package.json file. Which means that if a coworker pulls down your code from GIT, all the have to do is type in "npm install" to install every node module in the package.json file
This is why you should have a .gitignore file if you're using GIT, and that the node_modules folder is in this .gitignore file. You don't want these node modules to go into GIT, which is redundant.
npm install --global gulp-cli; npm install --save-dev gulp;Your next step is to create a gulpfile, which is as simple as creating a file named "gulpfile.js" in the root directory.
For now, just put the following code into your gulp file, and save it. Then simply type "gulp" into your terminal.
That's basically it! You have everything you need to use WordPress with node.js.
Make sure to check out my post about a example gulp file.