Tag Archives: NodeJS

Gulp – Rewrite source files instead of creating new files

I would like to minified the .js files of the bower packages in my project. Usually, gulp will read the source files and the pipe them into new files but this time i would like to overwrite the original file without creating a .min.js file.


gulp.task('jsmin', function() {
  return gulp.src('bower_components/**/*.js', {base: './'})


The above task will read those .js files inside the bower_components folder, uglify the source file and create the corresponding .map file for each .js file in the same folder.

Done =)

Reference: StackOverflow – Can Gulp overwrite all src files?


Drupal 7 – Setup Bootstrap 3 Theme with Gulp for LESS compilation

Got a new responsive site freelance and i would like to try Bootstrap 3 theme in Drupal 7. A little bit confused at the very beginning because the theme has a lot of features and bug fixes ongoing. So the documentation is a bit lacking and i have to make some trials and errors before knowing what to do.

Some Drupal developers may also have problem on compiling LESS. So here i include a gulp script and some NodeJS packages to help.

Assume you have setup the Drupal 7.

1. Download the Bootstrap 3 Drupal theme. The current stable version is 7.x-3.0 which is a bit old and only works with Bootstrap 3.0.x. I am going to use 7.x-3.1 which supports the latest Bootstrap version (v3.3.2 at the moment i write this post). The 7.x-3.1 is still in beta (7.x-3.1-beta2). You could download it from the releases listing page.

2. Extract the Bootstrap 3 base theme to the sites/all/themes folder. You would found the starterkits folder containing the subthemes. as follow. Continue reading Drupal 7 – Setup Bootstrap 3 Theme with Gulp for LESS compilation

Meteor – Run shell command at server side

1. Install the fibers node package on the server.

npm -g install fibers


2. Define the server methods in server.js.

Meteor.startup(function () {
  // Load future from fibers
  var Future = Npm.require("fibers/future");
  // Load exec
  var exec = Npm.require("child_process").exec;

  // Server methods
    runCode: function () {
      // This method call won't return immediately, it will wait for the
      // asynchronous code to finish, so we call unblock to allow this client
      // to queue other method calls (see Meteor docs)
      var future=new Future();
      var command="pwd";
          throw new Meteor.Error(500,command+" failed");
      return future.wait();

Continue reading Meteor – Run shell command at server side

Puppet – Run exec as a specific user

I would like to Puppet to install the node modules which is specified in the Node.js project package.json. But the Puppet agent is run under the root account while the project is owned by another Linux user. The Puppet exec type allows you the specific the running user but it would not include the environmental variables like the $HOME. Those variables have to be set when calling the exec type just like follow.

exec { "install node modules of a nodejs project":
  cwd         => "/home/ykyuen/nodejs-project",
  command     => "npm install",
  user        => "ykyuen",
  environment => ["HOME=/home/ykyuen"],


If you need to set more than one environmental variable, just add them in an array format.

  environment => ["HOME=/home/ykyuen", "FOO=foo"],


Done =)

Reference: Puppet Docs: Type Reference – Exec

StatsD – Installation and integration with Graphite

Previous: Install Graphite under pyenv virtualenv on Ubuntu


Compared to Graphite, installing StatsD server is just a piece of cake.

1. Install Node.js. For better management on Node.js, you could consider using nvm.


2. Checkout the StatsD project on GitHub.

git clone https://github.com/etsy/statsd.git


3. Copy the exampleConfig.js and name it to whatever you like and edit it as follow.
ex. statsdConfig.js.

  graphitePort: 2003
, graphiteHost: "<graphite host>"
, port: 8125
, backends: [ "./backends/graphite", "./backends/console" ] // console is for debug
, debug: true // For debug
, graphite: { legacyNamespace: false } // Better group all collected metrics under stats

Continue reading StatsD – Installation and integration with Graphite

Yeoman – Setup AngularJS and Foundation 5 with Sass

The generator-angular written by the Yeoman team comes with Bootstrap integration. But instead of using Bootstrap, i would like to use Foundation 5 with Sass. The following example is created under Node.js v0.10.29.

1. Create your project directory. In my case, i will name the project ng-foundation.

mkdir ng-foundation


2. Move to the ng-foundation folder.

cd ng-foundation


3. Scaffold the AngularJS project using the generator-angular as usual.

yo angular

Continue reading Yeoman – Setup AngularJS and Foundation 5 with Sass

Ubuntu – Install Node Ver­sion Man­ager globally for all users

The Node Ver­sion Man­ager(nvm) could help you to manage multiple Node.js installations. The following steps are executed from root account.

1. Install the required packages.

apt-get install build-essential openssl libssl-dev curl


2. Create a new user group and add those users which are allowed to manage Node.js installation. The following command create a new group called dev.

groupadd dev

Continue reading Ubuntu – Install Node Ver­sion Man­ager globally for all users

Setup Yeoman in Windows PowerShell

Update @ 2015-09-23: Using PowerShell is just my personal preference, You could use MS-DOS in Windows if your machine doesn’t have PowerShell installed.

1. Download Node.js and install it and make sure you have the npm package manager selected before the installation.
Continue reading Setup Yeoman in Windows PowerShell