Welcome!

@DevOpsSummit Authors: Liz McMillan, Elizabeth White, Pat Romanski, Yeshim Deniz, Zakia Bouachraoui

Related Topics: @DevOpsSummit, Java IoT, Microservices Expo

@DevOpsSummit: Blog Feed Post

Node.js ABCs - L Is for Loading | @DevOpsSummit #DevOps

A great benefit of utilizing a language like Node.js is the wide assortment of 3rd party modules that are at your disposal

One of the great benefits of utilizing a language like Node.js is the wide assortment of 3rd party modules that are at your disposal.  From calculating the validity of credit card numbers, to managing network connections, the Node Package Manager (npm) repository has hundreds of thousands of packages available to you.  This article will explain how you can load modules into your project.

Loading and Referencing a Module
In Node.js, modules are accessed either by their name or the file path on the system.  Non-system modules referenced by name will eventually be mapped into a file system path.

Each module exposes a public interface that can be used after the module is imported with the "require" into the current script.

var mod = require("some_module_name");

LoadingDockEquipment

The previous command will import and return an object that represents the external API exposed by the module.  The value of that object is dependent on the module and can include an object, an array, a function, or any other type of JavaScript object.

Developing and Exporting Modules
For the module developer, you must use the CommonJS Module System to make your modules available to the outside world.  Let's create a sample module “person.js” that exports a Person constructor.

/* File person.js */
function Person(name) {
var _name = name;
function name() {
return _name;
}
}
module.exports = Person;

In the above example, the Person function is defined and then specified with the "module.exports" object that the module will export to other scripts that require this module.

As mentioned above, more complex objects can be exported by adding onto the module.exports object with whatever values you deem fit for your module.

/* file mymodule.js */
function sayHi() { console.log("HI!!!"); }
function sayBye() { console.log("BYE!!!"); }
module.exports.sayHi = sayHi;
module.exports.sayBye = sayBye;

Below is the code to load the module and call the sayHi and sayBye functions.

var mymodule = require("./mymodule");
mymodule.sayHi();
HI!!!
mymodule.sayBye();
BYE!!!

Loading a Module
There are a couple of ways to reference modules depending on their kind.  There are core modules, 3rd party modules, or local modules.

Core Modules
Since core modules are part of the distribution, you need only refer to it by it's name (not the path).  Core modules with name collisions to local modules take precedence.  The following line will load a instance of the core "http" module.

var http = require('http');

File Module
A file module is a one that is defined in a single file on the file system.  The person.js example above is an example of a file module.  When loading a file module, you supply a path (full or relative) to the module file, optionally omitting the .js extension.

var mymodule = require("/home/joe/node/modules/mymodule");
var mymodule = require("./mymodule");

In those examples the loader will look for a file named "mymodule.js" in the specified directory.

Folder Modules
Like a file module, when loading a folder module, you specify the absolute or relative location of the folder.  The Node loader will assume this folder is a package and attempt to look for a package definition file (package.json) in which the name and location of the module file are located.  If no package.json file exists, the Node loader will look for a file named index.js.

Loader search procedure
If the module name is not a path and is not a core module, the loader will attempt to find it inside the special "node_modules" folder.  If the module doesn't exist there, it will continue up the path, folder by folder, looking within node_modules folders on those directories until either finds the module or hits the root of the file system.

Conclusion
That's about all there is to it for exporting and loading a Node.js module.  Creating modules is as easy as writing the module code and specifying what is returned with the module.exports object.  Then a simple call to require("module") is all the client has to write to make use of it.

Read the original blog entry...

More Stories By Joe Pruitt

Joe Pruitt is a Principal Strategic Architect at F5 Networks working with Network and Software Architects to allow them to build network intelligence into their applications.

@DevOpsSummit Stories
"DevOps is set to be one of the most profound disruptions to hit IT in decades," said Andi Mann. "It is a natural extension of cloud computing, and I have seen both firsthand and in independent research the fantastic results DevOps delivers. So I am excited to help the great team at @DevOpsSUMMIT and CloudEXPO tell the world how they can leverage this emerging disruptive trend."
The current age of digital transformation means that IT organizations must adapt their toolset to cover all digital experiences, beyond just the end users’. Today’s businesses can no longer focus solely on the digital interactions they manage with employees or customers; they must now contend with non-traditional factors. Whether it's the power of brand to make or break a company, the need to monitor across all locations 24/7, or the ability to proactively resolve issues, companies must adapt to the new world.
You want to start your DevOps journey but where do you begin? Do you say DevOps loudly 5 times while looking in the mirror and it suddenly appears? Do you hire someone? Do you upskill your existing team? Here are some tips to help support your DevOps transformation. Conor Delanbanque has been involved with building & scaling teams in the DevOps space globally. He is the Head of DevOps Practice at MThree Consulting, a global technology consultancy. Conor founded the Future of DevOps Thought Leaders Debate. He regularly supports and sponsors Meetup groups such as DevOpsNYC and DockerNYC.
DXWorldEXPO LLC announced today that ICC-USA, a computer systems integrator and server manufacturing company focused on developing products and product appliances, will exhibit at the 22nd International CloudEXPO | DXWorldEXPO. DXWordEXPO New York 2018, colocated with CloudEXPO New York 2018 will be held November 11-13, 2018, in New York City. ICC is a computer systems integrator and server manufacturing company focused on developing products and product appliances to meet a wide range of computational needs for many industries. Their solutions provide benefits across many environments, such as datacenter deployment, HPC, workstations, storage networks and standalone server installations. ICC has been in business for over 23 years and their phenomenal range of clients include multinational corporations, universities, and small businesses.
René Bostic is the Technical VP of the IBM Cloud Unit in North America. Enjoying her career with IBM during the modern millennial technological era, she is an expert in cloud computing, DevOps and emerging cloud technologies such as Blockchain. Her strengths and core competencies include a proven record of accomplishments in consensus building at all levels to assess, plan, and implement enterprise and cloud computing solutions. René is a member of the Society of Women Engineers (SWE) and a member of the Society of Information Management (SIM) Atlanta Chapter. She received a Business and Economics degree with a minor in Computer Science from St. Andrews Presbyterian University (Laurinburg, North Carolina). She resides in metro-Atlanta (Georgia).