Node bits

Parse a Markup & read contents of a folder

const md = require('commonmark');
const fs = require('fs-extra');


const parser = new md.Parser();
const renderer = new md.HtmlRenderer();

var input = '# This is a header\n\nAnd this is a paragraph';
var content = renderer.render(parser.parse(input)).trim();

console.log(content);

// __dirname
fs.readdir(__dirname, function (err, files) {
 if (err) throw err;
 for (var index in files) {
    console.log(files[index]);
 }
});
// package.json
{
  "author": "Hamzeen H ",
  "bin": "hello.js",
  "bugs": {
    "url": "https://github.com/hamzeen/hamzeen.github.io/issues"
  },
  "dependencies": {
    "commonmark": "^0.25.0",
    "fs-extra": "^0.29.0"
  }
}

Build an Ember Project and Launch

// build.js
var sys = require("sys"),
    exec = require('child_process').exec,
    util = require('util');

var visits = 0;
var result = exec("ember s --port=4300", function(err, stdout, stderr) {
  //sys.puts("1::");
});
//sys.puts("Obj:: "+util.inspect(result, false, null));

result.stdout.on('data', function(data) {

  visits += 1;
  if(visits == 5) {
    sys.puts("1 [Serving at 4300]");

    var spawn = require('child_process').spawn
    var sp = spawn('open', ['http://localhost:4300']);
    sp.on('exit', function (code) {
      sys.puts("2 [Opened Browser]");
    });
  }
});
Advertisements