Skip to content

lexich/browserify-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About browserify-node

Transformer for browserify to generate clientside code.
Build Status NPM version Coverage Status

###Information

  • Include file with node.js extention
  • In this file define exports funtion which return string of client js code
//test.node.js
module.exports = function() {
  return "{hello: \"world\"}";
}
  • require test.node.js file using browserify infrastructure
var test = require("test.node");
test.hello === "world"; // true

Instalation

npm install browserify-node --save-dev

Example

For example we want to load async text file

//text.node.js
var fs = require("fs");
var md5 = require("md5");
module.exports = function() {
  var data = fs.readFileSync("./text.txt");
  var hash = md5(data);
  var json = "{content:\"" + data + "\"}";
  var filename = "test-" + hash + ".json";
  fs.writeFileSync(filename, json);
  return "function(){ return $.getJSON('" + filename + "'); }"
}
//app.js
var text = require("text.node");
text().done(function(json) {
  console.log(json.content);
});

About

Generate clientside javascript in node environment

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published