Permalink
Browse files

update custom types example

do not execute console.log when module is required
and exports are used
  • Loading branch information...
1 parent 9cc570a commit 0b9042f284b95bb7dccdfeac57c89a0591bebc00 @rockitbaby rockitbaby committed Apr 29, 2015
Showing with 15 additions and 15 deletions.
  1. +15 −15 examples/custom_types.js
@@ -79,23 +79,23 @@ var SpaceYamlType = new yaml.Type('!space', {
var SPACE_SCHEMA = yaml.Schema.create([ SpaceYamlType, PointYamlType ]);
-
-// And read a document using that schema.
-
-fs.readFile(path.join(__dirname, 'custom_types.yml'), 'utf8', function (error, data) {
- var loaded;
-
- if (!error) {
- loaded = yaml.load(data, { schema: SPACE_SCHEMA });
- console.log(util.inspect(loaded, false, 20, true));
- } else {
- console.error(error.stack || error.message || String(error));
- }
-});
-
+// do not execute the following if file is required (http://stackoverflow.com/a/6398335)
+if (require.main === module) {
+
+ // And read a document using that schema.
+ fs.readFile(path.join(__dirname, 'custom_types.yml'), 'utf8', function (error, data) {
+ var loaded;
+
+ if (!error) {
+ loaded = yaml.load(data, { schema: SPACE_SCHEMA });
+ console.log(util.inspect(loaded, false, 20, true));
+ } else {
+ console.error(error.stack || error.message || String(error));
+ }
+ });
+}
// There are some exports to play with this example interactively.
-
module.exports.Point = Point;
module.exports.Space = Space;
module.exports.PointYamlType = PointYamlType;

0 comments on commit 0b9042f

Please sign in to comment.