Created
September 13, 2017 16:03
-
-
Save muhammadghazali/d055e1b7b7b6cb3bab7f977cf17e163f to your computer and use it in GitHub Desktop.
This is a silly world hello module that can be used on the Node.js and browser environment. Credits to this blog post: https://caolan.org/posts/writing_for_node_and_the_browser.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(exports => (exports.greet = () => "Hello world"))( | |
typeof exports === "undefined" ? (this["hello"] = {}) : exports | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Document</title> | |
</head> | |
<body> | |
<script src="hello.js"></script> | |
<script> | |
console.log(hello.greet()); | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// try to run this in your console | |
// node index.js | |
const hello = require("./hello.js"); | |
console.log(hello.greet()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment