Javascript News

Syndicate content
Pipes Output
Updated: 48 weeks 6 days ago

The Most Popular WordPress Landing Page Plugins

Mi, 2015-09-09 19:00

Landing pages are the bread and butter of any successful marketing campaign. They are choc full of customized content that speaks to your website visitors. This content speaks to your website visitors because it delivers the exact, specific information that your visitor was expecting. Landing pages are aligned with your marketing messages 110%, and always have one clear objective in mind: making your website visitors take a specific course of action.

When it comes to creating landing pages in WordPress, there is a multitude of plugin options available, all of which have their distinct advantages. In this article, we'll cover a selection of the most popular WordPress landing page plugins.

[author_more]

What is a Landing Page?

A landing page is a stand-alone web page that has been designed with a specific goal or objective in mind. This goal or objective is usually focused on user actions, on motivating your landing page visitors to take action, to do something, to convert. Often, this something might be to request a quote, or sign up to a mailing list, or provide contact details in exchange for a freebie (like an e-book or a white paper or a template of some description).

Landing pages are completely separate from your main website. And, in general, are completely without the main menu navigation that would otherwise tie the landing page to your website. The main reason for this lack of navigation is to give visitors less choice in terms of actions. With less options available, your landing page visitors are more likely to take the course of action that you want them to take, inching them closer and closer to your intended conversion.

Continue reading %The Most Popular WordPress Landing Page Plugins%

A Full Screen Bootstrap Carousel with Random Initial Image

Mi, 2015-09-09 18:00

A few months ago, I wrote an article that covered Bootstrap’s Affix and ScrollSpy components. This time though, I’ll be focused on a different Bootstrap component: I’ll go through the process of building two simple extensions for the Bootstrap carousel.

First, I’ll create a full-screen slideshow and then I’ll show you how to randomize the first slide on page load.

But before digging into those extensions, let’s start by creating a carousel based on the default styles.

Building the Carousel

To create the carousel, we’ll take advantage of the basic code for the carousel component that Bootstrap provides:

[code language="html"]
<div id="mycarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#mycarousel" data-slide-to="0" class="active"></li>
<li data-target="#mycarousel" data-slide-to="1"></li>
<li data-target="#mycarousel" data-slide-to="2"></li>
<li data-target="#mycarousel" data-slide-to="3"></li>
<li data-target="#mycarousel" data-slide-to="4"></li>
</ol>

<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="1.jpg" data-color="lightblue" alt="First Image">
<div class="carousel-caption">
<h3>First Image</h3>
</div>
</div>
<div class="item">
<img src="2.jpg" data-color="firebrick" alt="Second Image">
<div class="carousel-caption">
<h3>Second Image</h3>
</div>
</div>
<!-- more slides here -->
</div>

<!-- Controls -->
<a class="left carousel-control" href="#mycarousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#mycarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
[/code]

Notice that each of our images contains the custom data-color attribute. Later we’ll use its value as a fallback in case the corresponding image fails to load.

The next step is to initialize the carousel via JavaScript and modify the predefined values of the interval and pause configuration properties. Take note that we choose to set the value of the pause property to false because we always want the cycling to be active:

[code language="javascript"]
$('.carousel').carousel({
interval: 6000,
pause: "false"
});
[/code]

Having followed those simple steps (and of course imported the required files), we should now be able to build the first version of the carousel. Here’s how it looks so far:

See the Pen A Basic Bootstrap Carousel by SitePoint (@SitePoint) on CodePen.

Creating Full-screen Slides

At this point we’ll go one step further, converting the existing carousel into a full-screen slideshow. To implement this updated version we have to add some custom jQuery:

Continue reading %A Full Screen Bootstrap Carousel with Random Initial Image%

Watch: Singleton Methods in Ruby

Mi, 2015-09-09 17:30

Did you know that in Ruby you can define personal method for objects? That is, a method that only one object will respond to. Such methods are called singleton methods and it is worth knowing how to work with them. In this video we are going to discuss callbacks to observe method changes as well as differences between removing and undefining methods. The next mystery of Ruby is going to be revealed!

This is the third video of the Ruby Metaprogramming Revealed series. Learn more about Ruby metaprogramming by viewing the rest.

Loading the player...

Continue reading %Watch: Singleton Methods in Ruby%

Building a Dodger Game Clone in Unity

Mi, 2015-09-09 16:00

In this tutorial, we’ll be building a simple Dodger game in Unity. To see and play the final result, go here. Analyzing the Game Dodger is a small, simplistic game that doesn’t take much logic to program and can be customized almost endlessly. Dodger only has a few key elements of Gameplay: Player Input Player/Enemy […]

Continue reading %Building a Dodger Game Clone in Unity%

An Introduction into Event Loops in PHP

Mi, 2015-09-09 16:00

PHP developers are always waiting for something. Sometimes we’re waiting for requests to remote services. Sometimes we’re waiting for databases to return rows from a complex query. Wouldn’t it be great if we could do other things during all that waiting?

If you’ve written some JS, you’re probably familiar with callbacks and DOM events. And though we have callbacks in PHP, they don’t work in quite the same way. That’s thanks to a feature called the event loop.

We’re going to look at how the event loop works, and how we can use the event loop in PHP.

We’re going to see some interesting PHP libraries. Some would consider these not yet stable enough to use in production. Some would consider the examples presented as “better to do in more mature languages”. There are good reasons to try these things. There are also good reasons to avoid these things in production. The purpose of this post is to highlight what’s possible in PHP.

Continue reading %An Introduction into Event Loops in PHP%

Designing Web Code in a Native App

Di, 2015-09-08 19:00

Over the years I've heard developers say, "you can always tell when it's a web app," insinuating that web apps are lacking when compared with native apps. These same folks will claim that web app performance is poor and the design is inferior. Although that might have been true years ago, today's web fairs much better than the web of yesteryear. Our runtimes are superfast, leaving no lack of performance for apps. And the best user experience on the web is generations ahead of that of native apps, with responsive design making web apps a great experience on any device.

The benefits of web apps continue. When well written, anyone with a browser can interact with a web app regardless of platform, version, or device. Its single code base also makes it the overwhelming choice for developers, brands, and companies that don't desire or have the resources to build and maintain native apps for each platform.

[caption id="attachment_114218" align="aligncenter" width="999"] Awesome web apps are awesome apps. Both in a browser or in an app store.[/caption]

Defining the problem

Every day I work with developers who are using ManifoldJS to take great web apps and turn them into store apps. ManifoldJS lets you maintain the spirit of the web by building hosted web apps. Hosted web apps are different because they allow your code to live on a web server just as it does when you access it in a browser. That means the codebase is always up-to-date, you can deploy changes whenever you desire, and, generally, if the code works in the browser then it will work as a hosted web app.

Great web apps have great user experiences and a web app that is designed to work on a wide variety of browsers and devices can perform quite well as a cross-platform hosted web app. Some key characteristics of apps like this are:

  1. Responsive layouts. The design presents a good reading/viewing experience no matter what the screen size or orientation. Users can accomplish their goals without need to scroll in more than one direction or zoom in and out to interact with the app.
  2. Appropriately-sized fonts. You should be able to easily read the font on the screen. This works both ways - it should be large enough to be read on a small screen, but it should not be ridiculously large on larger screens. Balance is key.
  3. Flexible input. The app should support touchscreens, keyboard and mouse; but if you want to support next-generation interfaces, don't forget about input modes like voice or gestures.
  4. Speedy delivery. Not everyone has hard-wired access to a fiber optic connection and unlimited bandwidth. Many devices have limited bandwidth or slower processor speeds. Your app should not take too long to load or feel sluggish during interactions.

With all of that taken into account, the question I most frequently get is: How should I design my app? (And they mean that in terms of aesthetics.) In other words, what should the visual design look like? Generally, the options are:

  1. Design a single interface for the app, so it looks consistent no matter what platform it's being used on.
  2. Design a more "native" interface for each platform to honor its unique look and feel.

Continue reading %Designing Web Code in a Native App%

5 Things You Should Be Doing On Facebook Right Now

Di, 2015-09-08 18:00

Last week Mark Zuckerberg posted a status update on his personal Facebook account: “We just passed an important milestone. For the first time ever, one billion people used Facebook in a single day”. 1 billion people. Go ahead… try and tell me your target audience isn’t using Facebook. Facebook isn’t going anywhere people. It’s a […]

Continue reading %5 Things You Should Be Doing On Facebook Right Now%

Watch: Refactoring a Slow Animation

Di, 2015-09-08 17:30

In this screencast I'm going to show you how to refactor your CSS to improve and smoothen your animations. This screencast does come with code samples which can be found on CodePen - Demo 1 | Demo 2

Loading the player...

Continue reading %Watch: Refactoring a Slow Animation%

What’s New for Developers in Firefox OS 2.5

Di, 2015-09-08 17:00

Firefox OS 2.5 is scheduled for release on November 2nd, opening up a range of new possibilities, especially for developers. In this article I will show what you can expect in the next version of Firefox OS.

Continue reading %What’s New for Developers in Firefox OS 2.5%

Giveaway: Win Tickets To The Oracle JavaOne Conference!

Di, 2015-09-08 16:54

The Oracle JavaOne conference is right around the corner (October 25th-29th), and to get you pumped for the event, we’re giving away 40 free tickets! The conference, which is being held in San Francisco, is going to be part innovation, part exploration, and part celebration of Java’s 20 year history.

More Java Than Ever

Over 400 sessions are being offered this year, all taught by respective experts. If you want to explore a particular track, you can take the “Java and Security” track, “Emerging Languages” track, or one of the six other tracks. Or, you can explore by experience level or session type. Whatever your Java passion or pleasure, you can find it.

Keynotes

To celebrate Java’s 20th anniversary, Oracle executive and engineering experts will highlight memorable events that have taken place over the past 20 years, as well as forecast the future of Java. Using technical demonstrations, they’ll show how Java is, “...driving developer innovation, revolutionizing application development, and improving application services for the Internet of Things, enterprise architectures, and cloud computing.”

The Java Community keynote will celebrate the phenomenal 20 year history of Java, as well as use creative onstage demos to showcase the work of Java community gurus.

Java Hub

Get up close and personal with the latest Java innovations at the Java Hub.

Want to improve the future of Java? Stop by the Hackergarten and contribute to your favorite open source project.

Want to experience a hands-on demonstration of the power of Java technologies? Check out the MakerZone and see how Java is powering everything from game consoles to robots.

Want to see the intersection of Java and art? Don’t miss myMatrix, an interactive community project by media artist Wolf Nkole Helzle.

Want to see exactly how 3D modeling and printing work? Watch an exact clone of “Duke” be taken from “birth” all the way to 3D printing.

Want fresh coding tips from experienced developers? Don’t miss Nighthacking, where developers are interviewed and share coding tips.

Want a great cup of coffee? Grab a cup at the Oracle Technology Network Community Cafe, and chat with your baristas about anything Java related.

Java for Kids

Java isn’t just for adults! The JavaOne4Kids event wants to empower the next generation of programmers. With subjects like “Building An Arcade Game With Greenfoot” and “Minecraft Modding With Forge 1.8”, the event is a sure hit for young programmers. The event takes place Saturday, October 24th, and is geared for kids ages 10-18.

Duke's Cafe

Duke’s Cafe is a great place to grab a bite to eat, hang with friends, and maybe do a bit of hacking. There will be entertainment Monday -Thursday, and plenty of time and space for networking. Duke’s is your home away from home during JavaOne.

How to Win

SitePoint is partnering with Oracle to give away FORTY free tickets to the conference. To win a ticket to the conference, leave a comment below telling us how you’ll convince your boss to give you the week off for the conference. The best answers win.

See you there!

Continue reading %Giveaway: Win Tickets To The Oracle JavaOne Conference!%

The Absolute Beginner’s Guide to User Testing

Di, 2015-09-08 15:00

This article is a companion piece to my newly launched incrementalux podcast and is based on my learning from interviewing people much smarter than I am.

In Pursuit of the Perfect Product

While user-testing has always had a place in the web development process, perhaps it's the explosion of smartphones and internet-enabled devices that has really brought user-testing into the spotlight.

In the recent past, several design methodologies have focused on feedback from the end user. Lean UX places measuring feedback as one of its core tenets. User centered design puts the user,.. well, in the center.

Being a UX designer involves a lot of testing and gathering feedback. There are now many products in the marketplace that enable us to analyze and review our users. But, before you wear out that credit card on a raft of user testing software and services, you'll need (at least) an absolute beginner's understanding of the what, when, and how of user testing.

That's what I want to tackle today!

Let's start with the easiest question to answer.

When to Test

User testing is most effective when utilized before any effort goes into development. It helps to uncover issues on a conceptual or thinking level, before you begin coding or building. It helps to do a lot of testing before you commit to building a solution.

Test early, test often is a mantra that has been hammered into all of our heads. But, testing early alone is not sufficient.

[caption id="attachment_114443" align="aligncenter" width="615"] Source: Usertesting[/caption]

Meaning, the moment you have anything tangible, you begin testing with a user. The first napkin sketch or whiteboard diagram is a great place to begin your testing.

[caption id="attachment_114446" align="aligncenter" width="638"] Source: Zurb[/caption]

Paper prototypes allow you to draw and test out an entire flow. Here the user mimics their interactions with paper sketches. You, as a designer, get to test out the entire workflow and identify gaps in mental models of your users v/s the mental model of the system you built.

This phase of testing is both rapid and iterative. As soon as you identify issues, it's time for the next version to be quickly sketched and tested. Once you finish with throwaway prototypes like sketches and whiteboard diagrams, you can move on to more tangible wirefreames or photoshop mockups.

How to Test The 5 second test

Goal: A simple yes/no test to establish whether an idea is viable

The quickest and easiest way to gather feedback on designs is the 5 second test. Show your design to your team members, friends or spouses for 5 seconds and ask them questions like:

  • What do you think this design is about?
  • What is the primary action you could take?
  • What did you like about it?
  • What did you dislike about it?

This is a great way of quickly gathering feedback on whether the design is "hit or a miss". Whether the primary purpose of a screen is being conveyed instantly or not is a big deal in the attention economy, where users are bombarded with visuals, information, data and even bullshit. However, it's very binary and does not go into finer details.

Guerilla testing

Goal: Gather feedback on a design from random people at common places

‘Get out of the building’ is a fairly common phrase heard in the design community.

Continue reading %The Absolute Beginner’s Guide to User Testing%

How to Write Modular Code with Angular UI-Router & Named Views

Mo, 2015-09-07 20:00

One of the most important concepts in web development is writing clean, modular code. This is especially relevant when working as part of a team on highly complex applications. The Angular framework was built to create high-level applications, which can become very complex very fast, which in turn makes writing modular code all the more […]

Continue reading %How to Write Modular Code with Angular UI-Router & Named Views%

How to Make a Useful Toggl Time Tracker with Particle and Node

Mo, 2015-09-07 18:00

I have recently been tracking my time on projects more closely throughout the day. It is useful to see which projects take up more time than others and helps me measure which days I'm most productive (and what is distracting me!). My service of choice for this is Toggl. It is simple, clean and syncs across devices. Best of all - it has an API which you can hook up your own applications and devices to. I decided to set up a button connected to my Particle Photon that would start and stop my Toggl timer for me. I used a simple Node server to manage the communication between my Particle device and Toggl.

Clicking a physical button feels just that little bit more empowering than tapping a software button and prevents me needing to get out my smartphone or click around on my Mac to find the timer!

What You'll Need
  • A Particle Core or Photon - I'll be using a Particle Photon but both should be compatible with the demo
  • A physical button of some kind
  • A breadboard, resistors and jumper wires - If you are new to tinkering with microcontrollers, SparkFun has a great new Inventors Kit for the Photon
  • A Toggl account - If you don't have one, head to the Toggl website to sign up!
  • Knowledge of how to get code onto your Particle device - if you're new to this, I published a SitePoint article a few weeks back on connecting to the Photon. The Particle Core is similar.
  • A basic understanding of running a Node server and using npm - Peter Dierx at SitePoint has written a pretty comphrensive guide on starting with npm.

Note: Particle also sell a big physical button. You could quite likely adapt this concept to the big button for a lot of fun, I just don't own one of those... yet.

Finding Your API Keys

To get your Toggl API key, visit the Toggl "My Profile" Page. If you scroll down to the bottom of this page, you'll find a unique API token you can use like so:

Copy that token to a safe place. You'll need it!

You can also reset it using the tiny "Reset" link on the right hand side (useful in moments like just then when I revealed my API key to you all).

If it has been a while since your last Particle build session and you need a refresher on finding your Particle API key, go to the Particle Build online editor and click the gear icon at the very bottom to get to the settings page. From there, you'll see a screen which shows you your access token.

Copy that one too.

Our Particle Sketch

Our sketch with the layout of the breadboard, Particle device (shown as a Core in this pic but both this and a Photon will work), LED and button looks like so:

Download The Code

All of the code for this example can be found on GitHub.

Our Particle Code

Our Particle code will keep track of whether or not the button is pressed and whether or not we want to have our LED lit up or not. All the rest of the functionality will be taken care of by our Node server.

The Particle code looks like so:

[code language="c"]
int ledPin = D0;
int buttonPin = D5;
bool ready = true;
int last;

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
last = millis();
digitalWrite(ledPin, LOW);

Spark.function("ledTrigger", ledTrigger);
}

void loop() {
if (millis() - last > 200) {
if (digitalRead(buttonPin)) {
if (ready) {
ready = false;
Spark.publish("buttonPressed");
last = millis();
}
} else {
ready = true; // button ready to be pressed again
}
}
}

int ledTrigger(String value) {
if (value == "ON") {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}

return 0;
}
[/code]

I'll explain what each bit of that code means. To start with, we define our two components and the pins they are attached to. Our button is attached to D5 and our LED is attached to pin D0.

[code language="c"]
int ledPin = D0;
int buttonPin = D5;
[/code]

The next two variables are there to keep track of timing within our loop. ready tracks whether our button is ready to be pressed again. We want to ensure there is a period between when we first click it and when it can be clicked again. last is the variable which helps track this period of time, it keeps track of the last time the loop has been run. That might make more sense when you see it in action soon.

[code language="c"]
bool ready = true;
int last;
[/code]

In our setup() function, we start by setting the pin mode for our LED to output and set it to input for our button.

[code language="c"]
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);

// more code explained next!
}
[/code]

Continue reading %How to Make a Useful Toggl Time Tracker with Particle and Node%

Object Orientated Development with WordPress

Mo, 2015-09-07 17:00

Object Orientated code is everywhere and WordPress is no exception.

The Core of WordPress is built on series of objects/classes used to control everything from manipulation of the database to the look and feel of your site.

Throughout this tutorial, we will look into Object Orientated design and how you can use these in practical applications when developing for WordPress including:

  • Understanding exactly what object orientated design is.
  • Discussing why we should use object orientated design.
  • Examining a real world example to showcase how it can work.

Note 1: Also note that this tutorial outlines primarily WordPress centric concepts, so if you are entirely new to object orientated design you should probably get a quick overview of OO via the PHP reference guide.

Note 2: If you're keen on downloading everything right away feel free to download the source from my GitHub repository and follow along with the tutorial.

Let's jump right into it!

What Is Object Orientated Design Anyway?

Object Orientation Design (OO Design) is a different methodology for solving issues, separate from the traditional procedural approach.

With Object Orientated Design you create a structure (class) that will group together all of your related functions (methods) and information (properties) to solve an issue.

This is different from procedural development in which you create functions and variables to solve issues, however, these elements can be separated across multiple files, re-declared and often loosely related.

Continue reading %Object Orientated Development with WordPress%

How to Hire Your First Employees While Running Your Startup

Mo, 2015-09-07 16:00

Hiring your first employees is an exciting milestone for any startup founder. It’s a sign your startup is (literally) growing and getting traction. However, it’s also notoriously stressful, time-consuming and difficult. After all, if it’s just you and your co-founders, the first couple people you bring on board will contribute to a significant portion of […]

Continue reading %How to Hire Your First Employees While Running Your Startup%

Fast Multi-language Docs with SitePoint’s RTDSphinx-PHP

Mo, 2015-09-07 16:00

This post will guide you through getting up and running with RTDSphinx-PHP, a ReadTheDocs-friendly Sphinx based PHP documentation skeleton with sane defaults, pre-installed directives, and modified styles for optimal API and prose documentation rendering in multiple languages. For an unfinished example of the documentation, see here and switch the language in the bottom left flyout panel.

If this sounds familiar, it’s because we already went through a manual setup of a similar skeleton in a previous post, but that one had no localization support, too many steps, and wasn’t as reusable as this newly developed one. This guide will not be a “let’s build it from scratch” project, but rather an overview of the features this skeleton project offers out of the box, and an introduction into its usage.

This post will be the first in a long line of many SitePoint branded projects meant for wide-spread public consumption, fully open source and highly welcoming of other people’s contributions.

Quickstart

For prerequisites, make sure you have Python and pip, the Python package manager, installed.

First, clone the skeleton into a folder - either a subfolder of your project, like projectRoot/docs or into its own folder - anything goes.

git clone https://github.com/sitepoint/rtdsphinx-php docs

Optionally, create a Python virtual environment.

Then, while inside the cloned folder, install prerequisites from the requirements.txt file by running:

pip install -r requirements.txt

This will install all necessary packages.

That’s it. To generate files for a new language, run:

bin/update.sh xx

… where xx is the language code (e.g. “jp” for Japanese).
Then, edit files in locale/xx/LC_MESSAGES that end in .po.

To compile the HTML from these translations, run:

bin/build.sh xx yy zz

… where xx, yy and zz are language codes for all the languages you want to build. Inspect your generated HTML by opening _build/html/xx/index.html in a browser.

For deploying to ReadTheDocs, see below.

Continue reading %Fast Multi-language Docs with SitePoint’s RTDSphinx-PHP%

The Trick to Writing Fun, Engaging Article Intros

Mo, 2015-09-07 15:00

[caption id="attachment_114306" align="aligncenter" width="936"] Diamonds: Kim Alaniz[/caption]

Writing article introductions is seriously hard.

The truth is, most of us start with the middle section of our story in our mind. We want to explain how to do ‘x’ and or why we think ‘y’ is a good idea. Writing this part is generally easy, because we know exactly what we want to achieve.

Writing the conclusion isn’t too difficult once we’ve written the middle. We sum up what we’ve just written and perhaps add a personal insight or reflection. (* Footnote on writing conclusions below).

[caption id="attachment_114304" align="alignright" width="240"] First lines are hard — Photo: Alastair Thompson[/caption]

Intros are difficult in articles for the same reason that opening lines are difficult at parties, bars and park benches. We all know how to have a conversation, but finding a way to start a conversation with a stranger feels like a really high-stakes game. That’s probably explains why chat-up technique books sell tens of millions every year.

So, I guess I’m here to give you some clever chat-up lines for your readers.

Continue reading %The Trick to Writing Fun, Engaging Article Intros%

Build APIs with Napa

Mo, 2015-09-07 14:00

APIs are one of the hottest topics in web development. With the increasing number of SPAs (Single Page Applications) and the microservice craze, APIs will become even more popular. As Ruby on Rails developers, we have an amazing framework at our disposal, very capable of building APIs. Though Rails is powerful, it is more complex as well. Sometimes we need a simpler, more nimble framework, one that only does one thing and does it well. I think I have found such a framework. Allow me to introduce you to a framework that is specifically designed for building APIs: Napa.

Napa combines gems like Grape, Roar, and ActiveRecord, allowing us to build powerful APIs with minimal effort. In this tutorial, we will learn how to build an API with token authentication using Napa and Devise.

Continue reading %Build APIs with Napa%

How to Solve the Global npm Module Dependency Problem

Fr, 2015-09-04 18:00

The Node Package Manager (a.k.a. npm) has given web developers easy access to a lot of awesome JavaScript modules and has made our lives considerably easier when trying to find and manage dependencies for our applications. It also makes it easy for developers to create and publish their own modules, meaning that other developers can grab them with a simple npm install -g your-tool and start using them any time they want to. It’s utopia! Right?

Err, actually …

We’ve Got a Bit of a Problem

I will never say never use the -g option when installing an npm module, but I do have to say that we are causing problems by using it too much. There are a couple reasons that I think we should cut down on our use of global module installation, especially in the case of build, test, or linting tools such as Gulp, Karma, JSHint, and countless others. I’ll be referring primarily to Gulp throughout this article because it’s quite popular and it’s fun to say, but if you don’t like Gulp, just mentally replace it with whatever you prefer.

First of all, global modules are not listed as dependencies in your projects, even though your project depends on them, which causes extra steps for others using your application. You know that you need to use Gulp in order to get your project ready for production, so you install it globally and use it. When someone else wants to start working on, or using your wonderful open source project, they can’t just type npm install and get going. You end up having to throw directions into your README file saying something along the lines of

To use this project, follow these steps:

  • git clone the repo
  • Run npm install
  • Run npm install -g gulp
  • Run gulp to build

I see two issues with this: firstly, you are adding the extra step of installing Gulp globally and secondly, you are running gulp directly. I see an extra step that could have been avoided (globally installing Gulp) and I see that the user is required to know that your app uses Gulp in order to build the project. This first issue is the main one I’m going to address in this article, and although the second one isn’t as big of an issue, you’ll need to update the instructions if you end up switching tools. The solution I discuss later should fix both of these issues.

The second big issue relating to installing modules globally is that you can run into conflicts due to having the wrong version of the module installed. This is illustrated by the following two examples:

  • You created your project six months ago and you used the latest version of Gulp at that time. Today, someone has cloned your project’s repo and tried to run gulp to build it, but runs into errors. This is because the person who cloned your project is either running an older version or a newer version of Gulp that has some breaking differences.
  • You created a project six months ago that used Gulp. Since then you’ve moved on to other projects and updated Gulp on your machine. Now you go back to this old project and try to run gulp and you experience errors because you’ve updated Gulp since the last time you touched the project. Now you are forced to update your build process to work with the new version of Gulp before you can make any more progress on the project, instead of putting it off until a more convenient time.

These are potentially very crippling issues. Like I said earlier though, I wouldn’t make a blanket statement telling you never to install something globally. There are exceptions.

A Brief Note on Security

By default, on some systems, installing a npm module globally requires elevated privileges. If you find yourself running commands like sudo npm install -g a-package, you should change this. Our beginners guide to npm shows you how.

Continue reading %How to Solve the Global npm Module Dependency Problem%

Watch: A Tour of Android Studio

Fr, 2015-09-04 17:30

Android Studio is now the official IDE for Android development. In this video we look at how to download and install it, tour the interface an look at some of the tools and features it offers.

Loading the player...

Continue reading %Watch: A Tour of Android Studio%