├── .gitignore ├── 03lowdb └── code │ └── package-lock.json ├── 05website └── code │ └── package-lock.json ├── 06nedb └── code │ └── package-lock.json ├── 07restapi └── code │ └── bin │ └── package-lock.json ├── Docsify.md ├── LICENSE.md ├── README.md ├── TODO.md ├── __book.json ├── __express ├── app.js ├── bin │ └── www ├── package-lock.json ├── package.json ├── public │ └── stylesheets │ │ └── style.css ├── routes │ ├── index.js │ └── users.js └── views │ ├── error.jade │ ├── index.jade │ └── layout.jade ├── build.hxml ├── build_interp.hxml ├── contribute.md ├── docs ├── .nojekyll ├── 00helloworld │ ├── about.md │ ├── code │ │ ├── bin │ │ │ └── example.js │ │ ├── build.hxml │ │ ├── javascript.hxml │ │ └── src │ │ │ └── Main.hx │ ├── example.md │ └── installation.md ├── 01writing │ ├── about.md │ ├── code │ │ ├── bin │ │ │ ├── example.js │ │ │ └── hello.txt │ │ ├── build.hxml │ │ ├── javascript.hxml │ │ └── src │ │ │ └── Main.hx │ ├── example.md │ └── installation.md ├── 02reading │ ├── about.md │ ├── code │ │ ├── bin │ │ │ ├── example.js │ │ │ └── hello.txt │ │ ├── build.hxml │ │ ├── javascript.hxml │ │ └── src │ │ │ └── Main.hx │ ├── example.md │ └── installation.md ├── 03lowdb │ ├── about.md │ ├── code │ │ ├── bin │ │ │ └── example.js │ │ ├── build.hxml │ │ ├── dts2hx_convert.md │ │ ├── package-lock.json │ │ ├── package.json │ │ └── src │ │ │ └── Main.hx │ ├── example.md │ ├── installation.md │ └── test.md ├── 04haxelow │ ├── about.md │ ├── code │ │ ├── bin │ │ │ ├── db.json │ │ │ └── example.js │ │ ├── build.hxml │ │ ├── package.json │ │ └── src │ │ │ └── Main.hx │ ├── example.md │ └── installation.md ├── 05website │ ├── about.md │ ├── code │ │ ├── _package.json │ │ ├── bin │ │ │ ├── example.js │ │ │ └── public │ │ │ │ ├── favicon.ico │ │ │ │ ├── index_advanced.html │ │ │ │ ├── index_intermediate.html │ │ │ │ ├── remote_intermediate.html │ │ │ │ └── views │ │ │ │ ├── _index.pug │ │ │ │ ├── error.pug │ │ │ │ ├── index.pug │ │ │ │ └── layout.pug │ │ ├── build_00.hxml │ │ ├── build_01.hxml │ │ ├── build_02.hxml │ │ ├── build_03.hxml │ │ ├── build_04.hxml │ │ ├── package-lock.json │ │ ├── package.json │ │ └── src │ │ │ ├── Main00.hx │ │ │ ├── Main01.hx │ │ │ ├── Main02.hx │ │ │ ├── Main03.hx │ │ │ ├── Main04.hx │ │ │ └── routes │ │ │ ├── Index.hx │ │ │ └── Users.hx │ ├── exampleAdvanced.md │ ├── exampleBasic.md │ ├── exampleIntermediate.md │ ├── installation.md │ ├── test.md │ ├── tip.md │ └── todo.md ├── 06nedb │ ├── about.md │ ├── code │ │ ├── bin │ │ │ ├── database01.db │ │ │ ├── database02.db │ │ │ ├── database03.db │ │ │ ├── example01.js │ │ │ ├── example02.js │ │ │ └── example03.js │ │ ├── build_01.hxml │ │ ├── build_02.hxml │ │ ├── build_03.hxml │ │ ├── build_all.hxml │ │ ├── dts2hx_convert.md │ │ ├── package-lock.json │ │ ├── package.json │ │ └── src │ │ │ ├── Main01.hx │ │ │ ├── Main02.hx │ │ │ └── Main03.hx │ ├── example.md │ ├── example2.md │ └── installation.md ├── 07restapi │ ├── about.md │ ├── code │ │ ├── bin │ │ │ ├── example.js │ │ │ ├── package-lock.json │ │ │ ├── package.json │ │ │ ├── package.txt │ │ │ └── public │ │ │ │ ├── favicon.gif │ │ │ │ ├── favicon.ico │ │ │ │ └── index.html │ │ ├── build.hxml │ │ ├── src │ │ │ ├── Controller.hx │ │ │ ├── Main.hx │ │ │ ├── Routes.hx │ │ │ └── js │ │ │ │ └── npm │ │ │ │ └── express │ │ │ │ └── Logger.hx │ │ └── test.md │ ├── example.md │ └── installation.md ├── 09slackbot │ ├── about.md │ ├── code │ │ ├── bin │ │ │ └── example.js │ │ ├── build copy.hxml │ │ ├── build.hxml │ │ ├── javascript.hxml │ │ ├── package.json │ │ └── src │ │ │ ├── Main.hx │ │ │ └── slack │ │ │ └── Webhook.hx │ ├── example.md │ └── installation.md ├── 10scraping │ ├── about.md │ ├── code │ │ ├── bin │ │ │ └── example.js │ │ ├── build copy.hxml │ │ ├── build.hxml │ │ ├── javascript.hxml │ │ ├── package.json │ │ └── src │ │ │ └── Main.hx │ ├── example.md │ └── installation.md ├── 11automation │ ├── TODO.md │ ├── about.md │ ├── code │ │ ├── GruntFile.js │ │ ├── bin │ │ │ └── example.js │ │ ├── build.hxml │ │ ├── javascript.hxml │ │ ├── package.json │ │ └── src │ │ │ └── Main.hx │ ├── code2 │ │ ├── bin │ │ │ ├── example.js │ │ │ └── example.js.map │ │ ├── build copy.hxml │ │ ├── build.hxml │ │ ├── javascript.hxml │ │ ├── package.json │ │ └── src │ │ │ └── Main.hx │ ├── example.md │ ├── example2.md │ ├── installation.md │ └── installation2.md ├── 12socket │ ├── about.md │ ├── bug.txt │ ├── code │ │ ├── bin │ │ │ ├── example.js │ │ │ └── public │ │ │ │ ├── favicon.ico │ │ │ │ ├── js │ │ │ │ ├── client.js │ │ │ │ └── client.js.map │ │ │ │ └── views │ │ │ │ └── page.jade │ │ ├── build copy.hxml │ │ ├── build.hxml │ │ ├── javascript.hxml │ │ ├── package.json │ │ └── src │ │ │ ├── Main.hx │ │ │ └── MainClient.hx │ ├── example.md │ ├── installation.md │ └── todo.md ├── 13sequelize │ ├── about.md │ ├── code │ │ ├── bin │ │ │ ├── db │ │ │ │ └── database.sqlite │ │ │ ├── example.js │ │ │ └── example.js.map │ │ ├── build copy.hxml │ │ ├── build.hxml │ │ ├── package.json │ │ └── src │ │ │ └── Main.hx │ ├── example.md │ └── installation.md ├── 14jsondb │ └── code │ │ ├── bin │ │ ├── database.json │ │ └── example.js │ │ ├── build copy.hxml │ │ ├── build.hxml │ │ ├── src │ │ ├── JsonDB.hx │ │ └── Main.hx │ │ └── todo.md ├── GLOSSARY.md ├── README.md ├── __express │ ├── app.js │ ├── bin │ │ └── www │ ├── package-lock.json │ ├── package.json │ ├── public │ │ └── stylesheets │ │ │ └── style.css │ ├── routes │ │ ├── index.js │ │ └── users.js │ └── views │ │ ├── error.jade │ │ ├── index.jade │ │ └── layout.jade ├── _sidebar.md ├── favicon.ico ├── haxe │ ├── _hxml.md │ ├── _terminal.md │ ├── about.md │ ├── choosing-a-code-editor.md │ ├── code │ │ ├── Test.hx │ │ ├── compile.hxml │ │ ├── test.html │ │ └── test.js │ ├── hello-world.md │ ├── installation.md │ ├── learn-haxe.md │ └── quick-install.md ├── haxenode │ ├── about.md │ ├── cheatsheet.md │ ├── copy_paste.md │ ├── download.md │ ├── example.md │ ├── externs.md │ ├── installation.md │ ├── resource.md │ ├── what.md │ └── why.md ├── img │ ├── cover.jpg │ ├── cover.png │ ├── cover_small.jpg │ ├── haxe-logo.svg │ ├── haxe_javascript_logos.png │ ├── haxe_logo.png │ ├── haxe_nodejs_logos.png │ ├── haxe_php_logos.png │ ├── haxe_python_logos.png │ ├── helloworld.png │ ├── install.jpg │ ├── javascript_logo.png │ ├── macdown-logo-200.png │ ├── macdown-logo.png │ ├── markdown-logo-200.png │ ├── markdown-logo.png │ ├── nodejs-light.eps │ ├── nodejs_logo.png │ ├── npm-logo.svg │ ├── tldr.gif │ └── web-trifecta.svg ├── index.html ├── intro.md ├── level.md └── resources │ ├── follow.md │ └── more.md ├── icon.png ├── package-lock.json └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | 3 | 4 | 5 | docs/05website/code/.haxelib 6 | docs/*/code/.haxelib 7 | docs/03lowdb/code/.haxelib 8 | docs/.haxelib 9 | */*/.haxelib 10 | -------------------------------------------------------------------------------- /03lowdb/code/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "requires": true, 3 | "lockfileVersion": 1, 4 | "dependencies": { 5 | "@types/lodash": { 6 | "version": "4.14.162", 7 | "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.162.tgz", 8 | "integrity": "sha512-alvcho1kRUnnD1Gcl4J+hK0eencvzq9rmzvFPRmP5rPHx9VVsJj6bKLTATPVf9ktgv4ujzh7T+XWKp+jhuODig==" 9 | }, 10 | "@types/lowdb": { 11 | "version": "1.0.9", 12 | "resolved": "https://registry.npmjs.org/@types/lowdb/-/lowdb-1.0.9.tgz", 13 | "integrity": "sha512-LBRG5EPXFOJDoJc9jACstMhtMP+u+UkPYllBeGQXXKiaHc+uzJs9+/Aynb/5KkX33DtrIiKyzNVTPQc/4RcD6A==", 14 | "requires": { 15 | "@types/lodash": "*" 16 | } 17 | }, 18 | "dts2hx": { 19 | "version": "0.14.6", 20 | "resolved": "https://registry.npmjs.org/dts2hx/-/dts2hx-0.14.6.tgz", 21 | "integrity": "sha512-7Rqfr/RbHSHY+tvlZIOT1aclzEjaKIextNK80/ljFgisUjJYRAKdIREdy6oBdjTMi7Ywt4Pztn1PfloZlWxwtA==", 22 | "dev": true, 23 | "requires": { 24 | "typescript": "3.7.4" 25 | } 26 | }, 27 | "graceful-fs": { 28 | "version": "4.2.4", 29 | "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.4.tgz", 30 | "integrity": "sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw==" 31 | }, 32 | "is-promise": { 33 | "version": "2.2.2", 34 | "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.2.2.tgz", 35 | "integrity": "sha512-+lP4/6lKUBfQjZ2pdxThZvLUAafmZb8OAxFb8XXtiQmS35INgr85hdOGoEs124ez1FCnZJt6jau/T+alh58QFQ==" 36 | }, 37 | "lodash": { 38 | "version": "4.17.20", 39 | "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", 40 | "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==" 41 | }, 42 | "lowdb": { 43 | "version": "1.0.0", 44 | "resolved": "https://registry.npmjs.org/lowdb/-/lowdb-1.0.0.tgz", 45 | "integrity": "sha512-2+x8esE/Wb9SQ1F9IHaYWfsC9FIecLOPrK4g17FGEayjUWH172H6nwicRovGvSE2CPZouc2MCIqCI7h9d+GftQ==", 46 | "requires": { 47 | "graceful-fs": "^4.1.3", 48 | "is-promise": "^2.1.0", 49 | "lodash": "4", 50 | "pify": "^3.0.0", 51 | "steno": "^0.4.1" 52 | } 53 | }, 54 | "pify": { 55 | "version": "3.0.0", 56 | "resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz", 57 | "integrity": "sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY=" 58 | }, 59 | "steno": { 60 | "version": "0.4.4", 61 | "resolved": "https://registry.npmjs.org/steno/-/steno-0.4.4.tgz", 62 | "integrity": "sha1-BxEFvfwobmYVwEA8J+nXtdy4Vcs=", 63 | "requires": { 64 | "graceful-fs": "^4.1.3" 65 | } 66 | }, 67 | "typescript": { 68 | "version": "3.7.4", 69 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.4.tgz", 70 | "integrity": "sha512-A25xv5XCtarLwXpcDNZzCGvW2D1S3/bACratYBx2sax8PefsFhlYmkQicKHvpYflFS8if4zne5zT5kpJ7pzuvw==", 71 | "dev": true 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Docsify.md: -------------------------------------------------------------------------------- 1 | # Convert from Gitbook to Docsify 2 | 3 | I used Gitbook for generation of this documentation. However, recently I started looking for alternatives in case GitBook stops being free. 4 | 5 | The tools I had didn't work anymore, didn't want to make an login on the new platform. 6 | 7 | I have worked with docsify before and the migration is really easy. 8 | 9 | ## How to migrate to docsify.js? 10 | 11 | First Install docsify: 12 | 13 | ```bash 14 | npm i docsify-cli -g 15 | ``` 16 | 17 | 1. Initialize docsify on your repo folder: `docsify init docs` (default gitlab will use `docs` folder for documentation) 18 | 2. Rename `summary.md` to `_sidebar.md` (yes, it’s that simple!) 19 | 3. Copy all the folders/files into `docs` folder 20 | 4. Add `loadSidebar: true` to `window.$docsify` in `index.html` 21 | 5. That’s all there is to it! Now run: `docsify serve` 22 | 6. And push it to Github. 23 | 7. update absolute links to new docs (`tree/master/` to `tree/master/docs/`) 24 | 25 | Specific for my documentation: 26 | 27 | - copy `readme.md` to docs 28 | - copy `.nojekyll` to docs (if not generated) 29 | - copy `index.html` to docs (if not generated) 30 | - copy `favicon.ico` to docs 31 | - update `index.html` the js: `window.$docsify` 32 | - copy data from `book.json` to `window.$docsify` 33 | - change `_sidebar.md` "example" to example 34 | - change `_sidebar.md` "How to" to "More info" 35 | 36 | 37 | 38 | ## Resource 39 | 40 | - https://docsify.js.org 41 | - https://timdams.com/2019/05/02/migrating-from-gitbook-to-docsify-js/ 42 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Matthijs Kamstra 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Haxe and Node.js 2 | 3 | I wanted to do a quick prototype with Node.js and my favorite programming language Haxe. 4 | But I couldn't find any documentation on how to start. 5 | 6 | There used to be a website (an old one, from when Haxe spelled "haXe") that got you started. 7 | 8 | But that is no more. I decided to get some of that back. 9 | Based upon the information from the old site and my own need to document this. 10 | 11 | #### Visit the [http://matthijskamstra.github.io/haxenode/](http://matthijskamstra.github.io/haxenode/) ! 12 | 13 | 14 | ## How to contribute? 15 | 16 | Read more about that [here](contribute.md). 17 | But it boils down to: **JUST DO IT!** 18 | 19 | #### Visit [https://github.com/MatthijsKamstra/haxenode](https://github.com/MatthijsKamstra/haxenode) to modify the "source" aka markdown files. 20 | 21 | Found any "bug" or have a great idea? Please create a [new issue](https://github.com/MatthijsKamstra/haxenode/issues/new). 22 | 23 | 24 | ### How to build? 25 | 26 | I will be using [Gitbook](https://github.com/GitbookIO/gitbook#how-to-use-it) to export to static `html`. 27 | You need to install Node.js and then you automatically have NPM: 28 | 29 | Install gitbook 30 | 31 | ```bash 32 | npm install gitbook-cli -g 33 | ``` 34 | 35 | or if you have gitbook installed, update it 36 | 37 | ```bash 38 | gitbook update 39 | ``` 40 | 41 | I wanted to make the editing of these file as-easy-as-possible. 42 | This gitbook plugin helps with that: [gitbook plugin edit link](https://www.npmjs.com/package/gitbook-plugin-edit-link). 43 | And if all fails, I used [Disqus comments on your books](https://github.com/GitbookIO/plugin-disqus) to add comments at the bottom of each page. 44 | 45 | Activate the plugins with: 46 | 47 | ```bash 48 | gitbook install 49 | ``` 50 | 51 | Export everything to `html` 52 | 53 | ```bash 54 | gitbook build 55 | ``` 56 | 57 | ---- 58 | 59 | ### What is Gitbook? 60 | 61 | ![Gitbook logo](https://avatars0.githubusercontent.com/u/7111340?v=3&s=200) 62 | 63 | I will be using [gitbook](https://github.com/GitbookIO/gitbook) to generate the website. 64 | 65 | Primarily reason for this: I have never used it, it uses markdown as input files and it also generates a static `html` site. 66 | 67 | 68 | ### What is Markdown 69 | 70 | ![Markdown logo](img/markdown-logo-200.png) 71 | A familiar way to write documentation for developers. 72 | This should make it easier to **contribute**! 73 | 74 | **Markdown** is a plain text formatting syntax created by John Gruber, aiming to provide a easy-to-read and feasible markup. You can find the original Markdown syntax specification [here](http://daringfireball.net/projects/markdown/syntax). 75 | 76 | 77 | ![MacDown logo](img/macdown-logo-200.png) 78 | **MacDown** is a simple-to-use editor for Markdown documents. It renders your Markdown contents real-time into HTML, and display them in a preview panel. You can download it [here](http://macdown.uranusjr.com/). 79 | 80 | 81 | 82 | ### Original Haxenode.org? 83 | You can find the original data at the github account of [theRemix](https://github.com/theRemix/haxenode.org/tree/ajaxloaded/views) in `.jade` files 84 | -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | # TODO 2 | 3 | ``` 4 | -D hxnodejs_no_version_warning 5 | ``` 6 | 7 | ``` 8 | import js.Node.console; 9 | 10 | ... 11 | 12 | console.log() 13 | 14 | ``` 15 | 16 | - https://revolugame.com/2017/03/04/haxe-nodejs-module.html 17 | 18 | * ask permission from writers blogposts 19 | * write about this article 20 | - http://saumya.github.io/ray/articles/50/ 21 | * https://github.com/clemos/haxetelier-haxe-nodejs 22 | * https://github.com/janekp/saffron 23 | 24 | ### autoconvert 25 | 26 | - http://lib.haxe.org/p/refactor 27 | 28 | ``` 29 | js_to_haxe.cmd 30 | ``` 31 | 32 | ```bash 33 | haxelib install refactor 34 | 35 | ``` 36 | 37 | ## automated convert 38 | 39 | haxelib run refactor convert --exclude-string-literals --exclude-comments PATH_TO_SOURCE_JS_FOLDER \*.js PATH_TO_DEST_HAXE_FOLDER /[.]js/.hx/ js_to_haxe.rules 40 | 41 | haxelib run refactor convert --exclude-string-literals --exclude-comments ~/Documents/workingdir/haxe/haxejs/05externs/code/bin \*.js ~/Documents/workingdir/haxe/haxejs/05externs/code/bin/out /[.]js/.hx/ js_to_haxe.rules 42 | 43 | --- 44 | 45 | https://www.patreon.com/posts/2740520 46 | 47 | ### Examples DB 48 | 49 | https://github.com/louischatriot/nedb 50 | 51 | ### desktop 52 | 53 | https://github.com/nwjs/nw.js/ 54 | 55 | --- 56 | 57 | http://book.mixu.net/node/ch10.html 58 | 59 | --- 60 | 61 | http://stackoverflow.com/questions/14116253/import-haxe-modules-into-a-node-js-script 62 | 63 | //Haxenode.hx 64 | 65 | class Haxenode { 66 | @:expose("hello") 67 | public static function hello(){ 68 | return "hello"; 69 | } 70 | } 71 | @:expose("hello") part is to put something in module.exports. 72 | 73 | Now launch 74 | 75 | haxe -js haxenode.js -dce no Haxenode 76 | Now you can use haxenode.js in nodejs 77 | 78 | var haxenode = require('./haxenode.js'); 79 | var hello = haxenode.hello; 80 | So, this combined together is an answer to your question: 81 | 82 | var cp = require('child_process'); 83 | 84 | function requireHaxe(haxeClassPath,cb){ 85 | //generate a JavaScript module from the Haxe file, and then return the generated JavaScript module 86 | 87 | cp.exec('haxe -js haxenode.js -dce no ' + haxeClassPath,function(err){ 88 | if (err){ 89 | cb(err); return; 90 | } 91 | 92 | cb(null,require('./haxenode.js')); 93 | }); 94 | 95 | } 96 | Mind that output filename is a stub. 97 | 98 | But don't do that - better to compile haxe as build step (with all necessary compile options) and then use regular require at runtime. 99 | -------------------------------------------------------------------------------- /__book.json: -------------------------------------------------------------------------------- 1 | { 2 | "gitbook": ">=2.0.0", 3 | "structure": { 4 | "readme": "intro.md" 5 | }, 6 | "plugins": ["edit-link", "disqus", "ga", "anchors"], 7 | "pluginsConfig": { 8 | "edit-link": { 9 | "base": "https://github.com/MatthijsKamstra/haxenode/blob/master/docs/", 10 | "label": "" 11 | }, 12 | "disqus": { 13 | "shortName": "haxeandnodejs" 14 | }, 15 | "ga": { 16 | "token": "UA-67866831-2" 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /__express/app.js: -------------------------------------------------------------------------------- 1 | var createError = require('http-errors'); 2 | var express = require('express'); 3 | var path = require('path'); 4 | var cookieParser = require('cookie-parser'); 5 | var logger = require('morgan'); 6 | 7 | var indexRouter = require('./routes/index'); 8 | var usersRouter = require('./routes/users'); 9 | 10 | var app = express(); 11 | 12 | // view engine setup 13 | app.set('views', path.join(__dirname, 'views')); 14 | app.set('view engine', 'jade'); 15 | 16 | app.use(logger('dev')); 17 | app.use(express.json()); 18 | app.use(express.urlencoded({ extended: false })); 19 | app.use(cookieParser()); 20 | app.use(express.static(path.join(__dirname, 'public'))); 21 | 22 | app.use('/', indexRouter); 23 | app.use('/users', usersRouter); 24 | 25 | // catch 404 and forward to error handler 26 | app.use(function(req, res, next) { 27 | next(createError(404)); 28 | }); 29 | 30 | // error handler 31 | app.use(function(err, req, res, next) { 32 | // set locals, only providing error in development 33 | res.locals.message = err.message; 34 | res.locals.error = req.app.get('env') === 'development' ? err : {}; 35 | 36 | // render the error page 37 | res.status(err.status || 500); 38 | res.render('error'); 39 | }); 40 | 41 | module.exports = app; 42 | -------------------------------------------------------------------------------- /__express/bin/www: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /** 4 | * Module dependencies. 5 | */ 6 | 7 | var app = require('../app'); 8 | var debug = require('debug')('express:server'); 9 | var http = require('http'); 10 | 11 | /** 12 | * Get port from environment and store in Express. 13 | */ 14 | 15 | var port = normalizePort(process.env.PORT || '3000'); 16 | app.set('port', port); 17 | 18 | /** 19 | * Create HTTP server. 20 | */ 21 | 22 | var server = http.createServer(app); 23 | 24 | /** 25 | * Listen on provided port, on all network interfaces. 26 | */ 27 | 28 | server.listen(port); 29 | server.on('error', onError); 30 | server.on('listening', onListening); 31 | 32 | /** 33 | * Normalize a port into a number, string, or false. 34 | */ 35 | 36 | function normalizePort(val) { 37 | var port = parseInt(val, 10); 38 | 39 | if (isNaN(port)) { 40 | // named pipe 41 | return val; 42 | } 43 | 44 | if (port >= 0) { 45 | // port number 46 | return port; 47 | } 48 | 49 | return false; 50 | } 51 | 52 | /** 53 | * Event listener for HTTP server "error" event. 54 | */ 55 | 56 | function onError(error) { 57 | if (error.syscall !== 'listen') { 58 | throw error; 59 | } 60 | 61 | var bind = typeof port === 'string' 62 | ? 'Pipe ' + port 63 | : 'Port ' + port; 64 | 65 | // handle specific listen errors with friendly messages 66 | switch (error.code) { 67 | case 'EACCES': 68 | console.error(bind + ' requires elevated privileges'); 69 | process.exit(1); 70 | break; 71 | case 'EADDRINUSE': 72 | console.error(bind + ' is already in use'); 73 | process.exit(1); 74 | break; 75 | default: 76 | throw error; 77 | } 78 | } 79 | 80 | /** 81 | * Event listener for HTTP server "listening" event. 82 | */ 83 | 84 | function onListening() { 85 | var addr = server.address(); 86 | var bind = typeof addr === 'string' 87 | ? 'pipe ' + addr 88 | : 'port ' + addr.port; 89 | debug('Listening on ' + bind); 90 | } 91 | -------------------------------------------------------------------------------- /__express/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "express", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "start": "node ./bin/www" 7 | }, 8 | "dependencies": { 9 | "cookie-parser": "~1.4.4", 10 | "debug": "~2.6.9", 11 | "express": "~4.16.1", 12 | "http-errors": "~1.6.3", 13 | "jade": "~1.11.0", 14 | "morgan": "~1.9.1" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /__express/public/stylesheets/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding: 50px; 3 | font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; 4 | } 5 | 6 | a { 7 | color: #00B7FF; 8 | } 9 | -------------------------------------------------------------------------------- /__express/routes/index.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var router = express.Router(); 3 | 4 | /* GET home page. */ 5 | router.get('/', function(req, res, next) { 6 | res.render('index', { title: 'Express' }); 7 | }); 8 | 9 | module.exports = router; 10 | -------------------------------------------------------------------------------- /__express/routes/users.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var router = express.Router(); 3 | 4 | /* GET users listing. */ 5 | router.get('/', function(req, res, next) { 6 | res.send('respond with a resource'); 7 | }); 8 | 9 | module.exports = router; 10 | -------------------------------------------------------------------------------- /__express/views/error.jade: -------------------------------------------------------------------------------- 1 | extends layout 2 | 3 | block content 4 | h1= message 5 | h2= error.status 6 | pre #{error.stack} 7 | -------------------------------------------------------------------------------- /__express/views/index.jade: -------------------------------------------------------------------------------- 1 | extends layout 2 | 3 | block content 4 | h1= title 5 | p Welcome to #{title} 6 | -------------------------------------------------------------------------------- /__express/views/layout.jade: -------------------------------------------------------------------------------- 1 | doctype html 2 | html 3 | head 4 | title= title 5 | link(rel='stylesheet', href='/stylesheets/style.css') 6 | body 7 | block content 8 | -------------------------------------------------------------------------------- /build.hxml: -------------------------------------------------------------------------------- 1 | -cmd echo "├─┬ Start Haxe build" 2 | 3 | 4 | # extremly simple hello world 5 | -cmd cd docs/00helloworld/code/ 6 | --next 7 | build.hxml 8 | -cmd echo "│ ├── 00helloworld/code" 9 | 10 | 11 | # writing 12 | -cmd cd ../../ 13 | -cmd cd 01writing/code/ 14 | --next 15 | build.hxml 16 | -cmd echo "│ ├── 01writing/code" 17 | 18 | # reading 19 | -cmd cd ../../ 20 | -cmd cd 02reading/code/ 21 | --next 22 | build.hxml 23 | -cmd echo "│ ├── 02reading/code" 24 | 25 | # lowdb 26 | -cmd cd ../../ 27 | -cmd cd 03lowdb/code/ 28 | --next 29 | build.hxml 30 | -cmd echo "│ ├── 03lowdb/code" 31 | 32 | # haxelow 33 | -cmd cd ../../ 34 | -cmd cd 04haxelow/code/ 35 | --next 36 | build.hxml 37 | -cmd echo "│ ├── 04haxelow/code" 38 | 39 | # website 40 | -cmd cd ../../ 41 | -cmd cd 05website/code/ 42 | --next 43 | # build.hxml 44 | -cmd echo "│ ├── 05website/code" 45 | 46 | # nedb 47 | -cmd cd ../../ 48 | -cmd cd 06nedb/code/ 49 | --next 50 | build.hxml 51 | -cmd echo "│ ├── 06nedb/code" 52 | 53 | # restapi 54 | -cmd cd ../../ 55 | -cmd cd 07restapi/code/ 56 | --next 57 | # build.hxml 58 | -cmd echo "│ ├── 07restapi/code" 59 | 60 | # slack 61 | -cmd cd ../../ 62 | -cmd cd 09slackbot/code/ 63 | --next 64 | # build.hxml 65 | -cmd echo "│ ├── 09slackbot/code" 66 | 67 | # scraping 68 | -cmd cd ../../ 69 | -cmd cd 10scraping/code/ 70 | --next 71 | # build.hxml 72 | -cmd echo "│ ├── 10scraping/code" 73 | 74 | # automation 75 | -cmd cd ../../ 76 | -cmd cd 11automation/code/ 77 | --next 78 | build.hxml 79 | -cmd echo "│ ├── 11automation/code" 80 | 81 | # socket 82 | -cmd cd ../../ 83 | -cmd cd 12socket/code/ 84 | --next 85 | # build.hxml 86 | -cmd echo "│ ├── 12socket/code" 87 | 88 | # sequelize 89 | -cmd cd ../../ 90 | -cmd cd 13sequelize/code/ 91 | --next 92 | # build.hxml 93 | -cmd echo "│ ├── 13sequelize/code" 94 | 95 | 96 | 97 | 98 | 99 | -cmd echo "└── Finished Haxe build" -------------------------------------------------------------------------------- /build_interp.hxml: -------------------------------------------------------------------------------- 1 | --interp -------------------------------------------------------------------------------- /docs/.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthijsKamstra/haxenode/6930b222e50c101c9639ac26b72996c69f343e0b/docs/.nojekyll -------------------------------------------------------------------------------- /docs/00helloworld/about.md: -------------------------------------------------------------------------------- 1 | # About hello http 2 | 3 | I'd guess that while it's not the use case for node.js, most people are using it as a web application platform. The next example will be a simple HTTP server that responds to every request with the plain text message "Hello World" 4 | 5 | _Source: _ 6 | 7 | # About hello world 8 | 9 | Hello world is the first thing you will write in a new language. 10 | 11 | > A "Hello, World!" program is a computer program that outputs "Hello, World!" (or some variant thereof) on a display device. Because it is typically one of the simplest programs possible in most programming languages, it is by tradition often used to illustrate to beginners the most basic syntax of a programming language. It is also used to verify that a language or system is operating correctly. 12 | 13 | Source [wikipedia](https://en.wikipedia.org/wiki/%22Hello,_World!%22_program) 14 | 15 | If you did the [Haxe basics](../haxe/hello-world.md) you already did a "Hello World". 16 | This one is a little more structured and more commented! 17 | 18 | Check the [code folder](https://github.com/MatthijsKamstra/haxejs/tree/master/00helloworld/code) for more comments. 19 | 20 | --- 21 | 22 | _Don't feel stupid, it's a thing ()_ 23 | 24 | --- 25 | -------------------------------------------------------------------------------- /docs/00helloworld/code/bin/example.js: -------------------------------------------------------------------------------- 1 | (function ($global) { "use strict"; 2 | class Main { 3 | constructor() { 4 | console.log("src/Main.hx:13:","Node.js Hello World Example"); 5 | js_node_Http.createServer(function(request,response) { 6 | response.writeHead(200,{ "Content-Type" : "text/plain"}); 7 | response.end("Hello World\n"); 8 | }).listen(8080); 9 | console.log("src/Main.hx:20:","Server started: "); 10 | console.log("src/Main.hx:21:","open http://localhost:8080"); 11 | console.log("src/Main.hx:22:","Close Node with CTRL + C"); 12 | } 13 | static main() { 14 | let main = new Main(); 15 | } 16 | } 17 | class haxe_iterators_ArrayIterator { 18 | constructor(array) { 19 | this.current = 0; 20 | this.array = array; 21 | } 22 | hasNext() { 23 | return this.current < this.array.length; 24 | } 25 | next() { 26 | return this.array[this.current++]; 27 | } 28 | } 29 | var js_node_Http = require("http"); 30 | { 31 | } 32 | Main.main(); 33 | })({}); 34 | -------------------------------------------------------------------------------- /docs/00helloworld/code/build.hxml: -------------------------------------------------------------------------------- 1 | # -lib js-kit 2 | --library hxnodejs 3 | --class-path src 4 | --main Main 5 | --js bin/example.js 6 | --dce full 7 | -D js-es=6 8 | 9 | --next 10 | 11 | # Use terminal command to start Node.js! 12 | --cmd echo "use: 'node bin/example.js' to check script " 13 | --cmd cd bin 14 | --cmd node example.js 15 | --cmd echo exit -------------------------------------------------------------------------------- /docs/00helloworld/code/javascript.hxml: -------------------------------------------------------------------------------- 1 | # libs used in project 2 | # -lib js-kit 3 | -lib hxnodejs 4 | 5 | # integrate files to classpath 6 | -cp src 7 | 8 | # this class wil be used as entry point for your app. 9 | -main Main 10 | 11 | # JavaScript target 12 | -js bin/example.js 13 | 14 | # You can use -D source-map-content (requires Haxe 3.1+) to have the .hx 15 | # files directly embedded into the map file, this way you only have to 16 | # upload it, and it will be always in sync with the compiled .js even if 17 | # you modify your .hx files. 18 | # -D source-map-content 19 | 20 | # Generate source map and add debug information 21 | # -debug 22 | 23 | # dead code elimination : remove unused code 24 | # "-dce no" : do not remove unused code 25 | # "-dce std" : remove unused code in the std lib (default) 26 | # "-dce full" : remove all unused code 27 | -dce full 28 | 29 | # This is very cool, but not necessary for this project, you can create a package.json with the correct depencicies (https://github.com/clemos/haxe-js-kit# exporting-your-project-dependencies) 30 | # --macro npm.Package.export("package.json") 31 | 32 | # Use terminal command to start Node.js! 33 | -cmd node bin/example.js -------------------------------------------------------------------------------- /docs/00helloworld/code/src/Main.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | import js.Node; 4 | import js.node.Http; 5 | import js.node.http.ServerResponse; 6 | import js.node.http.IncomingMessage; 7 | 8 | /** 9 | * @author Matthijs Kamstra aka [mck] 10 | */ 11 | class Main { 12 | function new() { 13 | trace("Node.js Hello World Example"); 14 | 15 | Http.createServer(function(request:IncomingMessage, response:ServerResponse):Void { 16 | response.writeHead(200, {'Content-Type': 'text/plain'}); 17 | response.end('Hello World\n'); 18 | }).listen(8080); 19 | 20 | trace('Server started: '); 21 | trace('open http://localhost:8080'); 22 | trace('Close Node with CTRL + C'); 23 | } 24 | 25 | static public function main() { 26 | var main = new Main(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /docs/00helloworld/example.md: -------------------------------------------------------------------------------- 1 | # Example 2 | 3 | This is the hello world in node.js. An example you can find everywhere. 4 | 5 | ## How to start 6 | 7 | Create a folder named **foobar** (please use a better name; any name will do) and create folders **bin** and **src**. 8 | See example below: 9 | 10 | ``` 11 | + foobar 12 | + bin 13 | + src 14 | - Main.hx 15 | - build.hxml 16 | ``` 17 | 18 | ## Install 19 | 20 | check out [the installation](installation.md). 21 | 22 | ## The Main.hx 23 | 24 | Open your favorite editor, copy/paste the code and save it in the `src` folder. 25 | 26 | ```haxe 27 | package; 28 | 29 | import js.Node; 30 | import js.node.Http; 31 | import js.node.http.ServerResponse; 32 | import js.node.http.IncomingMessage; 33 | 34 | /** 35 | * @author Matthijs Kamstra aka [mck] 36 | */ 37 | class Main { 38 | function new() { 39 | trace("Node.js Hello World Example"); 40 | 41 | Http.createServer(function(request:IncomingMessage, response:ServerResponse):Void { 42 | response.writeHead(200, {'Content-Type': 'text/plain'}); 43 | response.end('Hello World\n'); 44 | }).listen(8080); 45 | 46 | trace('Server started: '); 47 | trace('open http://localhost:8080'); 48 | trace('Close Node with CTRL + C'); 49 | } 50 | 51 | static public function main() { 52 | var main = new Main(); 53 | } 54 | } 55 | 56 | 57 | ``` 58 | 59 | ## The Haxe build file, javascript.hxml 60 | 61 | Copy and past the following lines in a document named `javascript.hxml` 62 | This is the short version, you want to chech out the full version open this [file](/code/javascript.hxml); 63 | 64 | ``` 65 | # // javascript.hxml 66 | -lib hxnodejs 67 | -cp src 68 | -main Main 69 | -js bin/example.js 70 | -cmd node bin/example.js 71 | ``` 72 | 73 | ## Build js with Haxe and start Node 74 | 75 | To finish and see what we have, build the file and see the result 76 | 77 | 1. Open your terminal 78 | 2. `cd ` to the correct folder where you have saved the `javascript.hxml` 79 | 3. type `haxe javascript.hxml` 80 | 4. press enter 81 | -------------------------------------------------------------------------------- /docs/00helloworld/installation.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | 3 | Read the how to install **Node.js** and **Haxe** [here](../haxenode/download.md). 4 | Once you have installed **Haxe** you will automatically installed `haxelib`. 5 | The same goes for **Node.js**, you will have automatically installed `NPM`. 6 | 7 | ## Install Node.js externs for Haxe 8 | 9 | Install the [official Haxe node.js externs](https://github.com/HaxeFoundation/hxnodejs) lib via [haxelib](http://lib.haxe.org/p/hxnodejs/). 10 | Haxelib is automatically installed when installing Haxe and you can see it as a sort of NPM. 11 | 12 | ```bash 13 | haxelib install hxnodejs 14 | ``` 15 | -------------------------------------------------------------------------------- /docs/01writing/about.md: -------------------------------------------------------------------------------- 1 | # About 2 | 3 | > Writing to a file is another of the basic programming tasks that one needs to know about. This task is simple in Node.js. We can use the handy `writeFile` method inside the standard library's `fs` module, which can save all sorts of time and trouble. 4 | 5 | _Source: [how-to-write-files-in-nodejs](https://docs.nodejitsu.com/articles/file-system/how-to-write-files-in-nodejs)_ 6 | 7 | > Asynchronously writes data to a file, replacing the file if it already exists. Data can be a string or a buffer. 8 | > 9 | > The encoding option is ignored if data is a buffer. It defaults to `utf8`. 10 | 11 | Read more about it in the node.js api: 12 | [https://nodejs.org/api/fs.html]() 13 | -------------------------------------------------------------------------------- /docs/01writing/code/bin/hello.txt: -------------------------------------------------------------------------------- 1 | Hello World! 2 | Written on: 2020-10-22 12:45:06 -------------------------------------------------------------------------------- /docs/01writing/code/build.hxml: -------------------------------------------------------------------------------- 1 | --library hxnodejs 2 | --class-path src 3 | --main Main 4 | --js bin/example.js 5 | --dce full 6 | -D js-es=6 7 | 8 | --next 9 | 10 | # Use terminal command to start Node.js! 11 | --cmd echo "use: 'node bin/example.js' to check script " 12 | --cmd cd bin 13 | --cmd node example.js 14 | --cmd echo exit -------------------------------------------------------------------------------- /docs/01writing/code/javascript.hxml: -------------------------------------------------------------------------------- 1 | # libs used in project 2 | # -lib js-kit 3 | -lib hxnodejs 4 | 5 | # integrate files to classpath 6 | -cp src 7 | 8 | # this class wil be used as entry point for your app. 9 | -main Main 10 | 11 | # JavaScript target 12 | -js bin/example.js 13 | 14 | # You can use -D source-map-content (requires Haxe 3.1+) to have the .hx 15 | # files directly embedded into the map file, this way you only have to 16 | # upload it, and it will be always in sync with the compiled .js even if 17 | # you modify your .hx files. 18 | # -D source-map-content 19 | 20 | # Generate source map and add debug information 21 | # -debug 22 | 23 | # dead code elimination : remove unused code 24 | # "-dce no" : do not remove unused code 25 | # "-dce std" : remove unused code in the std lib (default) 26 | # "-dce full" : remove all unused code 27 | -dce full 28 | 29 | # # This is very cool, but not necessary for this project, you can create a package.json with the correct depencicies (https://github.com/clemos/haxe-js-kit# exporting-your-project-dependencies) 30 | # --macro npm.Package.export("package.json") 31 | 32 | # # Use terminal command to start Node.js! 33 | # -cmd cd bin 34 | # -cmd node example.js -------------------------------------------------------------------------------- /docs/01writing/code/src/Main.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | import js.Node; 4 | import js.node.Fs; 5 | 6 | /** 7 | * @author Matthijs Kamstra aka [mck] 8 | */ 9 | class Main { 10 | function new() { 11 | trace("Node.js writing Example"); 12 | 13 | var str:String = 'Hello World!\nWritten on: ' + Date.now().toString(); 14 | // this code example is closest to the pure node.js example 15 | Fs.writeFile('hello.txt', str, {}, function(err) { 16 | if (err != null) 17 | trace("err: " + err); 18 | else 19 | trace('Hello > hello.txt'); 20 | }); 21 | } 22 | 23 | static public function main() { 24 | var main = new Main(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /docs/01writing/example.md: -------------------------------------------------------------------------------- 1 | # Example 2 | 3 | Simply write to a file. 4 | Example is from [nodejitsu.com/](https://docs.nodejitsu.com/articles/file-system/how-to-write-files-in-nodejs) 5 | 6 | ## How to start 7 | 8 | Create a folder named **foobar** (please use a better name; any name will do) and create folders **bin** and **src**. 9 | See example below: 10 | 11 | ``` 12 | + foobar 13 | + bin 14 | + src 15 | - Main.hx 16 | - javascript.hxml 17 | ``` 18 | 19 | ## Install 20 | 21 | check out [the installation](installation.md). 22 | 23 | ## Pure node example 24 | 25 | ```js 26 | fs = require("fs"); 27 | fs.writeFile("helloworld.txt", "Hello World!", function (err) { 28 | if (err) return console.log(err); 29 | console.log("Hello World > helloworld.txt"); 30 | }); 31 | ``` 32 | 33 | ## The Main.hx 34 | 35 | Open your favorite editor, copy/paste the code and save it in the `src` folder. 36 | 37 | _With the current externs it's not possible to recreate example above, but we can something simular_ 38 | 39 | ```haxe 40 | package ; 41 | 42 | import js.Node; 43 | import js.node.Fs; 44 | 45 | /** 46 | * @author Matthijs Kamstra aka [mck] 47 | */ 48 | class Main 49 | { 50 | function new() 51 | { 52 | trace("Node.js writing Example"); 53 | 54 | var str : String = 'Hello World!\nWritten on: ' + Date.now().toString(); 55 | // this code example is closest to the pure node.js example 56 | Fs.writeFile('hello.txt', str, {}, function (err){ 57 | if (err != null) 58 | trace( "err: " + err ); 59 | else 60 | trace('Hello > hello.txt'); 61 | }); 62 | } 63 | static public function main() 64 | { 65 | var main = new Main(); 66 | } 67 | } 68 | 69 | ``` 70 | 71 | ## The Haxe build file, javascript.hxml 72 | 73 | Copy and past the following lines in a document named `javascript.hxml` 74 | This is the short version, you want to chech out the full version open this [file](/code/javascript.hxml); 75 | 76 | ``` 77 | # // javascript.hxml 78 | -lib js-kit 79 | -lib hxnodejs 80 | -cp src 81 | -main Main 82 | -js bin/example.js 83 | -cmd node bin/example.js 84 | ``` 85 | 86 | ## Build js with Haxe and start Node 87 | 88 | To finish and see what we have, build the file and see the result 89 | 90 | 1. Open your terminal 91 | 2. `cd ` to the correct folder where you have saved the `javascript.hxml` 92 | 3. type `haxe javascript.hxml` 93 | 4. press enter 94 | -------------------------------------------------------------------------------- /docs/01writing/installation.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | 3 | Read the how to install **Node.js** and **Haxe** [here](../haxenode/download.md). 4 | Once you have installed **Haxe** you will automatically installed `haxelib`. 5 | The same goes for **Node.js**, you will have automatically installed `NPM`. 6 | 7 | ## Install Node.js externs for Haxe 8 | 9 | Install the [official Haxe node.js externs](https://github.com/HaxeFoundation/hxnodejs) lib via [haxelib](http://lib.haxe.org/p/hxnodejs/). 10 | Haxelib is automatically installed when installing Haxe and you can see it as a sort of NPM. 11 | 12 | ```bash 13 | haxelib install hxnodejs 14 | ``` 15 | -------------------------------------------------------------------------------- /docs/02reading/about.md: -------------------------------------------------------------------------------- 1 | # About 2 | 3 | > Reading the contents of a file into memory is a very common programming task. And as with many other things, the Node.js core API provides methods to make this trivial. There are a variety of file system methods, all contained in the `fs` module. The easiest way to read the entire contents of a file is with `fs.readFile`. 4 | 5 | _Source: [nodejitsu.com](https://docs.nodejitsu.com/articles/file-system/how-to-read-files-in-nodejs)_ 6 | 7 | > Asynchronously reads the entire contents of a file. 8 | 9 | Read more about it in the node.js api: 10 | [https://nodejs.org/api/fs.html]() 11 | -------------------------------------------------------------------------------- /docs/02reading/code/bin/hello.txt: -------------------------------------------------------------------------------- 1 | 2020-10-22 12:46:46 -------------------------------------------------------------------------------- /docs/02reading/code/build.hxml: -------------------------------------------------------------------------------- 1 | --library hxnodejs 2 | --class-path src 3 | --main Main 4 | --js bin/example.js 5 | --dce full 6 | -D js-es=6 7 | 8 | --next 9 | 10 | # Use terminal command to start Node.js! 11 | --cmd echo "use: 'node bin/example.js' to check script " 12 | --cmd cd bin 13 | --cmd node example.js 14 | --cmd echo exit -------------------------------------------------------------------------------- /docs/02reading/code/javascript.hxml: -------------------------------------------------------------------------------- 1 | # libs used in project 2 | -lib js-kit 3 | -lib hxnodejs 4 | 5 | # integrate files to classpath 6 | -cp src 7 | 8 | # this class wil be used as entry point for your app. 9 | -main Main 10 | 11 | # JavaScript target 12 | -js bin/example.js 13 | 14 | # You can use -D source-map-content (requires Haxe 3.1+) to have the .hx 15 | # files directly embedded into the map file, this way you only have to 16 | # upload it, and it will be always in sync with the compiled .js even if 17 | # you modify your .hx files. 18 | # -D source-map-content 19 | 20 | # Generate source map and add debug information 21 | # -debug 22 | 23 | # dead code elimination : remove unused code 24 | # "-dce no" : do not remove unused code 25 | # "-dce std" : remove unused code in the std lib (default) 26 | # "-dce full" : remove all unused code 27 | -dce full 28 | 29 | # This is very cool, but not necessary for this project, you can create a package.json with the correct depencicies (https://github.com/clemos/haxe-js-kit# exporting-your-project-dependencies) 30 | --macro npm.Package.export("package.json") 31 | 32 | # Use terminal command to start Node.js! 33 | -cmd cd bin 34 | -cmd node example.js -------------------------------------------------------------------------------- /docs/02reading/code/src/Main.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | import js.Node; 4 | import js.node.Fs; 5 | 6 | /** 7 | * @author Matthijs Kamstra aka [mck] 8 | */ 9 | class Main { 10 | function new() { 11 | trace("Node.js reading and writing Example"); 12 | 13 | var str = Date.now().toString(); 14 | 15 | // write the file 16 | Fs.writeFile('hello.txt', str, {}, function(err) { 17 | if (err != null) 18 | trace("err: " + err); 19 | else 20 | trace('Hello > hello.txt'); 21 | }); 22 | 23 | // read the file 24 | Fs.readFile('hello.txt', function(err, data) { 25 | if (err != null) 26 | trace("err: " + err); 27 | else 28 | trace("data: " + data); 29 | }); 30 | } 31 | 32 | static public function main() { 33 | var main = new Main(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /docs/02reading/example.md: -------------------------------------------------------------------------------- 1 | # Example 2 | 3 | Simply write to a file. 4 | Example is from [nodejitsu.com/](https://docs.nodejitsu.com/articles/file-system/how-to-read-files-in-nodejs) 5 | 6 | ## How to start 7 | 8 | Create a folder named **foobar** (please use a better name; any name will do) and create folders **bin** and **src**. 9 | See example below: 10 | 11 | ``` 12 | + foobar 13 | + bin 14 | + src 15 | - Main.hx 16 | - javascript.hxml 17 | ``` 18 | 19 | ## Install 20 | 21 | check out [the installation](installation.md). 22 | 23 | ## Pure node example 24 | 25 | ```js 26 | fs = require("fs"); 27 | fs.readFile("/etc/hosts", "utf8", function (err, data) { 28 | if (err) { 29 | return console.log(err); 30 | } 31 | console.log(data); 32 | }); 33 | ``` 34 | 35 | ## The Main.hx 36 | 37 | Open your favorite editor, copy/paste the code and save it in the `src` folder. 38 | 39 | ```haxe 40 | package ; 41 | 42 | import js.Node; 43 | import js.node.Fs; 44 | 45 | /** 46 | * @author Matthijs Kamstra aka [mck] 47 | */ 48 | class Main { 49 | function new() { 50 | Fs.readFile('/etc/hosts', {encoding:'utf8'}, function (err,data){ 51 | if(err != null) 52 | trace( "err: " + err ); 53 | else 54 | trace( "data: " + data ); 55 | }); 56 | } 57 | 58 | static public function main(){ 59 | var main = new Main(); 60 | } 61 | } 62 | ``` 63 | 64 | ## The Haxe build file, javascript.hxml 65 | 66 | Copy and past the following lines in a document named `javascript.hxml` 67 | This is the short version, you want to chech out the full version open this [file](/code/javascript.hxml); 68 | 69 | ``` 70 | # // javascript.hxml 71 | -lib js-kit 72 | -lib hxnodejs 73 | -cp src 74 | -main Main 75 | -js bin/example.js 76 | -cmd node bin/example.js 77 | ``` 78 | 79 | ## Build js with Haxe and start Node 80 | 81 | To finish and see what we have, build the file and see the result 82 | 83 | 1. Open your terminal 84 | 2. `cd ` to the correct folder where you have saved the `javascript.hxml` 85 | 3. type `haxe javascript.hxml` 86 | 4. press enter 87 | -------------------------------------------------------------------------------- /docs/02reading/installation.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | 3 | Read the how to install **Node.js** and **Haxe** [here](../haxenode/download.md). 4 | Once you have installed **Haxe** you will automatically installed `haxelib`. 5 | The same goes for **Node.js**, you will have automatically installed `NPM`. 6 | 7 | ## Install Node.js externs for Haxe 8 | 9 | Install the [official Haxe node.js externs](https://github.com/HaxeFoundation/hxnodejs) lib via [haxelib](http://lib.haxe.org/p/hxnodejs/). 10 | Haxelib is automatically installed when installing Haxe and you can see it as a sort of NPM. 11 | 12 | ```bash 13 | haxelib install hxnodejs 14 | ``` 15 | -------------------------------------------------------------------------------- /docs/03lowdb/about.md: -------------------------------------------------------------------------------- 1 | # About 2 | 3 | There is always a need to store data, one way or another. In the example we store our data in a `.json` file. 4 | 5 | We will be using [lowdb](https://github.com/typicode/lowdb) for this 6 | 7 | >Need a quick way to get a local database? 8 | 9 | ---- 10 | 11 | Because the data is returned by Lodash, you should read more about it: [https://lodash.com/](https://lodash.com/) -------------------------------------------------------------------------------- /docs/03lowdb/code/bin/example.js: -------------------------------------------------------------------------------- 1 | (function ($global) { "use strict"; 2 | var Lowdb = require("lowdb"); 3 | class Main { 4 | constructor() { 5 | console.log("src/Main.hx:14:","Node.js Lowdb Example"); 6 | let now = new Date(); 7 | let adapter = new lowdb_adapters_FileSync("db.json"); 8 | let db = Lowdb(adapter); 9 | } 10 | static main() { 11 | let main = new Main(); 12 | } 13 | } 14 | class haxe_iterators_ArrayIterator { 15 | constructor(array) { 16 | this.current = 0; 17 | this.array = array; 18 | } 19 | hasNext() { 20 | return this.current < this.array.length; 21 | } 22 | next() { 23 | return this.array[this.current++]; 24 | } 25 | } 26 | var lowdb_adapters_FileSync = require("lowdb/adapters/FileSync"); 27 | { 28 | } 29 | Main.main(); 30 | })({}); 31 | -------------------------------------------------------------------------------- /docs/03lowdb/code/build.hxml: -------------------------------------------------------------------------------- 1 | --library hxnodejs 2 | --library lodash 3 | --library lowdb 4 | --class-path src 5 | --main Main 6 | --js bin/example.js 7 | --dce full 8 | -D js-es=6 9 | 10 | 11 | # --next 12 | 13 | # Use terminal command to start Node.js! 14 | --cmd echo "use: 'node bin/example.js' to check script " 15 | --cmd cd bin 16 | --cmd node example.js 17 | --cmd echo exit -------------------------------------------------------------------------------- /docs/03lowdb/code/dts2hx_convert.md: -------------------------------------------------------------------------------- 1 | ## tl;dr 2 | 3 | ```bash 4 | # install 5 | npm install dts2hx --save-dev 6 | # npm install lowdb --save 7 | npm install @types/lowdb --save 8 | 9 | npm install 10 | 11 | # run dts2hx 12 | npx dts2hx lowdb 13 | 14 | # install hxnodejs 15 | haxelib install hxnodejs 16 | 17 | # don't forget to add `--library lowdb` to your build 18 | ``` 19 | 20 | ## install packages 21 | 22 | ```bash 23 | npm install dts2hx --save-dev 24 | npm install lowdb --save 25 | npm install @types/lowdb --save 26 | ``` 27 | 28 | ## run dts2hx 29 | 30 | ```bash 31 | // doesn't work because the lowdb ts files are not in the repo 32 | npx dts2hx lowdb 33 | ``` 34 | 35 | works 36 | 37 | ```bash 38 | npx dts2hx @types/lowdb 39 | ``` 40 | 41 | ## add lib 42 | 43 | build.hxml 44 | 45 | ```bash 46 | --library lowdb 47 | ``` 48 | 49 | ## install hxnodejs in .haxelib folder 50 | 51 | ```bash 52 | haxelib install hxnodejs 53 | ``` 54 | -------------------------------------------------------------------------------- /docs/03lowdb/code/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "code", 3 | "lockfileVersion": 2, 4 | "requires": true, 5 | "packages": { 6 | "": { 7 | "hasInstallScript": true, 8 | "dependencies": { 9 | "@types/lowdb": "^1.0.11" 10 | }, 11 | "devDependencies": { 12 | "dts2hx": "^0.16.0" 13 | } 14 | }, 15 | "node_modules/@types/lodash": { 16 | "version": "4.14.172", 17 | "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.172.tgz", 18 | "integrity": "sha512-/BHF5HAx3em7/KkzVKm3LrsD6HZAXuXO1AJZQ3cRRBZj4oHZDviWPYu0aEplAqDFNHZPW6d3G7KN+ONcCCC7pw==" 19 | }, 20 | "node_modules/@types/lowdb": { 21 | "version": "1.0.11", 22 | "resolved": "https://registry.npmjs.org/@types/lowdb/-/lowdb-1.0.11.tgz", 23 | "integrity": "sha512-h99VMxvTuz+VsXUVCCJo4dsps4vbkXwvU71TpmxDoiBU24bJ0VBygIHgmMm+UPoQIFihmV6euRik4z8J7XDJWg==", 24 | "dependencies": { 25 | "@types/lodash": "*" 26 | } 27 | }, 28 | "node_modules/dts2hx": { 29 | "version": "0.16.0", 30 | "resolved": "https://registry.npmjs.org/dts2hx/-/dts2hx-0.16.0.tgz", 31 | "integrity": "sha512-pyfk90me0QlXRIiZaOzudN9Qyk09e7aKZttOJQ8zCeyXHKAos+/OJno9dfs8HVbU8pA7Mqvg1Nc8RuVmeirJug==", 32 | "dev": true, 33 | "dependencies": { 34 | "typescript": "3.7.4" 35 | }, 36 | "bin": { 37 | "dts2hx": "cli.js" 38 | } 39 | }, 40 | "node_modules/typescript": { 41 | "version": "3.7.4", 42 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.4.tgz", 43 | "integrity": "sha512-A25xv5XCtarLwXpcDNZzCGvW2D1S3/bACratYBx2sax8PefsFhlYmkQicKHvpYflFS8if4zne5zT5kpJ7pzuvw==", 44 | "dev": true, 45 | "bin": { 46 | "tsc": "bin/tsc", 47 | "tsserver": "bin/tsserver" 48 | }, 49 | "engines": { 50 | "node": ">=4.2.0" 51 | } 52 | } 53 | }, 54 | "dependencies": { 55 | "@types/lodash": { 56 | "version": "4.14.172", 57 | "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.172.tgz", 58 | "integrity": "sha512-/BHF5HAx3em7/KkzVKm3LrsD6HZAXuXO1AJZQ3cRRBZj4oHZDviWPYu0aEplAqDFNHZPW6d3G7KN+ONcCCC7pw==" 59 | }, 60 | "@types/lowdb": { 61 | "version": "1.0.11", 62 | "resolved": "https://registry.npmjs.org/@types/lowdb/-/lowdb-1.0.11.tgz", 63 | "integrity": "sha512-h99VMxvTuz+VsXUVCCJo4dsps4vbkXwvU71TpmxDoiBU24bJ0VBygIHgmMm+UPoQIFihmV6euRik4z8J7XDJWg==", 64 | "requires": { 65 | "@types/lodash": "*" 66 | } 67 | }, 68 | "dts2hx": { 69 | "version": "0.16.0", 70 | "resolved": "https://registry.npmjs.org/dts2hx/-/dts2hx-0.16.0.tgz", 71 | "integrity": "sha512-pyfk90me0QlXRIiZaOzudN9Qyk09e7aKZttOJQ8zCeyXHKAos+/OJno9dfs8HVbU8pA7Mqvg1Nc8RuVmeirJug==", 72 | "dev": true, 73 | "requires": { 74 | "typescript": "3.7.4" 75 | } 76 | }, 77 | "typescript": { 78 | "version": "3.7.4", 79 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.4.tgz", 80 | "integrity": "sha512-A25xv5XCtarLwXpcDNZzCGvW2D1S3/bACratYBx2sax8PefsFhlYmkQicKHvpYflFS8if4zne5zT5kpJ7pzuvw==", 81 | "dev": true 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /docs/03lowdb/code/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "_postinstall": "dts2hx --all && haxelib install hxnodejs", 4 | "postinstall": "dts2hx --all && dts2hx @types/lowdb/adapters/FileSync && haxelib install hxnodejs" 5 | }, 6 | "devDependencies": { 7 | "dts2hx": "^0.16.0" 8 | }, 9 | "dependencies": { 10 | "@types/lowdb": "^1.0.11" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /docs/03lowdb/code/src/Main.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | import lowdb.adapters.FileSync; 4 | import lodash.*; 5 | 6 | // import lowdb.*; 7 | // import lowdb.Lowdb; 8 | 9 | /** 10 | * @author Matthijs Kamstra aka [mck] 11 | */ 12 | class Main { 13 | function new() { 14 | trace("Node.js Lowdb Example"); 15 | 16 | var now = Date.now(); 17 | 18 | // var _lowdb = Lowdb.call('db.json'); 19 | // Lowdb.query(_lowdb, 'posts').push({title: 'Lowdb is awesome', date: str}); 20 | 21 | // trace(Lowdb.query(_lowdb, 'posts').find({title: 'Lowdb is awesome'})); 22 | 23 | // // _lowdb.save(); 24 | // trace("_lowdb.object: " + _lowdb.object); 25 | 26 | var adapter = new FileSync('db.json'); 27 | var db = Lowdb.call(adapter); 28 | 29 | // // Set some defaults (required if your JSON file is empty) 30 | // untyped db.defaults({ 31 | // posts: [], 32 | // user: {}, 33 | // count: 0, 34 | // updated: now 35 | // }).write(); 36 | 37 | // // Add a post 38 | // untyped db.get('posts').push({id: 1, title: 'lowdb is awesome', date: now}).write(); 39 | 40 | // // Set a user using Lodash shorthand syntax 41 | // untyped db.set('user.name', 'typicode').write(); 42 | 43 | // // Increment count 44 | // untyped db.update('count', n -> n + 1).write(); 45 | // untyped db.update('updated', now).write(); 46 | } 47 | 48 | static public function main() { 49 | var main = new Main(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /docs/03lowdb/example.md: -------------------------------------------------------------------------------- 1 | # Example 2 | 3 | Simply write to a file. 4 | Example is from [nodejitsu.com/](https://docs.nodejitsu.com/articles/file-system/how-to-read-files-in-nodejs) 5 | 6 | ## How to start 7 | 8 | Create a folder named **foobar** (please use a better name; any name will do) and create folders **bin** and **src**. 9 | See example below: 10 | 11 | ``` 12 | + foobar 13 | + bin 14 | + src 15 | - Main.hx 16 | - javascript.hxml 17 | ``` 18 | 19 | ## Install 20 | 21 | check out [the installation](installation.md). 22 | 23 | ## Node.js example 24 | 25 | ``` 26 | var low = require('lowdb') 27 | var db = low('db.json') 28 | 29 | db('posts').push({ title: 'lowdb is awesome'}) 30 | ``` 31 | 32 | ## The Main.hx 33 | 34 | It's not always possible to have the exact same calls in Haxe externs like you have in javascript/node.js. 35 | 36 | Lowdb is a good example: 37 | 38 | ``` 39 | var db = low('db.json') 40 | // translates in Haxe externs to 41 | var db = LowDb.construct('db.json'); 42 | ``` 43 | 44 | and 45 | 46 | ``` 47 | db('posts').push({ title: 'lowdb is awesome'}) 48 | // translates in Haxe externs to 49 | LowDb.query(_lowdb, 'posts').push({title:'lowdb is awesome'}); 50 | ``` 51 | 52 | and 53 | 54 | ``` 55 | db('posts').find({ title: 'lowdb is awesome' }) 56 | // translates in Haxe externs to 57 | trace (LowDb.query(_lowdb, 'posts').find({ title: 'lowdb is awesome' })); 58 | ``` 59 | 60 | Knowing that I hope the code below will make more sense. 61 | Open your favorite editor, copy/paste the code and save it in the `src` folder. 62 | 63 | ```haxe 64 | package ; 65 | 66 | import js.Node; 67 | import js.npm.LowDb; 68 | 69 | /** 70 | * @author Matthijs Kamstra aka [mck] 71 | */ 72 | class Main 73 | { 74 | function new() 75 | { 76 | trace("Node.js LowDB Example"); 77 | 78 | var _lowdb = LowDb.construct('db.json'); 79 | LowDb.query(_lowdb, 'posts').push({title:'lowdb is awesome'}); 80 | 81 | trace ("_lowdb.object: " + _lowdb.object); 82 | } 83 | 84 | static public function main() 85 | { 86 | var main = new Main(); 87 | } 88 | } 89 | 90 | ``` 91 | 92 | ## The Haxe build file, javascript.hxml 93 | 94 | Copy and past the following lines in a document named `javascript.hxml` 95 | This is the short version, you want to chech out the full version open this [file](/code/javascript.hxml); 96 | 97 | ``` 98 | # // javascript.hxml 99 | -lib js-kit 100 | -lib hxnodejs 101 | -cp src 102 | -main Main 103 | -js bin/example.js 104 | -cmd node bin/example.js 105 | ``` 106 | 107 | ## Build js with Haxe and start Node 108 | 109 | To finish and see what we have, build the file and see the result 110 | 111 | 1. Open your terminal 112 | 2. `cd ` to the correct folder where you have saved the `javascript.hxml` 113 | 3. type `haxe javascript.hxml` 114 | 4. press enter 115 | -------------------------------------------------------------------------------- /docs/03lowdb/installation.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | 3 | Read the how to install **Node.js** and **Haxe** [here](../haxenode/download.md). 4 | Once you have installed **Haxe** you will automatically installed `haxelib`. 5 | The same goes for **Node.js**, you will have automatically installed `NPM`. 6 | 7 | ## Install Node.js externs for Haxe 8 | 9 | Install the [official Haxe node.js externs](https://github.com/HaxeFoundation/hxnodejs) lib via [haxelib](http://lib.haxe.org/p/hxnodejs/). 10 | Haxelib is automatically installed when installing Haxe and you can see it as a sort of NPM. 11 | 12 | ```bash 13 | haxelib install hxnodejs 14 | ``` 15 | 16 | In this tutorial I use js-kit externs, there are more ways to get externs but the js-kit has a lot so it's more a one stop shop thing! 17 | 18 | ```bash 19 | haxelib git js-kit https://github.com/clemos/haxe-js-kit.git haxelib 20 | 21 | ``` 22 | 23 | ## Install lowdb via NPM: 24 | 25 | [Lowdb](https://github.com/typicode/lowdb) 26 | 27 | > Need a quick way to get a local database? 28 | 29 | ``` 30 | npm install lowdb --save 31 | ``` 32 | -------------------------------------------------------------------------------- /docs/03lowdb/test.md: -------------------------------------------------------------------------------- 1 | ## tl;dr 2 | 3 | ``` 4 | # install 5 | npm install dts2hx --save-dev 6 | npm install lowdb --save 7 | npm install @types/lowdb --save 8 | 9 | # run dts2hx 10 | npx dts2hx lowdb 11 | npx dts2hx @types/lowdb/adapters/FileSync 12 | 13 | # install hxnodejs 14 | haxelib install hxnodejs 15 | 16 | # don't forget to add `--library lowdb` to your build 17 | ``` 18 | 19 | ## install packages 20 | 21 | ``` 22 | npm install dts2hx --save-dev 23 | npm install lowdb --save 24 | npm install @types/lowdb --save 25 | ``` 26 | 27 | ## run dts2hx 28 | 29 | ``` 30 | // doesn't work because the lowdb ts files are not in the repo 31 | npx dts2hx lowdb 32 | ``` 33 | 34 | works 35 | 36 | ``` 37 | npx dts2hx @types/lowdb 38 | ``` 39 | 40 | ## add lib 41 | 42 | build.hxml 43 | 44 | ``` 45 | --library lowdb 46 | ``` 47 | 48 | ## install hxnodejs in .haxelib folder 49 | 50 | ```bash 51 | haxelib install hxnodejs 52 | ``` 53 | -------------------------------------------------------------------------------- /docs/04haxelow/about.md: -------------------------------------------------------------------------------- 1 | # About 2 | 3 | There is always a need to store data, one way or another. In the example we store our data in a `.json` file. 4 | 5 | In the previous example we used [lowdb](https://github.com/typicode/lowdb) for this. 6 | 7 | But there is a better way to do something similar in Haxe. 8 | 9 | In this example we will use [haxelow](https://github.com/ciscoheat/haxelow) 10 | 11 | ```bash 12 | haxelib install haxelow 13 | ``` 14 | -------------------------------------------------------------------------------- /docs/04haxelow/code/bin/db.json: -------------------------------------------------------------------------------- 1 | { 2 | "Person" : [ 3 | { 4 | "_hxcls" : "Person" 5 | ,"name" : "Test-1631357315503" 6 | ,"age" : 77 7 | } 8 | ,{ 9 | "_hxcls" : "Person" 10 | ,"name" : "Test-1631357404296" 11 | ,"age" : 13 12 | } 13 | ,{ 14 | "_hxcls" : "Person" 15 | ,"name" : "Test-1631357416574" 16 | ,"age" : 4 17 | } 18 | ,{ 19 | "_hxcls" : "Person" 20 | ,"name" : "Test-1631357485400" 21 | ,"age" : 30 22 | } 23 | ,{ 24 | "_hxcls" : "Person" 25 | ,"name" : "Test-1631357498319" 26 | ,"age" : 97 27 | } 28 | ,{ 29 | "_hxcls" : "Person" 30 | ,"name" : "Test-1631357509245" 31 | ,"age" : 20 32 | } 33 | ,{ 34 | "_hxcls" : "Person" 35 | ,"name" : "Test-1631357524366" 36 | ,"age" : 85 37 | } 38 | ,{ 39 | "_hxcls" : "Person" 40 | ,"name" : "Test-1631357551519" 41 | ,"age" : 83 42 | } 43 | ,{ 44 | "_hxcls" : "Person" 45 | ,"name" : "Test-1631357580309" 46 | ,"age" : 91 47 | } 48 | ,{ 49 | "_hxcls" : "Person" 50 | ,"name" : "Test-1631357582151" 51 | ,"age" : 88 52 | } 53 | ,{ 54 | "_hxcls" : "Person" 55 | ,"name" : "Test" 56 | ,"age" : 50 57 | } 58 | ,{ 59 | "_hxcls" : "Person" 60 | ,"name" : "Test-1631357767841" 61 | ,"age" : 85 62 | } 63 | ] 64 | } -------------------------------------------------------------------------------- /docs/04haxelow/code/build.hxml: -------------------------------------------------------------------------------- 1 | --library haxelow 2 | --library hxnodejs 3 | --class-path src 4 | --main Main 5 | --js bin/example.js 6 | --dce full 7 | -D js-es=6 8 | # only because we can... 9 | -D no-deprecation-warnings 10 | 11 | --next 12 | 13 | # Use terminal command to start Node.js! 14 | --cmd echo "use: 'node bin/example.js' to check script " 15 | --cmd cd bin 16 | --cmd node example.js 17 | --cmd echo exit -------------------------------------------------------------------------------- /docs/04haxelow/code/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "steno": "^0.5.0" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /docs/04haxelow/code/src/Main.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | import js.Node; 4 | 5 | /** 6 | * @author Matthijs Kamstra aka [mck] 7 | */ 8 | class Main { 9 | function new() { 10 | trace("Node.js Haxelow Example"); 11 | 12 | // Create the database 13 | var db = new HaxeLow('db.json'); 14 | 15 | // Get a collection of a class 16 | var persons = db.col(Person); 17 | 18 | // persons is now an Array 19 | // that can be manipulated as you like 20 | persons.push(new Person('Test-${Date.now().getTime()}', Math.round(Math.random() * 100))); 21 | 22 | trace(db.col(Person).length); 23 | 24 | // Save all collections to disk. 25 | 26 | // This is the only way to save, no automatic saving 27 | // takes place. 28 | db.save(); 29 | 30 | trace("open /bin/db.json"); 31 | } 32 | 33 | static public function main() { 34 | var main = new Main(); 35 | } 36 | } 37 | 38 | class Person { 39 | public function new(name, age) { 40 | this.name = name; 41 | this.age = age; 42 | } 43 | 44 | public var name:String; 45 | public var age:Int; 46 | } 47 | -------------------------------------------------------------------------------- /docs/04haxelow/example.md: -------------------------------------------------------------------------------- 1 | # Example 2 | 3 | Write to a simple json database... 4 | Done in Haxe 5 | 6 | ## How to start 7 | 8 | Create a folder named **foobar** (please use a better name; any name will do) and create folders **bin** and **src**. 9 | See example below: 10 | 11 | ``` 12 | + foobar 13 | + bin 14 | + src 15 | - Main.hx 16 | - javascript.hxml 17 | ``` 18 | 19 | ## Install 20 | 21 | Check out [the installation](installation.md). 22 | 23 | ## The Main.hx 24 | 25 | Open your favorite editor, copy/paste the code and save it in the `src` folder. 26 | 27 | ```haxe 28 | package ; 29 | 30 | import js.Node; 31 | 32 | /** 33 | * @author Matthijs Kamstra aka [mck] 34 | */ 35 | class Main 36 | { 37 | function new() 38 | { 39 | trace("Node.js Haxelow Example"); 40 | 41 | // Create the database 42 | var db = new HaxeLow('db.json'); 43 | 44 | // Get a collection of a class 45 | var persons = db.col(Person); 46 | 47 | // persons is now an Array 48 | // that can be manipulated as you like 49 | persons.push(new Person("Test", 50)); 50 | 51 | // Save all collections to disk. 52 | // This is the only way to save, no automatic saving 53 | // takes place. 54 | db.save(); 55 | } 56 | 57 | static public function main() 58 | { 59 | var main = new Main(); 60 | } 61 | } 62 | 63 | class Person { 64 | public function new(name, age) { 65 | this.name = name; 66 | this.age = age; 67 | } 68 | 69 | public var name : String; 70 | public var age : Int; 71 | } 72 | ``` 73 | 74 | ## The Haxe build file, javascript.hxml 75 | 76 | Copy and past the following lines in a document named `javascript.hxml` 77 | This is the short version, you want to chech out the full version open this [file](/code/javascript.hxml); 78 | 79 | ``` 80 | # // javascript.hxml 81 | -lib js-kit 82 | -lib hxnodejs 83 | -lib haxelow 84 | -cp src 85 | -main Main 86 | -js bin/example.js 87 | -cmd node bin/example.js 88 | ``` 89 | 90 | ## Build js with Haxe and start Node 91 | 92 | To finish and see what we have, build the file and see the result 93 | 94 | 1. Open your terminal 95 | 2. `cd ` to the correct folder where you have saved the `javascript.hxml` 96 | 3. type `haxe javascript.hxml` 97 | 4. press enter 98 | -------------------------------------------------------------------------------- /docs/04haxelow/installation.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | 3 | Read the how to install **Node.js** and **Haxe** [here](../haxenode/download.md). 4 | Once you have installed **Haxe** you will automatically installed `haxelib`. 5 | The same goes for **Node.js**, you will have automatically installed `NPM`. 6 | 7 | ## Install Node.js externs for Haxe 8 | 9 | Install the [official Haxe node.js externs](https://github.com/HaxeFoundation/hxnodejs) lib via [haxelib](http://lib.haxe.org/p/hxnodejs/). 10 | Haxelib is automaticly installed when installing Haxe and you can see it as a sort of NPM. 11 | 12 | ```bash 13 | haxelib install hxnodejs 14 | ``` 15 | 16 | ## AND install haxelow via haxelib 17 | 18 | Use haxelib to install **haxelow** : 19 | 20 | ```bash 21 | haxelib install haxelow 22 | ``` 23 | 24 | ## Install Steno via NPM: 25 | 26 | haxelow uses steno to write to disk, so you need to install it using NPM. 27 | 28 | ``` 29 | npm install --save steno 30 | ``` 31 | -------------------------------------------------------------------------------- /docs/05website/about.md: -------------------------------------------------------------------------------- 1 | # About Node website 2 | 3 | The cool part about _Node.js_ that it's JavaScript for back-end! 4 | You write JavaScript but for the back-end! 5 | Did I mention back-end? 6 | 7 | But the important thing to know is that everything in _Node.js_ is clean/minimal. 8 | You could rewrite every call, or use a framework that does all the heavy lifting. 9 | 10 | If you started this tutorials/examples from the beginning you already seen [http in action](../00helloworld/about.md). 11 | Which tells the http classes that express (also) uses, it's nice to know how things work. 12 | But if you want to create a website I strongly suggest you use `ExpressJS`!!! 13 | 14 | In this tutorial we will be using [Express](http://expressjs.com): 15 | 16 | > ### Web Applications 17 | > 18 | > Express is a minimal and flexible Node.js web application framework. It provides a robust set of features for web and mobile applications. 19 | > 20 | 21 | And build an `index.html`, `remote.html` and `404`! 22 | 23 | This example covers 3 different examples 24 | 25 | - [Basic](exampleBasic.md) 26 | - [Intermediate](exampleIntermediate.md) 27 | - [Advanced](exampleAdvanced.md) 28 | 29 | Because I don't want to spend time on styling the `.html`/`.jade` files, I use [Bootstrap](http://getbootstrap.com/getting-started/#examples) 30 | 31 | --- 32 | -------------------------------------------------------------------------------- /docs/05website/code/_package.json: -------------------------------------------------------------------------------- 1 | { 2 | "license": "MIT", 3 | "description": "Create a website with express", 4 | "author": "Matthijs Kamstra aka [mck]", 5 | "start": "node index.js", 6 | "private": true, 7 | "dependencies": { 8 | "pug": "*", 9 | "morgan": "*", 10 | "body-parser": "^1.10.1", 11 | "serve-favicon": "*", 12 | "express": "~4.17" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /docs/05website/code/bin/example.js: -------------------------------------------------------------------------------- 1 | // Generated by Haxe 4.1.4 2 | (function ($global) { "use strict"; 3 | var CookieParser = require("cookie-parser"); 4 | var Express = require("express"); 5 | class Main04 { 6 | constructor() { 7 | let app = Express(); 8 | let port = 3000; 9 | console.log("src/Main04.hx:20:","Express website (04): open browser at http://localhost:" + port); 10 | console.log("src/Main04.hx:21:","Stop node.js : CTRL + c"); 11 | app.set("views",js_node_Path.join(__dirname,"public","views")); 12 | app.set("view engine","pug"); 13 | app.use(Morgan("dev")); 14 | app.use(Express.json()); 15 | app.use(Express.urlencoded({ extended : false})); 16 | let tmp = CookieParser(); 17 | app.use(tmp); 18 | let tmp1 = Express.static; 19 | let tmp2 = js_node_Path.join(__dirname,"public"); 20 | app.use(tmp1(tmp2)); 21 | let router = express_Router(); 22 | routes_Index.init(router); 23 | let server = app.listen(port,function() { 24 | console.log("src/Main04.hx:77:","Example app listening at http://localhost:" + port); 25 | }); 26 | } 27 | static main() { 28 | let main = new Main04(); 29 | } 30 | } 31 | var Morgan = require("morgan"); 32 | var express_Router = require("express").Router; 33 | class haxe_iterators_ArrayIterator { 34 | constructor(array) { 35 | this.current = 0; 36 | this.array = array; 37 | } 38 | hasNext() { 39 | return this.current < this.array.length; 40 | } 41 | next() { 42 | return this.array[this.current++]; 43 | } 44 | } 45 | var js_node_Path = require("path"); 46 | class routes_Index { 47 | static init(app) { 48 | app.get("/",function(req,res,next) { 49 | res.render("index",{ title : "Express"}); 50 | return null; 51 | }); 52 | } 53 | } 54 | Main04.main(); 55 | })({}); 56 | -------------------------------------------------------------------------------- /docs/05website/code/bin/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthijsKamstra/haxenode/6930b222e50c101c9639ac26b72996c69f343e0b/docs/05website/code/bin/public/favicon.ico -------------------------------------------------------------------------------- /docs/05website/code/bin/public/index_advanced.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Haxe Node - Website - Index 9 | 10 | 11 | 12 | 13 | 27 | 28 | 29 | 30 | 31 |
32 | 33 |
34 |
35 | 36 | 37 |
38 | 39 |
40 | 41 |
42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /docs/05website/code/bin/public/index_intermediate.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Haxe Node - Website - Index 9 | 10 | 11 | 12 |
13 | index 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /docs/05website/code/bin/public/remote_intermediate.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Haxe Node - Website - Remote 9 | 10 | 11 | 12 |
13 | remote 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /docs/05website/code/bin/public/views/_index.pug: -------------------------------------------------------------------------------- 1 | doctype html 2 | html(lang='en') 3 | head 4 | meta(charset='utf-8') 5 | meta(http-equiv='X-UA-Compatible', content='IE=edge') 6 | meta(name='viewport', content='width=device-width, initial-scale=1') 7 | // The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags 8 | meta(name='description', content='') 9 | meta(name='author', content='') 10 | link(rel='icon', href='favicon.ico') 11 | title #{title} :: Starter Template for Bootstrap 12 | // Bootstrap core CSS 13 | link(href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css', rel='stylesheet') 14 | style(type='text/css'). 15 | body { 16 | padding-top: 40px; 17 | padding-bottom: 40px; 18 | background-color: # eee; 19 | } 20 | .form-inline { 21 | max-width: 330px; 22 | padding: 15px; 23 | margin: 0 auto; 24 | } 25 | body 26 | nav.navbar.navbar-inverse.navbar-fixed-top 27 | .container 28 | .navbar-header 29 | button.navbar-toggle.collapsed(type='button', data-toggle='collapse', data-target='#navbar', aria-expanded='false', aria-controls='navbar') 30 | span.sr-only Toggle navigation 31 | span.icon-bar 32 | span.icon-bar 33 | span.icon-bar 34 | a.navbar-brand(href='#') Project name 35 | #navbar.collapse.navbar-collapse 36 | ul.nav.navbar-nav 37 | li.active 38 | a(href='#') Home 39 | li 40 | a(href='#about') About 41 | li 42 | a(href='#contact') Contact 43 | // /.nav-collapse 44 | .container 45 | .starter-template 46 | h1 #{h1} :: Bootstrap starter template 47 | p.lead 48 | | Use this document as a way to quickly start any new project. 49 | br 50 | | All you get is this text and a mostly barebones HTML document. 51 | // /.container 52 | // 53 | Bootstrap core JavaScript 54 | ================================================== 55 | // Placed at the end of the document so the pages load faster 56 | script(src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js') 57 | script(src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js') 58 | -------------------------------------------------------------------------------- /docs/05website/code/bin/public/views/error.pug: -------------------------------------------------------------------------------- 1 | extends layout 2 | 3 | block content 4 | h1= message 5 | h2= error.status 6 | pre #{error.stack} 7 | -------------------------------------------------------------------------------- /docs/05website/code/bin/public/views/index.pug: -------------------------------------------------------------------------------- 1 | extends layout 2 | 3 | block content 4 | h1= title 5 | p Welcome to #{title} 6 | -------------------------------------------------------------------------------- /docs/05website/code/bin/public/views/layout.pug: -------------------------------------------------------------------------------- 1 | doctype html 2 | html 3 | head 4 | title= title 5 | link(rel='stylesheet', href='/stylesheets/style.css') 6 | body 7 | block content 8 | -------------------------------------------------------------------------------- /docs/05website/code/build_00.hxml: -------------------------------------------------------------------------------- 1 | --library hxnodejs 2 | --library express 3 | --class-path src 4 | --main Main00 5 | --js bin/example.js 6 | --dce full 7 | -D js-es=6 8 | 9 | # --next 10 | 11 | # # Use terminal command to start Node.js! 12 | # --cmd echo "use: 'node bin/example.js' to check script " 13 | # --cmd cd bin 14 | # --cmd node example.js 15 | # --cmd echo exit -------------------------------------------------------------------------------- /docs/05website/code/build_01.hxml: -------------------------------------------------------------------------------- 1 | --library hxnodejs 2 | --library express 3 | --library morgan 4 | --library serve-favicon 5 | --class-path src 6 | --main Main01 7 | --js bin/example.js 8 | --dce full 9 | -D js-es=6 10 | 11 | # --next 12 | 13 | # # Use terminal command to start Node.js! 14 | # --cmd echo "use: 'node bin/example.js' to check script " 15 | # --cmd cd bin 16 | # --cmd node example.js 17 | # --cmd echo exit -------------------------------------------------------------------------------- /docs/05website/code/build_02.hxml: -------------------------------------------------------------------------------- 1 | --library hxnodejs 2 | --library express 3 | --library morgan 4 | --library serve-favicon 5 | --class-path src 6 | --main Main02 7 | --js bin/example.js 8 | --dce full 9 | -D js-es=6 10 | 11 | # --next 12 | 13 | # # Use terminal command to start Node.js! 14 | # --cmd echo "use: 'node bin/example.js' to check script " 15 | # --cmd cd bin 16 | # --cmd node example.js 17 | # --cmd echo exit -------------------------------------------------------------------------------- /docs/05website/code/build_03.hxml: -------------------------------------------------------------------------------- 1 | --library hxnodejs 2 | --library express 3 | --library morgan 4 | --library serve-favicon 5 | --class-path src 6 | --main Main03 7 | --js bin/example.js 8 | --dce full 9 | -D js-es=6 10 | 11 | # --next 12 | 13 | # # Use terminal command to start Node.js! 14 | # --cmd echo "use: 'node bin/example.js' to check script " 15 | # --cmd cd bin 16 | # --cmd node example.js 17 | # --cmd echo exit -------------------------------------------------------------------------------- /docs/05website/code/build_04.hxml: -------------------------------------------------------------------------------- 1 | --library hxnodejs 2 | --library express 3 | --library morgan 4 | --library serve-favicon 5 | --library cookie-parser 6 | --class-path src 7 | --main Main04 8 | --js bin/example.js 9 | --dce full 10 | -D js-es=6 11 | 12 | # --next 13 | 14 | # # Use terminal command to start Node.js! 15 | # --cmd echo "use: 'node bin/example.js' to check script " 16 | # --cmd cd bin 17 | # --cmd node example.js 18 | # --cmd echo exit -------------------------------------------------------------------------------- /docs/05website/code/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "postinstall": "dts2hx --all && haxelib install hxnodejs" 4 | }, 5 | "devDependencies": { 6 | "dts2hx": "^0.14.6" 7 | }, 8 | "dependencies": { 9 | "@types/cookie-parser": "^1.4.2", 10 | "@types/express": "^4.17.8", 11 | "@types/morgan": "^1.9.1", 12 | "@types/serve-favicon": "^2.5.1", 13 | "cookie-parser": "^1.4.5", 14 | "express": "^4.17.1", 15 | "morgan": "^1.10.0", 16 | "pug": "^3.0.0", 17 | "serve-favicon": "^2.5.0" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /docs/05website/code/src/Main00.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | import node.net.AddressInfo; 4 | import js.Node; 5 | import Express; 6 | 7 | /** 8 | * @author Matthijs Kamstra aka [mck] 9 | */ 10 | class Main00 { 11 | var server:node.http.Server; 12 | 13 | function new() { 14 | // source http://expressjs.com/starter/hello-world.html 15 | 16 | var app = Express.call(); 17 | var port = 3000; 18 | 19 | trace('Express website (Basic): open browser at http://localhost:${port}'); 20 | trace('Stop node.js : CTRL + c'); 21 | 22 | app.get('/', (req, res, next) -> { 23 | res.send('Hello World! :: Express website (00)'); 24 | }); 25 | 26 | server = app.listen(port, function() { 27 | var addressInfo:AddressInfo = server.address(); 28 | trace('Example app listening at http://${addressInfo.address}:${addressInfo.port}'); // ???? http://:::3000 29 | }); 30 | } 31 | 32 | static public function main() { 33 | var main = new Main00(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /docs/05website/code/src/Main01.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | import js.Node; 4 | import js.node.Path; 5 | import Express; 6 | import Morgan; 7 | import ServeFavicon; 8 | 9 | /** 10 | * @author Matthijs Kamstra aka [mck] 11 | */ 12 | class Main01 { 13 | function new() { 14 | // source: https://www.codementor.io/nodejs/tutorial/build-google-tv-raspberrypi-nodejs-socket-io 15 | 16 | var app = Express.call(); 17 | var port = 3000; 18 | 19 | trace('Express website (01): open browser at http://localhost:${port}'); 20 | trace("Stop node.js : CTRL + c"); 21 | 22 | // all environments 23 | app.set('port', 3000); 24 | 25 | // app.use(new Favicon(Node.__dirname + '/public/favicon.ico')); 26 | app.use(cast ServeFavicon.call(Node.__dirname + '/public/favicon.ico')); 27 | 28 | // var morgan = Morgan.call('dev'); 29 | app.use(cast Morgan.call('dev')); 30 | 31 | // app.use(BodyParser.urlencoded()); 32 | 33 | // var _static = Express.static_.call(Path.join(Node.__dirname, 'public')); 34 | app.use(cast Express.static_.call(Path.join(Node.__dirname, 'public'))); 35 | 36 | // Routes 37 | 38 | // http://localhost:3000 39 | app.get('/', (req, res, next) -> { 40 | res.send('Hello World! :: Express website (01)'); 41 | }); 42 | 43 | app.get('/test', function(req, res, next) { 44 | res.sendFile(Node.__dirname + '/public/index_intermediate.html'); 45 | return null; 46 | }); 47 | 48 | // http://localhost:3000/remote 49 | app.get('/remote', (req, res, next) -> { 50 | res.sendFile(Node.__dirname + '/public/remote_intermediate.html'); 51 | return null; 52 | }); 53 | 54 | // http://localhost:3000/nope 55 | app.use((req, res, next) -> { 56 | res.status(404).send('404'); 57 | }); 58 | 59 | var server = app.listen(app.get('port'), function() { 60 | trace('Express server listening on port ' + app.get('port')); 61 | }); 62 | } 63 | 64 | static public function main() { 65 | var main = new Main01(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /docs/05website/code/src/Main02.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | import js.Node; 4 | import js.node.Path; 5 | import Express; 6 | import Morgan; 7 | import ServeFavicon; 8 | 9 | /** 10 | * @author Matthijs Kamstra aka [mck] 11 | */ 12 | class Main02 { 13 | function new() { 14 | var app = Express.call(); 15 | var port = 3000; 16 | 17 | trace('Express website (02): open browser at http://localhost:${port}'); 18 | trace("Stop node.js : CTRL + c"); 19 | 20 | // https://www.codementor.io/nodejs/tutorial/build-google-tv-raspberrypi-nodejs-socket-io 21 | // https://scotch.io/tutorials/use-expressjs-to-get-url-and-post-parameters 22 | // http://www.clock.co.uk/blog/a-simple-website-in-nodejs-with-express-jade-and-stylus 23 | 24 | // all environments 25 | app.set('port', 3000); 26 | 27 | // app.use(new Favicon(Node.__dirname + '/public/favicon.ico')); 28 | app.use(cast ServeFavicon.call(Node.__dirname + '/public/favicon.ico')); 29 | 30 | app.set('views', Node.__dirname + '/public/views'); 31 | app.set('view engine', 'pug'); 32 | 33 | // var morgan = Morgan.call('dev'); 34 | app.use(cast Morgan.call('dev')); 35 | 36 | // app.use(BodyParser.json()); 37 | // app.use(BodyParser.urlencoded({extended: true})); 38 | // // app.use(new MethodOverride()); // can't find it in js-kit AND don't know what it does... 39 | 40 | // var _static = Express.static_.call(Path.join(Node.__dirname, 'public')); 41 | app.use(cast Express.static_.call(Path.join(Node.__dirname, 'public'))); 42 | 43 | // Routes 44 | 45 | // http://localhost:3000 46 | app.get('/', (req, res, next) -> { 47 | res.send('Hello World! :: Express website (02)'); 48 | }); 49 | 50 | // http://localhost:3000/remote 51 | app.get('/remote', (req, res, next) -> { 52 | res.sendFile(Node.__dirname + '/public/remote_intermediate.html'); 53 | return null; 54 | }); 55 | 56 | // http://localhost:3000/pug 57 | app.get('/pug', (req, res, next) -> { 58 | res.render('index', {title: 'Home', h1: 'Title'}); 59 | return null; 60 | }); 61 | 62 | // http://localhost:3000/api/users?username=foobar 63 | // routes will go here 64 | app.get('/api/users', (req, res, next) -> { 65 | var username = req.param('username'); 66 | res.send('username: ' + username); 67 | return null; 68 | }); 69 | 70 | // POST http://localhost:8080/api/users 71 | app.post('/api/users', (req, res, next) -> { 72 | var _req:Dynamic = req; 73 | var _username = _req.body.username; 74 | res.send('_username: ' + _username); 75 | return null; 76 | }); 77 | 78 | // http://localhost:3000/nope 79 | app.use((req, res, next) -> { 80 | res.status(404).send('404'); 81 | }); 82 | 83 | app.listen(app.get('port'), function() { 84 | trace('Express server listening on port ' + app.get('port')); 85 | }); 86 | } 87 | 88 | static public function main() { 89 | var main = new Main02(); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /docs/05website/code/src/Main03.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | import js.Node; 4 | import js.node.Path; 5 | import Express; 6 | import Morgan; 7 | import ServeFavicon; 8 | 9 | /** 10 | * @author Matthijs Kamstra aka [mck] 11 | */ 12 | class Main03 { 13 | function new() { 14 | var app = Express.call(); 15 | var port = 3000; 16 | 17 | trace('Express website (03): open browser at http://localhost:${port}'); 18 | trace("Stop node.js : CTRL + c"); 19 | 20 | var router = express.Router.call_(); 21 | 22 | // middleware that is specific to this router 23 | router.use(function timeLog(req, res, next) { 24 | js.Browser.console.log('Time: ', Date.now()); 25 | return null; 26 | }); 27 | 28 | router.get('/', (req, res, next) -> { 29 | res.send('Hello World router style!'); 30 | }); 31 | // define the home page route 32 | router.get('/birds', function(req, res, next) { 33 | res.send('Birds home page'); 34 | return null; 35 | }); 36 | // define the about route 37 | router.get('/about', function(req, res, next) { 38 | res.send('About birds'); 39 | return null; 40 | }); 41 | 42 | // app.get('/', (req, res, next) -> res.send('Hello World!')); 43 | app.listen(port, () -> trace('Example app listening at http://localhost:${port}')); 44 | } 45 | 46 | static public function main() { 47 | var main = new Main03(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /docs/05website/code/src/Main04.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | import CookieParser; 4 | import js.Node; 5 | import js.node.Path; 6 | import Express; 7 | import Morgan; 8 | import ServeFavicon; 9 | 10 | /** 11 | * @author Matthijs Kamstra aka [mck] 12 | */ 13 | class Main04 { 14 | function new() { 15 | // https://expressjs.com/en/starter/generator.html 16 | 17 | var app = Express.call(); 18 | var port = 3000; 19 | 20 | trace('Express website (04): open browser at http://localhost:${port}'); 21 | trace("Stop node.js : CTRL + c"); 22 | 23 | // var createError = require('http-errors'); 24 | // var express = require('express'); 25 | // var path = require('path'); 26 | // var cookieParser = require('cookie-parser'); 27 | // var logger = require('morgan'); 28 | 29 | // var indexRouter = require('./routes/index'); 30 | // var usersRouter = require('./routes/users'); 31 | 32 | // var app = express(); 33 | 34 | // view engine setup 35 | app.set('views', Path.join(Node.__dirname, 'public', 'views')); 36 | app.set('view engine', 'pug'); 37 | 38 | // app.use(logger('dev')); 39 | app.use(cast Morgan.call('dev')); 40 | 41 | app.use(cast Express.json()); 42 | app.use(cast Express.urlencoded({extended: false})); 43 | app.use(cast CookieParser.call()); 44 | app.use(cast Express.static_.call(Path.join(Node.__dirname, 'public'))); 45 | 46 | // smoke signal 47 | // app.get('/', (req, res, next) -> res.send('Hello World!')); 48 | 49 | // test if it works 50 | // app.get('/', function(req, res, next) { 51 | // res.render('index', {title: 'Express'}); 52 | // return null; 53 | // }); 54 | 55 | var router = express.Router.call_(); 56 | routes.Index.init(router); 57 | 58 | // app.use('/', indexRouter); 59 | // app.use('/users', usersRouter); 60 | 61 | // catch 404 and forward to error handler 62 | // app.use(function(req, res, next) { 63 | // next(createError(404)); 64 | // }); 65 | 66 | // error handler 67 | // app.use(function(err, req, res, next) { 68 | // // set locals, only providing error in development 69 | // res.locals.message = err.message; 70 | // res.locals.error = req.app.get('env') == 'development' ? err : {}; 71 | 72 | // // render the error page 73 | // res.status(err.status || 500); 74 | // res.render('error'); 75 | // }); 76 | 77 | var server = app.listen(port, () -> trace('Example app listening at http://localhost:${port}')); 78 | // server.on 79 | } 80 | 81 | static public function main() { 82 | var main = new Main04(); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /docs/05website/code/src/routes/Index.hx: -------------------------------------------------------------------------------- 1 | package routes; 2 | 3 | class Index { 4 | public static function init(app:express_serve_static_core.Router):Void { 5 | /* GET home page. */ 6 | app.get('/', function(req, res, next) { 7 | res.render('index', {title: 'Express'}); 8 | return null; 9 | }); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /docs/05website/code/src/routes/Users.hx: -------------------------------------------------------------------------------- 1 | package routes; 2 | 3 | -------------------------------------------------------------------------------- /docs/05website/exampleBasic.md: -------------------------------------------------------------------------------- 1 | # Example basic website 2 | 3 | We start with a simple example from the ExpressJS homepage: 4 | 5 | 6 | ## How to start 7 | 8 | Create a folder named **foobar** (please use a better name; any name will do) and create folders **bin** and **src**. 9 | See example below: 10 | 11 | ``` 12 | + foobar 13 | + bin 14 | + src 15 | - MainBasic.hx 16 | - javascript.hxml 17 | ``` 18 | 19 | ## Install 20 | 21 | Check out [the installation](installation.md). 22 | 23 | ## The MainBasic.hx 24 | 25 | Open your favorite editor, copy/paste the code and save it in the `src` folder. 26 | 27 | ```haxe 28 | package ; 29 | import js.Node; 30 | import js.npm.Express; 31 | class MainBasic 32 | { 33 | private var server:Dynamic; 34 | function new() 35 | { 36 | trace("Express website (Basic): open browser at http://localhost:3000"); 37 | trace("stop node : CTRL + c"); 38 | 39 | var app : Express = new Express(); 40 | 41 | app.get('/', function (req, res) { 42 | res.send('Hello World!'); 43 | }); 44 | 45 | server = app.listen(3000, function () 46 | { 47 | var host = server.address().address; 48 | var port = server.address().port; 49 | trace( 'Example app listening at http://$host:$port'); // ???? http://:::3000 50 | }); 51 | 52 | } 53 | 54 | static public function main() 55 | { 56 | var main = new MainBasic(); 57 | } 58 | } 59 | ``` 60 | 61 | ## The Haxe build file, javascript.hxml 62 | 63 | Copy and past the following lines in a document named `javascript.hxml` 64 | This is the short version, you want to chech out the full version open this [file](/code/javascript.hxml); 65 | 66 | ``` 67 | # // javascript.hxml 68 | -lib js-kit 69 | -lib hxnodejs 70 | -cp src 71 | -main MainBasic 72 | -js bin/example.js 73 | -cmd cd bin 74 | -cmd node example.js 75 | ``` 76 | 77 | ## Build js with Haxe and start Node 78 | 79 | To finish and see what we have, build the file and see the result 80 | 81 | 1. Open your terminal 82 | 2. `cd ` to the correct folder where you have saved the `javascript.hxml` 83 | 3. type `haxe javascript.hxml` 84 | 4. press enter 85 | 86 | --- 87 | -------------------------------------------------------------------------------- /docs/05website/installation.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | 3 | Read the how to install **Node.js** and **Haxe** [here](../haxenode/download.md). 4 | Once you have installed **Haxe** you will automatically installed `haxelib`. 5 | The same goes for **Node.js**, you will have automatically installed `NPM`. 6 | 7 | ## Install Node.js externs for Haxe 8 | 9 | Install the [official Haxe node.js externs](https://github.com/HaxeFoundation/hxnodejs) lib via [haxelib](http://lib.haxe.org/p/hxnodejs/). 10 | Haxelib is automatically installed when installing Haxe and you can see it as a sort of NPM. 11 | 12 | ```bash 13 | haxelib install hxnodejs 14 | ``` 15 | 16 | In this tutorial I use js-kit externs, there are more ways to get externs but the js-kit has a lot so it's more a one stop shop thing! 17 | 18 | ```bash 19 | haxelib git js-kit https://github.com/clemos/haxe-js-kit.git haxelib 20 | 21 | ``` 22 | 23 | ## Install express via NPM : 24 | 25 | [Express](https://github.com/strongloop/express) 26 | 27 | > Fast, un-opinionated, minimalist web framework for node. 28 | 29 | ``` 30 | npm install express 31 | ``` 32 | 33 | ## Install for the more Intermediate and Advance example 34 | 35 | Express uses more dependencies: 36 | 37 | ``` 38 | npm install morgan 39 | npm install body-parser 40 | npm install serve-favicon 41 | npm install express 42 | npm install jade 43 | ``` 44 | 45 | --- 46 | 47 | ## Install all modules with NPM via package.json 48 | 49 | If you have a package.json file in your directory and you run npm install, then npm will look at the dependencies that are listed in that file and download the latest versions satisfying semver rules for all of those. 50 | 51 | To do so, `cd` to the correct folder ( `cd path/to/correct/folder/with/package/dot/json/` ) 52 | 53 | ``` 54 | npm install 55 | ``` 56 | 57 | This will install everything in `node_modules`. 58 | -------------------------------------------------------------------------------- /docs/05website/test.md: -------------------------------------------------------------------------------- 1 | ``` 2 | npm install body-parser express jade morgan serve-favicon 3 | ``` 4 | 5 | ## tl;dr 6 | 7 | ``` 8 | # install 9 | npm install dts2hx --save-dev 10 | npm install express --save 11 | npm install @types/express --save 12 | 13 | # run dts2hx 14 | npx dts2hx express 15 | 16 | # install hxnodejs 17 | haxelib install hxnodejs 18 | 19 | # don't forget to add `--library express` to your build 20 | ``` 21 | 22 | ## install packages 23 | 24 | ``` 25 | npm install dts2hx --save-dev 26 | npm install express --save 27 | npm install @types/express --save 28 | ``` 29 | 30 | ## run dts2hx 31 | 32 | ``` 33 | // doesn't work because the express ts files are not in the repo 34 | npx dts2hx express 35 | ``` 36 | 37 | works 38 | 39 | ``` 40 | npx dts2hx @types/express 41 | ``` 42 | 43 | ## add lib 44 | 45 | build.hxml 46 | 47 | ``` 48 | --library express 49 | ``` 50 | 51 | ## install hxnodejs in .haxelib folder 52 | 53 | ```bash 54 | haxelib install hxnodejs 55 | ``` 56 | -------------------------------------------------------------------------------- /docs/05website/tip.md: -------------------------------------------------------------------------------- 1 | ``` 2 | npm install -g nodemon 3 | ``` 4 | 5 | use 6 | 7 | ``` 8 | nodemon example.js 9 | ``` -------------------------------------------------------------------------------- /docs/05website/todo.md: -------------------------------------------------------------------------------- 1 | https://www.codementor.io/nodejs/tutorial/build-google-tv-raspberrypi-nodejs-socket-io 2 | -------------------------------------------------------------------------------- /docs/06nedb/about.md: -------------------------------------------------------------------------------- 1 | # About Nedb 2 | 3 | There is always a need to store data, one way or another. 4 | We already describe two ways to store data in a `.json` file ([haxelow](../04haxelow) and [lowdb](../03lowdb)). 5 | 6 | But what if we need something with more punch: [NeDB](https://github.com/louischatriot/nedb) 7 | 8 | ## NeDB (Node embedded database) 9 | 10 | > Embedded persistent database for Node.js, written in JavaScript, with no dependency (except npm modules). Which can be used with a simple require statement. The API is a subset of MongoDB's. You can use it as a persistent or an in-memory only datastore, and it can also be used in all recent browsers (Chrome, Firefox, Safari, IE9+). 11 | 12 | ``` 13 | npm install nedb --save 14 | ``` 15 | -------------------------------------------------------------------------------- /docs/06nedb/code/bin/database01.db: -------------------------------------------------------------------------------- 1 | {"hello":"world","n":5,"today":{"$$date":1631353300315},"nedbIsAwesome":true,"notthere":null,"fruits":["apple","orange","pear"],"infos":{"name":"nedb"},"_id":"GveaVTyzU4oh8RXA"} 2 | -------------------------------------------------------------------------------- /docs/06nedb/code/bin/database02.db: -------------------------------------------------------------------------------- 1 | {"_id":"id1","planet":"Mars","system":"solar","inhabited":false,"createdAt":{"$$date":1631353300903},"updatedAt":{"$$date":1631353300903}} 2 | {"_id":"id1","planet":"Mars","system":"solar","inhabited":false,"createdAt":{"$$date":1631353300903},"updatedAt":{"$$date":1631353300912},"satellites":["Phobos","Deimos"]} 3 | -------------------------------------------------------------------------------- /docs/06nedb/code/bin/database03.db: -------------------------------------------------------------------------------- 1 | {"_id":"id1","planet":"Mars","system":"solar","inhabited":false,"satellites":["Phobos","Deimos"]} 2 | {"_id":"id1631353301411","planet":"Earth","system":"solar","inhabited":true,"humans":{"genders":2,"eyes":true}} 3 | {"_id":"id1631353301412","planet":"Jupiter","system":"solar","inhabited":false} 4 | {"_id":"id1631353301413","planet":"Omicron Persei 8","system":"futurama","inhabited":true,"humans":{"genders":7}} 5 | {"_id":"id1631353301414","completeData":{"planets":[{"name":"Earth","number":3},{"name":"Mars","number":2},{"name":"Pluton","number":9}]}} 6 | -------------------------------------------------------------------------------- /docs/06nedb/code/bin/example01.js: -------------------------------------------------------------------------------- 1 | (function ($global) { "use strict"; 2 | class Main01 { 3 | constructor() { 4 | console.log("src/Main01.hx:11:","Node.js NeDB example 01"); 5 | let options = { filename : js_node_Path.join(__dirname,"/database01.db"), autoload : true}; 6 | let db = new Nedb(options); 7 | let doc = { hello : "world", n : 5, today : new Date(), nedbIsAwesome : true, notthere : null, fruits : ["apple","orange","pear"], infos : { name : "nedb"}}; 8 | db.insert(doc,function(err,newDoc) { 9 | console.log("src/Main01.hx:34:","newDoc: " + Std.string(newDoc)); 10 | }); 11 | } 12 | static main() { 13 | let main = new Main01(); 14 | } 15 | } 16 | Main01.__name__ = true; 17 | Math.__name__ = true; 18 | var Nedb = require("nedb"); 19 | class Std { 20 | static string(s) { 21 | return js_Boot.__string_rec(s,""); 22 | } 23 | } 24 | Std.__name__ = true; 25 | class haxe_iterators_ArrayIterator { 26 | constructor(array) { 27 | this.current = 0; 28 | this.array = array; 29 | } 30 | hasNext() { 31 | return this.current < this.array.length; 32 | } 33 | next() { 34 | return this.array[this.current++]; 35 | } 36 | } 37 | haxe_iterators_ArrayIterator.__name__ = true; 38 | class js_Boot { 39 | static __string_rec(o,s) { 40 | if(o == null) { 41 | return "null"; 42 | } 43 | if(s.length >= 5) { 44 | return "<...>"; 45 | } 46 | let t = typeof(o); 47 | if(t == "function" && (o.__name__ || o.__ename__)) { 48 | t = "object"; 49 | } 50 | switch(t) { 51 | case "function": 52 | return ""; 53 | case "object": 54 | if(((o) instanceof Array)) { 55 | let str = "["; 56 | s += "\t"; 57 | let _g = 0; 58 | let _g1 = o.length; 59 | while(_g < _g1) { 60 | let i = _g++; 61 | str += (i > 0 ? "," : "") + js_Boot.__string_rec(o[i],s); 62 | } 63 | str += "]"; 64 | return str; 65 | } 66 | let tostr; 67 | try { 68 | tostr = o.toString; 69 | } catch( _g ) { 70 | return "???"; 71 | } 72 | if(tostr != null && tostr != Object.toString && typeof(tostr) == "function") { 73 | let s2 = o.toString(); 74 | if(s2 != "[object Object]") { 75 | return s2; 76 | } 77 | } 78 | let str = "{\n"; 79 | s += "\t"; 80 | let hasp = o.hasOwnProperty != null; 81 | let k = null; 82 | for( k in o ) { 83 | if(hasp && !o.hasOwnProperty(k)) { 84 | continue; 85 | } 86 | if(k == "prototype" || k == "__class__" || k == "__super__" || k == "__interfaces__" || k == "__properties__") { 87 | continue; 88 | } 89 | if(str.length != 2) { 90 | str += ", \n"; 91 | } 92 | str += s + k + " : " + js_Boot.__string_rec(o[k],s); 93 | } 94 | s = s.substring(1); 95 | str += "\n" + s + "}"; 96 | return str; 97 | case "string": 98 | return o; 99 | default: 100 | return String(o); 101 | } 102 | } 103 | } 104 | js_Boot.__name__ = true; 105 | var js_node_Path = require("path"); 106 | { 107 | String.__name__ = true; 108 | Array.__name__ = true; 109 | Date.__name__ = "Date"; 110 | } 111 | js_Boot.__toStr = ({ }).toString; 112 | Main01.main(); 113 | })({}); 114 | -------------------------------------------------------------------------------- /docs/06nedb/code/bin/example02.js: -------------------------------------------------------------------------------- 1 | (function ($global) { "use strict"; 2 | class Main02 { 3 | constructor() { 4 | console.log("src/Main02.hx:11:","Node.js NeDB example 02"); 5 | let options = { filename : js_node_Path.join(__dirname,"/database02.db"), autoload : true, timestampData : true}; 6 | let db = new Nedb(options); 7 | let _planet = { _id : "id1", planet : "Mars", system : "solar", inhabited : false}; 8 | db.insert(_planet); 9 | db.update({ _id : "id1"},{ $set : { satellites : ["Phobos","Deimos"]}}); 10 | } 11 | static main() { 12 | let main = new Main02(); 13 | } 14 | } 15 | var Nedb = require("nedb"); 16 | class haxe_iterators_ArrayIterator { 17 | constructor(array) { 18 | this.current = 0; 19 | this.array = array; 20 | } 21 | hasNext() { 22 | return this.current < this.array.length; 23 | } 24 | next() { 25 | return this.array[this.current++]; 26 | } 27 | } 28 | var js_node_Path = require("path"); 29 | { 30 | } 31 | Main02.main(); 32 | })({}); 33 | -------------------------------------------------------------------------------- /docs/06nedb/code/bin/example03.js: -------------------------------------------------------------------------------- 1 | (function ($global) { "use strict"; 2 | class Main03 { 3 | constructor() { 4 | console.log("src/Main03.hx:12:","Node.js NeDB example 03"); 5 | let options = { filename : js_node_Path.join(__dirname,"/database03.db"), autoload : true}; 6 | let db = new Nedb(options); 7 | db.insert({ _id : "id1", planet : "Mars", system : "solar", inhabited : false, satellites : ["Phobos","Deimos"]}); 8 | db.insert({ _id : "id" + (new Date().getTime() + 2), planet : "Earth", system : "solar", inhabited : true, humans : { genders : 2, eyes : true}}); 9 | db.insert({ _id : "id" + (new Date().getTime() + 3), planet : "Jupiter", system : "solar", inhabited : false}); 10 | db.insert({ _id : "id" + (new Date().getTime() + 4), planet : "Omicron Persei 8", system : "futurama", inhabited : true, humans : { genders : 7}}); 11 | db.insert({ _id : "id" + (new Date().getTime() + 5), completeData : { planets : [{ name : "Earth", number : 3},{ name : "Mars", number : 2},{ name : "Pluton", number : 9}]}}); 12 | db.find({ system : "solar"},function(err,docs) { 13 | console.log("src/Main03.hx:64:","{ system: 'solar' } :: " + docs.length); 14 | }); 15 | db.find({ system : "solar", inhabited : true},function(err,docs) { 16 | console.log("src/Main03.hx:76:","{ system: 'solar', inhabited: true } :: " + docs.length); 17 | }); 18 | db.find({ "humans.genders" : 2},function(err,docs) { 19 | console.log("src/Main03.hx:82:","{ \"humans.genders\": 2 } :: " + docs.length); 20 | }); 21 | db.find({ "completeData.planets.name" : "Mars"},function(err,docs) { 22 | console.log("src/Main03.hx:88:","docs: " + docs); 23 | }); 24 | db.find({ "completeData.planets.name" : "Jupiter"},function(err,docs) { 25 | console.log("src/Main03.hx:93:","docs.length: " + docs.length); 26 | }); 27 | db.find({ "completeData.planets.0.name" : "Earth"},function(err,docs) { 28 | console.log("src/Main03.hx:99:","docs.length: " + docs.length); 29 | }); 30 | db.find({ humans : { genders : 2}},function(err,docs) { 31 | console.log("src/Main03.hx:105:","docs.length: " + docs.length); 32 | }); 33 | db.find({ },function(err,docs) { 34 | console.log("src/Main03.hx:110:","docs.length: " + docs.length); 35 | }); 36 | db.findOne({ _id : "id1"},function(err,doc) { 37 | console.log("src/Main03.hx:117:","doc.planet: " + doc.planet); 38 | }); 39 | } 40 | static main() { 41 | let main = new Main03(); 42 | } 43 | } 44 | var Nedb = require("nedb"); 45 | class haxe_iterators_ArrayIterator { 46 | constructor(array) { 47 | this.current = 0; 48 | this.array = array; 49 | } 50 | hasNext() { 51 | return this.current < this.array.length; 52 | } 53 | next() { 54 | return this.array[this.current++]; 55 | } 56 | } 57 | var js_node_Path = require("path"); 58 | { 59 | } 60 | Main03.main(); 61 | })({}); 62 | -------------------------------------------------------------------------------- /docs/06nedb/code/build_01.hxml: -------------------------------------------------------------------------------- 1 | --library nedb 2 | --library hxnodejs 3 | --class-path src 4 | --main Main01 5 | --js bin/example01.js 6 | --dce full 7 | -D js-es=6 8 | -D source-map-content 9 | 10 | --next 11 | 12 | # Use terminal command to start Node.js! 13 | # --cmd echo "use: 'node bin/example.js' to check script " 14 | --cmd cd bin 15 | --cmd node example01.js 16 | # --cmd echo exit -------------------------------------------------------------------------------- /docs/06nedb/code/build_02.hxml: -------------------------------------------------------------------------------- 1 | --library nedb 2 | --library hxnodejs 3 | --class-path src 4 | --main Main02 5 | --js bin/example02.js 6 | --dce full 7 | -D js-es=6 8 | -D source-map-content 9 | 10 | --next 11 | 12 | # Use terminal command to start Node.js! 13 | # --cmd echo "use: 'node bin/example.js' to check script " 14 | --cmd cd bin 15 | --cmd node example02.js 16 | # --cmd echo exit -------------------------------------------------------------------------------- /docs/06nedb/code/build_03.hxml: -------------------------------------------------------------------------------- 1 | --library nedb 2 | --library hxnodejs 3 | --class-path src 4 | --main Main03 5 | --js bin/example03.js 6 | --dce full 7 | -D js-es=6 8 | -D source-map-content 9 | 10 | --next 11 | 12 | # Use terminal command to start Node.js! 13 | # --cmd echo "use: 'node bin/example.js' to check script " 14 | --cmd cd bin 15 | --cmd node example03.js 16 | # --cmd echo exit -------------------------------------------------------------------------------- /docs/06nedb/code/build_all.hxml: -------------------------------------------------------------------------------- 1 | --cmd haxe build_01.hxml 2 | --cmd haxe build_02.hxml 3 | --cmd haxe build_03.hxml -------------------------------------------------------------------------------- /docs/06nedb/code/dts2hx_convert.md: -------------------------------------------------------------------------------- 1 | ## tl;dr 2 | 3 | ```bash 4 | # install 5 | npm install dts2hx --save-dev 6 | npm install nedb --save 7 | npm install @types/nedb --save 8 | 9 | # run dts2hx 10 | npx dts2hx nedb 11 | 12 | # install hxnodejs 13 | haxelib install hxnodejs 14 | 15 | # don't forget to add `--library nedb` to your build 16 | ``` 17 | 18 | ## install packages 19 | 20 | ```bash 21 | npm install dts2hx --save-dev 22 | npm install nedb --save 23 | npm install @types/nedb --save 24 | ``` 25 | 26 | ## run dts2hx 27 | 28 | ```bash 29 | // doesn't work because the nedb ts files are not in the repo 30 | npx dts2hx nedb 31 | ``` 32 | 33 | works 34 | 35 | ```bash 36 | npx dts2hx @types/nedb 37 | ``` 38 | 39 | ## add lib 40 | 41 | build.hxml 42 | 43 | ```bash 44 | --library nedb 45 | ``` 46 | 47 | ## install hxnodejs in .haxelib folder 48 | 49 | ```bash 50 | haxelib install hxnodejs 51 | ``` 52 | -------------------------------------------------------------------------------- /docs/06nedb/code/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "postinstall": "dts2hx --all && haxelib install hxnodejs" 4 | }, 5 | "devDependencies": { 6 | "dts2hx": "^0.16.0" 7 | }, 8 | "dependencies": { 9 | "@types/nedb": "^1.8.12", 10 | "nedb": "^1.8.0" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /docs/06nedb/code/src/Main01.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | import js.Node; 4 | import js.node.Path; 5 | 6 | /** 7 | * @author Matthijs Kamstra aka [mck] 8 | */ 9 | class Main01 { 10 | function new() { 11 | trace("Node.js NeDB example 01"); 12 | 13 | // https://github.com/louischatriot/nedb#creatingloading-a-database 14 | 15 | var options:nedb.DataStoreOptions = {filename: Path.join(Node.__dirname, '/database01.db'), autoload: true}; 16 | var db = new Nedb(options); 17 | 18 | var doc = { 19 | hello: 'world', 20 | n: 5, 21 | today: Date.now(), 22 | nedbIsAwesome: true, 23 | notthere: null, 24 | // notToBeSaved: undefined, // Will not be saved (Doesn't even work in Haxe: src/Main00.hx:29: characters 17-26 : Unknown identifier : undefined) 25 | fruits: ['apple', 'orange', 'pear'], 26 | infos: {name: 'nedb'} 27 | }; 28 | 29 | db.insert(doc, function(err, newDoc) { 30 | // Callback is optional 31 | // newDoc is the newly inserted document, including its _id 32 | // newDoc has no key called notToBeSaved since its value was undefined 33 | 34 | trace('newDoc: $newDoc'); 35 | }); 36 | } 37 | 38 | static public function main() { 39 | var main = new Main01(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /docs/06nedb/code/src/Main02.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | import js.Node; 4 | import js.node.Path; 5 | 6 | /** 7 | * @author Matthijs Kamstra aka [mck] 8 | */ 9 | class Main02 { 10 | function new() { 11 | trace("Node.js NeDB example 02"); 12 | 13 | // https://github.com/louischatriot/nedb#finding-documents 14 | 15 | var options:nedb.DataStoreOptions = {filename: Path.join(Node.__dirname, '/database02.db'), autoload: true, timestampData: true}; 16 | var db = new Nedb(options); 17 | 18 | var _planet:Planet = { 19 | _id: 'id1', 20 | planet: 'Mars', 21 | system: 'solar', 22 | inhabited: false 23 | }; 24 | 25 | db.insert(_planet); 26 | 27 | db.update({_id: 'id1'}, {$set:{satellites:['Phobos', 'Deimos']}}); 28 | } 29 | 30 | static public function main() { 31 | var main = new Main02(); 32 | } 33 | } 34 | 35 | typedef Planet = { 36 | @:optional var _id:String; // 'id1' 37 | var planet:String; // 'Mars' 38 | var system:String; // 'solar' 39 | var inhabited:Bool; // false 40 | @:optional var satellites:Array; // ['Phobos', 'Deimos'] } ); 41 | @:optional var humans:{ 42 | var genders:Int; 43 | @:optional var eyes:Bool; 44 | }; 45 | @:optional var completeData:Dynamic; 46 | } 47 | -------------------------------------------------------------------------------- /docs/06nedb/installation.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | 3 | Read the how to install **Node.js** and **Haxe** [here](../haxenode/download.md). 4 | Once you have installed **Haxe** you will automatically installed `haxelib`. 5 | The same goes for **Node.js**, you will have automatically installed `NPM`. 6 | 7 | ## Install Node.js externs for Haxe 8 | 9 | Install the [official Haxe node.js externs](https://github.com/HaxeFoundation/hxnodejs) lib via [haxelib](http://lib.haxe.org/p/hxnodejs/). 10 | Haxelib is automatically installed when installing Haxe and you can see it as a sort of NPM. 11 | 12 | ```bash 13 | haxelib install hxnodejs 14 | ``` 15 | 16 | In this tutorial I use js-kit externs, there are more ways to get externs but the js-kit has a lot so it's more a one stop shop thing! 17 | 18 | ```bash 19 | haxelib git js-kit https://github.com/clemos/haxe-js-kit.git haxelib 20 | 21 | ``` 22 | 23 | ## Install Nedb via NPM: 24 | 25 | Install nedb 26 | 27 | ``` 28 | npm install nedb --save 29 | ``` 30 | -------------------------------------------------------------------------------- /docs/07restapi/about.md: -------------------------------------------------------------------------------- 1 | # About Node website 2 | 3 | The cool part about _Node.js_ that it's JavaScript for back-end! 4 | You write JavaScript but for the back-end! 5 | Did I mention back-end? 6 | 7 | But the important thing to know is that everything in _Node.js_ is clean/minimal. 8 | You could rewrite every call, or use a framework that does all the heavy lifting. 9 | 10 | If you started this tutorials/examples from the beginning you already seen [http in action](../00helloworld/about.md). 11 | Which tells the http classes that express (also) uses, it's nice to know how things work. 12 | But if you want to create a website I strongly suggest you use `ExpressJS`!!! 13 | 14 | In this tutorial we will be using [Express](http://expressjs.com): 15 | 16 | > ### Web Applications 17 | > 18 | > Express is a minimal and flexible Node.js web application framework. It provides a robust set of features for web and mobile applications. 19 | > 20 | 21 | And build an `index.html`, `remote.html` and `404`! 22 | 23 | This example covers 3 different examples 24 | 25 | - [Basic](exampleBasic.md) 26 | - [Intermediate](exampleIntermediate.md) 27 | - [Advanced](exampleAdvanced.md) 28 | 29 | Because I don't want to spend time on styling the `.html`/`.jade` files, I use [Bootstrap](http://getbootstrap.com/getting-started/#examples) 30 | 31 | --- 32 | -------------------------------------------------------------------------------- /docs/07restapi/code/bin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "license": "MIT", 3 | "description": "Create a website with express", 4 | "author": "Matthijs Kamstra aka [mck]", 5 | "start": "node index.js", 6 | "private": true, 7 | "dependencies": { 8 | "express": "~4.17" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /docs/07restapi/code/bin/package.txt: -------------------------------------------------------------------------------- 1 | { 2 | "license": "MIT", 3 | "description": "Create a website with express", 4 | "author": "Matthijs Kamstra aka [mck]", 5 | "start": "node index.js", 6 | "private": true, 7 | "dependencies": { 8 | // "morgan": "^1.5.1", 9 | // "body-parser": "^1.10.1", 10 | // "serve-favicon": "*", 11 | "express": "~4.17" 12 | } 13 | } -------------------------------------------------------------------------------- /docs/07restapi/code/bin/public/favicon.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthijsKamstra/haxenode/6930b222e50c101c9639ac26b72996c69f343e0b/docs/07restapi/code/bin/public/favicon.gif -------------------------------------------------------------------------------- /docs/07restapi/code/bin/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthijsKamstra/haxenode/6930b222e50c101c9639ac26b72996c69f343e0b/docs/07restapi/code/bin/public/favicon.ico -------------------------------------------------------------------------------- /docs/07restapi/code/bin/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Haxe Node - Website - Index 9 | 10 | 11 | 12 |
13 |

Rest API

14 | 22 | 23 |

POST /musicians

24 | 25 |
26 |
27 | 28 | 29 |
30 |
31 | 32 | 33 |
34 | 35 |
36 | 37 | 38 | 54 | 55 | 56 |
57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /docs/07restapi/code/build.hxml: -------------------------------------------------------------------------------- 1 | --library express 2 | --library hxnodejs 3 | --class-path src 4 | --main Main 5 | --js bin/example.js 6 | --dce full 7 | -D js-es=6 8 | 9 | # --next 10 | 11 | # # Use terminal command to start Node.js! 12 | # --cmd echo "use: 'node bin/example.js' to check script " 13 | # --cmd cd bin 14 | # --cmd node example.js 15 | # --cmd echo exit -------------------------------------------------------------------------------- /docs/07restapi/code/src/Controller.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | import js.Node; 4 | 5 | // import js.npm.Express; 6 | // import js.npm.express.*; 7 | class Controller { 8 | public static function index(req, res, next) { 9 | res.sendfile(Node.__dirname + '/public/index.html'); 10 | return null; 11 | } 12 | 13 | public static function findAll(req, res, next) { 14 | res.send([ 15 | { 16 | "id": 1, 17 | "name": "Max", 18 | "band": "Maximum Pain", 19 | "instrument": "guitar" 20 | } 21 | ]); 22 | return null; 23 | }; 24 | 25 | public static function findByName(req, res, next) { 26 | res.send('{"id": 1,"name":"${req.params.name}","band":"BBQ Brawlers"}'); 27 | return null; 28 | }; 29 | 30 | public static function findById(req, res, next) { 31 | res.send('findbyid: ${req.params.id}'); 32 | return null; 33 | }; 34 | 35 | public static function add(req, res, next) { 36 | var inputName = untyped req.body.inputName; // embrace the dynamic nature of javascript/node.js 37 | var inputGroupName = untyped req.body.inputGroupName; 38 | res.send('{"id": 1,"name":"${inputName}","band":"${inputGroupName}"}'); 39 | return null; 40 | }; 41 | 42 | public static function update(req, res, next) { 43 | res.send('update'); 44 | return null; 45 | }; 46 | 47 | public static function delete(req, res, next) { 48 | res.send('delete'); 49 | return null; 50 | }; 51 | } 52 | -------------------------------------------------------------------------------- /docs/07restapi/code/src/Main.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | // import js.Node; 4 | // import js.node.Http; 5 | // import js.node.Path; 6 | // import js.npm.Express; 7 | // import js.npm.express.*; 8 | // import js.Node.console; 9 | 10 | /** 11 | * @author Matthijs Kamstra aka [mck] 12 | */ 13 | class Main { 14 | function new() { 15 | var router = express.Router.call_(); 16 | var app = Express.call(); 17 | var PORT = 3001; 18 | 19 | trace('Node.js rest-api: open browser at http://localhost:${PORT}'); 20 | trace('Stop node.js : CTRL + c'); 21 | 22 | // all environments 23 | app.set('port', PORT); 24 | // app.use(new Favicon(Node.__dirname + '/public/favicon.ico')); 25 | // app.use(new Morgan('dev')); 26 | // app.use(BodyParser.json()); // support json encoded bodies 27 | // app.use(BodyParser.urlencoded({extended: true})); // support encoded bodies 28 | // app.use(new Static(Path.join(Node.__dirname, 'public'))); 29 | 30 | // Routes 31 | Routes.init(router); 32 | 33 | // app.use(function(req, res, next) { 34 | // res.status(404).send('404'); 35 | // // res.status(404).send(output); 36 | // }); 37 | 38 | app.listen(app.get('port'), function() { 39 | trace('Express server listening on port ' + app.get('port')); 40 | }); 41 | } 42 | 43 | static public function main() { 44 | var main = new Main(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /docs/07restapi/code/src/Routes.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | // import express_serve_static_core.Router; 4 | // import js.npm.Express; 5 | // import js.npm.express.*; 6 | class Routes { 7 | public static function init(app:express_serve_static_core.Router):Void { 8 | app.get('/', Controller.index); 9 | app.get('/musician/:name', Controller.findByName); 10 | app.get('/musicians', Controller.findAll); 11 | app.get('/musicians/:id', Controller.findById); 12 | app.post('/musicians', Controller.add); 13 | // app.put('/musicians/:id', Controller.update); 14 | // app.delete('/musicians/:id', Controller.delete); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /docs/07restapi/code/src/js/npm/express/Logger.hx: -------------------------------------------------------------------------------- 1 | package js.npm.express; 2 | 3 | 4 | typedef LogOptions = { 5 | @:optional var immediate : Bool; 6 | @:optional var skip : Request->Response-> Bool; 7 | @:optional var stream : Dynamic; 8 | } 9 | 10 | /** 11 | * Logger 12 | * @author TiagoLr 13 | */ 14 | extern class Logger 15 | implements npm.Package.Require < "morgan", "*" > #if !haxe3,#end 16 | implements Middleware 17 | { 18 | public function new(?format:String, ?options:LogOptions) : Void; 19 | 20 | } -------------------------------------------------------------------------------- /docs/07restapi/code/test.md: -------------------------------------------------------------------------------- 1 | ## tl;dr 2 | 3 | ``` 4 | # install 5 | npm install dts2hx --save-dev 6 | npm install express --save 7 | npm install @types/express --save 8 | 9 | # run dts2hx 10 | npx dts2hx express 11 | 12 | # install hxnodejs 13 | haxelib install hxnodejs 14 | 15 | # don't forget to add `--library express` to your build 16 | ``` 17 | 18 | ## install packages 19 | 20 | ``` 21 | npm install dts2hx --save-dev 22 | npm install express --save 23 | npm install @types/express --save 24 | ``` 25 | 26 | ## run dts2hx 27 | 28 | ``` 29 | // doesn't work because the express ts files are not in the repo 30 | npx dts2hx express 31 | ``` 32 | 33 | works 34 | 35 | ``` 36 | npx dts2hx @types/express 37 | ``` 38 | 39 | ## add lib 40 | 41 | build.hxml 42 | 43 | ``` 44 | --library express 45 | ``` 46 | 47 | ## install hxnodejs in .haxelib folder 48 | 49 | ```bash 50 | haxelib install hxnodejs 51 | ``` 52 | -------------------------------------------------------------------------------- /docs/07restapi/example.md: -------------------------------------------------------------------------------- 1 | # Example basic website 2 | 3 | We start with a simple example from the ExpressJS homepage: 4 | 5 | 6 | ## How to start 7 | 8 | Create a folder named **foobar** (please use a better name; any name will do) and create folders **bin** and **src**. 9 | See example below: 10 | 11 | ``` 12 | + foobar 13 | + bin 14 | + src 15 | - MainBasic.hx 16 | - javascript.hxml 17 | ``` 18 | 19 | ## Install 20 | 21 | Check out [the installation](installation.md). 22 | 23 | ## The MainBasic.hx 24 | 25 | Open your favorite editor, copy/paste the code and save it in the `src` folder. 26 | 27 | ```haxe 28 | package ; 29 | import js.Node; 30 | import js.npm.Express; 31 | class MainBasic 32 | { 33 | private var server:Dynamic; 34 | function new() 35 | { 36 | trace("Express website (Basic): open browser at http://localhost:3000"); 37 | trace("stop node : CTRL + c"); 38 | 39 | var app : Express = new Express(); 40 | 41 | app.get('/', function (req, res) { 42 | res.send('Hello World!'); 43 | }); 44 | 45 | server = app.listen(3000, function () 46 | { 47 | var host = server.address().address; 48 | var port = server.address().port; 49 | trace( 'Example app listening at http://$host:$port'); // ???? http://:::3000 50 | }); 51 | 52 | } 53 | 54 | static public function main() 55 | { 56 | var main = new MainBasic(); 57 | } 58 | } 59 | ``` 60 | 61 | ## The Haxe build file, javascript.hxml 62 | 63 | Copy and past the following lines in a document named `javascript.hxml` 64 | This is the short version, you want to chech out the full version open this [file](/code/javascript.hxml); 65 | 66 | ``` 67 | # // javascript.hxml 68 | -lib js-kit 69 | -lib hxnodejs 70 | -cp src 71 | -main MainBasic 72 | -js bin/example.js 73 | -cmd cd bin 74 | -cmd node example.js 75 | ``` 76 | 77 | ## Build js with Haxe and start Node 78 | 79 | To finish and see what we have, build the file and see the result 80 | 81 | 1. Open your terminal 82 | 2. `cd ` to the correct folder where you have saved the `javascript.hxml` 83 | 3. type `haxe javascript.hxml` 84 | 4. press enter 85 | 86 | --- 87 | -------------------------------------------------------------------------------- /docs/07restapi/installation.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | 3 | Read the how to install **Node.js** and **Haxe** [here](../haxenode/download.md). 4 | Once you have installed **Haxe** you will automatically installed `haxelib`. 5 | The same goes for **Node.js**, you will have automatically installed `NPM`. 6 | 7 | ## Install Node.js externs for Haxe 8 | 9 | Install the [official Haxe node.js externs](https://github.com/HaxeFoundation/hxnodejs) lib via [haxelib](http://lib.haxe.org/p/hxnodejs/). 10 | Haxelib is automatically installed when installing Haxe and you can see it as a sort of NPM. 11 | 12 | ```bash 13 | haxelib install hxnodejs 14 | ``` 15 | 16 | In this tutorial I use js-kit externs, there are more ways to get externs but the js-kit has a lot so it's more a one stop shop thing! 17 | 18 | ```bash 19 | haxelib git js-kit https://github.com/clemos/haxe-js-kit.git haxelib 20 | ``` 21 | 22 | ## Install express via NPM : 23 | 24 | [Express](https://github.com/strongloop/express) 25 | 26 | > Fast, un-opinionated, minimalist web framework for node. 27 | 28 | ``` 29 | npm install express 30 | ``` 31 | 32 | ## Install for the more Intermediate and Advance example 33 | 34 | Express uses more dependencies: 35 | 36 | ``` 37 | npm install morgan 38 | npm install body-parser 39 | npm install serve-favicon 40 | npm install express 41 | ``` 42 | 43 | --- 44 | 45 | ## Install all modules with NPM via package.json 46 | 47 | If you have a package.json file in your directory and you run npm install, then npm will look at the dependencies that are listed in that file and download the latest versions satisfying semver rules for all of those. 48 | 49 | To do so, `cd` to the correct folder ( `cd path/to/correct/folder/with/package/dot/json/` ) 50 | 51 | ``` 52 | npm install 53 | ``` 54 | 55 | This will install everything in `node_modules`. 56 | -------------------------------------------------------------------------------- /docs/09slackbot/about.md: -------------------------------------------------------------------------------- 1 | # About slack 2 | 3 | People who have never heart of [slack](https://slack.com/) should visit and read about it. 4 | 5 | And you should probably skip this tutorial, because... well you need a slack channel 6 | 7 | > 8 | 9 | ### Welcome to the Slack API 10 | 11 | > The Slack APIs allow you to integrate complex services with Slack to go beyond the integration we provide out of the box. 12 | 13 | You can read the rest [here](https://api.slack.com/) 14 | 15 | ### About slackbot 16 | 17 | > 18 | 19 | ### Send data into Slack in real-time. 20 | 21 | > Incoming Webhooks are a simple way to post messages from external sources into Slack. They make use of normal HTTP requests with a JSON payload, which includes the message text and some options. Message Attachments can also be used in Incoming Webhooks to display richly-formatted messages that stand out from regular chat messages. 22 | 23 | [https://api.slack.com/incoming-webhooks](https://api.slack.com/incoming-webhooks) 24 | -------------------------------------------------------------------------------- /docs/09slackbot/code/bin/example.js: -------------------------------------------------------------------------------- 1 | // Generated by Haxe 3.4.4 2 | if (process.version < "v4.0.0") console.warn("Module " + (typeof(module) == "undefined" ? "" : module.filename) + " requires node.js version 4.0.0 or higher"); 3 | (function () { "use strict"; 4 | var Main = function() { 5 | console.log("Slack Incoming Webhooks Example"); 6 | var webhookURL = "https://hooks.slack.com/services/USE/YOUR/CODE/HERE"; 7 | var slack1 = new slack_Webhook(webhookURL); 8 | var payload = { text : "another test", icon_emoji : ":8ball:", username : "3cpo"}; 9 | slack1.send(payload); 10 | }; 11 | Main.main = function() { 12 | var main = new Main(); 13 | }; 14 | var haxe_io_Bytes = function() { }; 15 | var js_node_buffer_Buffer = require("buffer").Buffer; 16 | var slack_Webhook = function(url) { 17 | this._url = url; 18 | }; 19 | slack_Webhook.prototype = { 20 | send: function(payload) { 21 | var request = require("request"); 22 | var option = { url : this._url, body : JSON.stringify(payload)}; 23 | request.post(option,function(error,response,body) { 24 | if(!error) { 25 | console.log("body: " + body); 26 | } else { 27 | console.log("We’ve encountered an error: " + (error == null ? "null" : "" + error)); 28 | } 29 | }); 30 | } 31 | }; 32 | Main.main(); 33 | })(); 34 | -------------------------------------------------------------------------------- /docs/09slackbot/code/build copy.hxml: -------------------------------------------------------------------------------- 1 | # -lib js-kit 2 | --library hxnodejs 3 | --class-path src 4 | --main Main 5 | --js bin/example.js 6 | --dce full 7 | -D js-es=6 8 | 9 | --next 10 | 11 | # Use terminal command to start Node.js! 12 | --cmd echo "use: 'node bin/example.js' to check script " 13 | --cmd cd bin 14 | --cmd node example.js 15 | --cmd echo exit -------------------------------------------------------------------------------- /docs/09slackbot/code/build.hxml: -------------------------------------------------------------------------------- 1 | -lib js-kit 2 | -lib hxnodejs 3 | -cp src 4 | -main Main 5 | -js bin/example.js 6 | -dce full -------------------------------------------------------------------------------- /docs/09slackbot/code/javascript.hxml: -------------------------------------------------------------------------------- 1 | # libs used in project 2 | -lib js-kit 3 | -lib hxnodejs 4 | 5 | # integrate files to classpath 6 | -cp src 7 | 8 | # this class wil be used as entry point for your app. 9 | -main Main 10 | 11 | # JavaScript target 12 | -js bin/example.js 13 | 14 | # You can use -D source-map-content (requires Haxe 3.1+) to have the .hx 15 | # files directly embedded into the map file, this way you only have to 16 | # upload it, and it will be always in sync with the compiled .js even if 17 | # you modify your .hx files. 18 | # -D source-map-content 19 | 20 | # Generate source map and add debug information 21 | # -debug 22 | 23 | # dead code elimination : remove unused code 24 | # "-dce no" : do not remove unused code 25 | # "-dce std" : remove unused code in the std lib (default) 26 | # "-dce full" : remove all unused code 27 | -dce full 28 | 29 | # This is very cool, but not necessary for this project, you can create a package.json with the correct depencicies (https://github.com/clemos/haxe-js-kit# exporting-your-project-dependencies) 30 | --macro npm.Package.export("package.json") 31 | 32 | # Use terminal command to start Node.js! 33 | -cmd node bin/example.js -------------------------------------------------------------------------------- /docs/09slackbot/code/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "request": "^2.55.0", 4 | "cheerio": "^0.19.0" 5 | } 6 | } -------------------------------------------------------------------------------- /docs/09slackbot/code/src/Main.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | import slack.*; 4 | 5 | /** 6 | * @author Matthijs Kamstra aka [mck] 7 | */ 8 | class Main { 9 | function new() { 10 | trace("Slack Incoming Webhooks Example"); 11 | 12 | var webhookURL = "https://hooks.slack.com/services/USE/YOUR/CODE/HERE"; 13 | var slack = new Webhook(webhookURL); 14 | 15 | var payload:Webhook.Payload = { 16 | text: "another test", 17 | icon_emoji: ":8ball:", 18 | username: "3cpo" 19 | }; 20 | slack.send(payload); 21 | } 22 | 23 | static public function main() { 24 | var main = new Main(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /docs/09slackbot/code/src/slack/Webhook.hx: -------------------------------------------------------------------------------- 1 | package slack; 2 | 3 | import js.Node; 4 | import js.npm.Request; 5 | 6 | class Webhook { 7 | // source: https://api.slack.com/incoming-webhooks 8 | private var _url:String; 9 | 10 | public function new(url:String) { 11 | _url = url; 12 | } 13 | 14 | public function send(payload:Payload):Void { 15 | var request:Request = Request.construct(); 16 | 17 | var option = { 18 | url: _url, 19 | body: haxe.Json.stringify(payload) 20 | }; 21 | 22 | request.post(option, function(error, response, body) { 23 | if (!error) { 24 | trace("body: " + body); 25 | } else { 26 | trace("We’ve encountered an error: " + error); 27 | } 28 | }); 29 | } 30 | } 31 | 32 | typedef Payload = { 33 | var text:String; 34 | @:optional var username:String; 35 | @:optional var channel:String; 36 | @:optional var icon_url:String; 37 | @:optional var icon_emoji:String; 38 | // @:optional var attachments:String; 39 | @:optional var unfurl_links:String; 40 | @:optional var link_names:String; 41 | } 42 | -------------------------------------------------------------------------------- /docs/09slackbot/example.md: -------------------------------------------------------------------------------- 1 | # Example incoming webhooks 2 | 3 | https://api.slack.com/incoming-webhooks 4 | 5 | ## How to start 6 | 7 | Create a folder named **foobar** (please use a better name; any name will do) and create folders **bin** and **src**. 8 | See example below: 9 | 10 | ``` 11 | + foobar 12 | + bin 13 | + src 14 | + slack 15 | - Webhook.hx 16 | - Main.hx 17 | - javascript.hxml 18 | ``` 19 | 20 | ## Install 21 | 22 | check out [the installation](installation.md). 23 | 24 | ## The Main.hx 25 | 26 | Open your favorite editor, copy/paste the code and save it in the `src` folder. 27 | 28 | ```haxe 29 | package; 30 | 31 | import slack.*; 32 | 33 | class Main { 34 | function new() { 35 | trace("Slack Incoming Webhooks Example"); 36 | 37 | var webhookURL = "https://hooks.slack.com/services/USE/YOUR/CODE/HERE"; 38 | var slack = new Webhook(webhookURL); 39 | 40 | var payload:Webhook.Payload = { 41 | text: "another test", 42 | icon_emoji: ":8ball:", 43 | username: "3cpo" 44 | }; 45 | slack.send(payload); 46 | } 47 | 48 | static public function main() { 49 | var main = new Main(); 50 | } 51 | } 52 | ``` 53 | 54 | Create a folder named `slack` into the `src` folder 55 | 56 | Copy and save document in folder `src/slack` with the name `Webhook.hx` 57 | 58 | ```haxe 59 | package slack; 60 | 61 | import js.Node; 62 | import js.npm.Request; 63 | 64 | class Webhook { 65 | // source: https://api.slack.com/incoming-webhooks 66 | private var _url:String; 67 | 68 | public function new(url:String) { 69 | _url = url; 70 | } 71 | 72 | public function send(payload:Payload):Void { 73 | var request:Request = Request.construct(); 74 | 75 | var option = { 76 | url: _url, 77 | body: haxe.Json.stringify(payload) 78 | }; 79 | 80 | request.post(option, function(error, response, body) { 81 | if (!error) { 82 | trace("body: " + body); 83 | } else { 84 | trace("We’ve encountered an error: " + error); 85 | } 86 | }); 87 | } 88 | } 89 | 90 | typedef Payload = { 91 | var text:String; 92 | @:optional var username:String; 93 | @:optional var channel:String; 94 | @:optional var icon_url:String; 95 | @:optional var icon_emoji:String; 96 | // @:optional var attachments:String; 97 | @:optional var unfurl_links:String; 98 | @:optional var link_names:String; 99 | } 100 | 101 | 102 | ``` 103 | 104 | ## The Haxe build file, javascript.hxml 105 | 106 | Copy and past the following lines in a document named `javascript.hxml` 107 | This is the short version, you want to chech out the full version open this [file](/code/javascript.hxml); 108 | 109 | ``` 110 | # // javascript.hxml 111 | -lib js-kit 112 | -lib hxnodejs 113 | -cp src 114 | -main Main 115 | -js bin/example.js 116 | -cmd node bin/example.js 117 | ``` 118 | 119 | ## Build js with Haxe and start Node 120 | 121 | To finish and see what we have, build the file and see the result 122 | 123 | 1. Open your terminal 124 | 2. `cd ` to the correct folder where you have saved the `javascript.hxml` 125 | 3. type `haxe javascript.hxml` 126 | 4. press enter 127 | -------------------------------------------------------------------------------- /docs/09slackbot/installation.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | 3 | Read the how to install **Node.js** and **Haxe** [here](../haxenode/download.md). 4 | Once you have installed **Haxe** you will automatically installed `haxelib`. 5 | The same goes for **Node.js**, you will have automatically installed `NPM`. 6 | 7 | ## Install Node.js externs for Haxe 8 | 9 | Install the [official Haxe node.js externs](https://github.com/HaxeFoundation/hxnodejs) lib via [haxelib](http://lib.haxe.org/p/hxnodejs/). 10 | Haxelib is automatically installed when installing Haxe and you can see it as a sort of NPM. 11 | 12 | ```bash 13 | haxelib install hxnodejs 14 | ``` 15 | 16 | In this tutorial I use js-kit externs, there are more ways to get externs but the js-kit has a lot so it's more a one stop shop thing! 17 | 18 | ```bash 19 | haxelib git js-kit https://github.com/clemos/haxe-js-kit.git haxelib 20 | 21 | ``` 22 | 23 | ## Install request via NPM : 24 | 25 | [Request](https://github.com/request/request) 26 | 27 | > Simplified HTTP request client. 28 | 29 | ``` 30 | npm install request 31 | ``` 32 | 33 | ## Install all modules with NPM via package.json 34 | 35 | If you have a package.json file in your directory and you run npm install, then npm will look at the dependencies that are listed in that file and download the latest versions satisfying semver rules for all of those. 36 | 37 | To do so, `cd` to the correct folder ( `cd path/to/correct/folder/with/package/dot/json/` ) 38 | 39 | ``` 40 | npm install 41 | ``` 42 | 43 | This will install everything in `node_modules`. 44 | -------------------------------------------------------------------------------- /docs/10scraping/about.md: -------------------------------------------------------------------------------- 1 | # About scraping 2 | 3 | > Web scraping is the process of programmatically retrieving information from the Internet. As the volume of data on the web has increased, this practice has become increasingly widespread. And a number of powerful services have emerged to simplify it. 4 | 5 | 6 | > Web scraping (web harvesting or web data extraction) is a computer software technique of extracting information from websites. 7 | 8 | From [wikipedia](https://en.wikipedia.org/wiki/Web_scraping) 9 | 10 | Okay another explanation: 11 | > Web Scraping refers to an application that processes the HTML of a Web page to extract data for manipulation such as converting the Web page to another format (i.e. HTML to WML). Web Scraping scripts and applications will simulate a person viewing a Web site with a browser. With these scripts you can connect to a Web page and request a page, as a browser would do. The Web server will send back the page which you can then manipulate or extract specific information from. 12 | 13 | From [webopedia](http://www.webopedia.com/TERM/W/Web_Scraping.html) 14 | 15 | ## About this tutorial 16 | 17 | Node.js is an easy way to do some web-scraping. 18 | But there are not a lot of tutorials about Haxe and Node.js, so there are none about Haxe/Node.js and scraping. 19 | Not a problem, lets translate a existing tutorial to Haxe! 20 | 21 | This is the Haxe version of the tutorial posted on [smashmagazine](http://www.smashingmagazine.com/2015/04/web-scraping-with-nodejs/) 22 | 23 | -------------------------------------------------------------------------------- /docs/10scraping/code/bin/example.js: -------------------------------------------------------------------------------- 1 | // Generated by Haxe 3.4.4 2 | if (process.version < "v4.0.0") console.warn("Module " + (typeof(module) == "undefined" ? "" : module.filename) + " requires node.js version 4.0.0 or higher"); 3 | (function () { "use strict"; 4 | var Main = function() { 5 | console.log("Node.js Scraping Example"); 6 | var request = require("request"); 7 | var url = "http://www.wunderground.com/cgi-bin/findweather/getForecast?&query=02888"; 8 | request.get(url,function(error,response,body) { 9 | if(!error) { 10 | var _cheerio = js_npm_Cheerio.load(body); 11 | var temperature = _cheerio("[data-variable='temperature'] .wx-value").html(); 12 | console.log("It’s " + temperature + " degrees Celsius."); 13 | } else { 14 | console.log("We’ve encountered an error: " + (error == null ? "null" : "" + error)); 15 | } 16 | }); 17 | }; 18 | Main.main = function() { 19 | var main = new Main(); 20 | }; 21 | var haxe_io_Bytes = function() { }; 22 | var js_node_buffer_Buffer = require("buffer").Buffer; 23 | var js_npm_Cheerio = require("cheerio"); 24 | Main.main(); 25 | })(); 26 | -------------------------------------------------------------------------------- /docs/10scraping/code/build copy.hxml: -------------------------------------------------------------------------------- 1 | # -lib js-kit 2 | --library hxnodejs 3 | --class-path src 4 | --main Main 5 | --js bin/example.js 6 | --dce full 7 | -D js-es=6 8 | 9 | --next 10 | 11 | # Use terminal command to start Node.js! 12 | --cmd echo "use: 'node bin/example.js' to check script " 13 | --cmd cd bin 14 | --cmd node example.js 15 | --cmd echo exit -------------------------------------------------------------------------------- /docs/10scraping/code/build.hxml: -------------------------------------------------------------------------------- 1 | -lib js-kit 2 | -lib hxnodejs 3 | -cp src 4 | -main Main 5 | -js bin/example.js 6 | -dce full -------------------------------------------------------------------------------- /docs/10scraping/code/javascript.hxml: -------------------------------------------------------------------------------- 1 | # libs used in project 2 | -lib js-kit 3 | -lib hxnodejs 4 | 5 | # integrate files to classpath 6 | -cp src 7 | 8 | # this class wil be used as entry point for your app. 9 | -main Main 10 | 11 | # JavaScript target 12 | -js bin/example.js 13 | 14 | # You can use -D source-map-content (requires Haxe 3.1+) to have the .hx 15 | # files directly embedded into the map file, this way you only have to 16 | # upload it, and it will be always in sync with the compiled .js even if 17 | # you modify your .hx files. 18 | # -D source-map-content 19 | 20 | # Generate source map and add debug information 21 | # -debug 22 | 23 | # dead code elimination : remove unused code 24 | # "-dce no" : do not remove unused code 25 | # "-dce std" : remove unused code in the std lib (default) 26 | # "-dce full" : remove all unused code 27 | -dce full 28 | 29 | # This is very cool, but not necessary for this project, you can create a package.json with the correct depencicies (https://github.com/clemos/haxe-js-kit# exporting-your-project-dependencies) 30 | --macro npm.Package.export("package.json") 31 | 32 | # Use terminal command to start Node.js! 33 | -cmd node bin/example.js -------------------------------------------------------------------------------- /docs/10scraping/code/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "request": "^2.55.0", 4 | "cheerio": "^0.19.0" 5 | } 6 | } -------------------------------------------------------------------------------- /docs/10scraping/code/src/Main.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | import js.Node; 4 | import js.npm.Cheerio; 5 | import js.npm.Request; 6 | 7 | /** 8 | * @author Matthijs Kamstra aka [mck] 9 | */ 10 | class Main { 11 | function new() { 12 | trace("Node.js Scraping Example"); 13 | 14 | var request:Request = Request.construct(); 15 | var url = "http://www.wunderground.com/cgi-bin/findweather/getForecast?&query=02888"; 16 | 17 | request.get(url, function(error, response, body) { 18 | if (!error) { 19 | // Variables names staring with a dollar are not allowed, that is why I changed $ into _cheerio 20 | var _cheerio = Cheerio.load(body); 21 | var temperature = _cheerio("[data-variable='temperature'] .wx-value").html(); 22 | 23 | trace("It’s " + temperature + " degrees Celsius."); 24 | } else { 25 | trace("We’ve encountered an error: " + error); 26 | } 27 | }); 28 | } 29 | 30 | static public function main() { 31 | var main = new Main(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /docs/10scraping/installation.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | 3 | Read the how to install **Node.js** and **Haxe** [here](../haxenode/download.md). 4 | Once you have installed **Haxe** you will automatically installed `haxelib`. 5 | The same goes for **Node.js**, you will have automatically installed `NPM`. 6 | 7 | ## Install Node.js externs for Haxe 8 | 9 | Install the [official Haxe node.js externs](https://github.com/HaxeFoundation/hxnodejs) lib via [haxelib](http://lib.haxe.org/p/hxnodejs/). 10 | Haxelib is automatically installed when installing Haxe and you can see it as a sort of NPM. 11 | 12 | ```bash 13 | haxelib install hxnodejs 14 | ``` 15 | 16 | In this tutorial I use js-kit externs, there are more ways to get externs but the js-kit has a lot so it's more a one stop shop thing! 17 | 18 | ```bash 19 | haxelib git js-kit https://github.com/clemos/haxe-js-kit.git haxelib 20 | 21 | ``` 22 | 23 | ## Install cheerio via NPM: 24 | 25 | [Cheerio](http://cheeriojs.github.io/cheerio/) 26 | 27 | > Fast, flexible, and lean implementation of core jQuery designed specifically for the server. 28 | 29 | ``` 30 | npm install cheerio 31 | ``` 32 | 33 | ## Install request via NPM: 34 | 35 | [Request](https://github.com/request/request) 36 | 37 | > Simplified HTTP request client. 38 | 39 | ``` 40 | npm install request 41 | ``` 42 | 43 | ## Install all modules with NPM via package.json 44 | 45 | If you have a package.json file in your directory and you run npm install, then npm will look at the dependencies that are listed in that file and download the latest versions satisfying semver rules for all of those. 46 | 47 | To do so, `cd` to the correct folder ( `cd path/to/correct/folder/with/package/dot/json/` ) 48 | 49 | ``` 50 | npm install 51 | ``` 52 | 53 | This will install everything in `node_modules`. 54 | -------------------------------------------------------------------------------- /docs/11automation/TODO.md: -------------------------------------------------------------------------------- 1 | 2 | ## Install the grunt plugin grunt-nodemon 3 | 4 | > Grunt task to run nodemon 5 | 6 | [grunt-nodemon](https://github.com/ChrisWren/grunt-nodemon) 7 | The sad thing is, that this project is not actively maintainded. 8 | So I hope someone will pick it up again... 9 | But for now it seems to work so enjoy! 10 | 11 | ``` 12 | npm install grunt-nodemon --save-dev 13 | ``` 14 | -------------------------------------------------------------------------------- /docs/11automation/code/GruntFile.js: -------------------------------------------------------------------------------- 1 | module.exports = function(grunt) { 2 | 3 | // Project configuration. 4 | grunt.initConfig({ 5 | pkg: grunt.file.readJSON('package.json'), 6 | 7 | exec: { 8 | haxe: 'haxe javascript.hxml' 9 | }, 10 | 11 | watch: { 12 | scripts: { 13 | files: ['**/*.md','**/*.hx'], 14 | tasks: ['exec'], 15 | options: { 16 | livereload: true 17 | }, 18 | }, 19 | } 20 | // ,nodemon: { 21 | // dev: { 22 | // script: 'bin/example.js' 23 | // } 24 | // } 25 | 26 | }); 27 | 28 | grunt.loadNpmTasks('grunt-contrib-watch'); 29 | grunt.loadNpmTasks('grunt-exec'); 30 | // grunt.loadNpmTasks('grunt-nodemon'); 31 | 32 | grunt.registerTask('default', ['exec']); 33 | 34 | }; -------------------------------------------------------------------------------- /docs/11automation/code/build.hxml: -------------------------------------------------------------------------------- 1 | -lib js-kit 2 | -lib hxnodejs 3 | -cp src 4 | -main Main 5 | -js bin/example.js 6 | -dce full -------------------------------------------------------------------------------- /docs/11automation/code/javascript.hxml: -------------------------------------------------------------------------------- 1 | # libs used in project 2 | -lib js-kit 3 | -lib hxnodejs 4 | 5 | # integrate files to classpath 6 | -cp src 7 | 8 | # this class wil be used as entry point for your app. 9 | -main Main 10 | 11 | # JavaScript target 12 | -js bin/example.js 13 | 14 | # You can use -D source-map-content (requires Haxe 3.1+) to have the .hx 15 | # files directly embedded into the map file, this way you only have to 16 | # upload it, and it will be always in sync with the compiled .js even if 17 | # you modify your .hx files. 18 | # -D source-map-content 19 | 20 | # Generate source map and add debug information 21 | # -debug 22 | 23 | # dead code elimination : remove unused code 24 | # "-dce no" : do not remove unused code 25 | # "-dce std" : remove unused code in the std lib (default) 26 | # "-dce full" : remove all unused code 27 | -dce full 28 | 29 | # This is very cool, but not necessary for this project, you can create a package.json with the correct depencicies (https://github.com/clemos/haxe-js-kit# exporting-your-project-dependencies) 30 | --macro npm.Package.export("package.json") -------------------------------------------------------------------------------- /docs/11automation/code/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "license": "MIT", 3 | "description": "Create a website with express", 4 | "author": "Matthijs Kamstra aka [mck]", 5 | "private": true, 6 | "dependencies": { 7 | 8 | }, 9 | "devDependencies": { 10 | "grunt": "~0.4.1", 11 | "grunt-contrib-watch": "~0.5.3", 12 | "grunt-exec" : "~0.4.6", 13 | "grunt-nodemon" : "*" 14 | } 15 | } -------------------------------------------------------------------------------- /docs/11automation/code/src/Main.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | import js.Node; 4 | import js.node.Http; 5 | import js.node.http.ServerResponse; 6 | import js.node.http.IncomingMessage; 7 | 8 | /** 9 | * @author Matthijs Kamstra aka [mck] 10 | */ 11 | class Main { 12 | function new() { 13 | trace("Node.js Hello World Example"); 14 | 15 | Http.createServer(function(request:IncomingMessage, response:ServerResponse):Void { 16 | response.writeHead(200, {'Content-Type': 'text/plain'}); 17 | response.end('Hello World\n' + Date.now()); 18 | }).listen(8080); 19 | 20 | trace('Server started: '); 21 | trace('open http://localhost:8080'); 22 | trace('Close Node with CTRL + C'); 23 | } 24 | 25 | static public function main() { 26 | var main = new Main(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /docs/11automation/code2/build copy.hxml: -------------------------------------------------------------------------------- 1 | # -lib js-kit 2 | --library hxnodejs 3 | --class-path src 4 | --main Main 5 | --js bin/example.js 6 | --dce full 7 | -D js-es=6 8 | 9 | --next 10 | 11 | # Use terminal command to start Node.js! 12 | --cmd echo "use: 'node bin/example.js' to check script " 13 | --cmd cd bin 14 | --cmd node example.js 15 | --cmd echo exit -------------------------------------------------------------------------------- /docs/11automation/code2/build.hxml: -------------------------------------------------------------------------------- 1 | -lib js-kit 2 | -lib hxnodejs 3 | -cp src 4 | -main Main 5 | -js bin/example.js 6 | -dce full -------------------------------------------------------------------------------- /docs/11automation/code2/javascript.hxml: -------------------------------------------------------------------------------- 1 | # libs used in project 2 | -lib js-kit 3 | -lib hxnodejs 4 | 5 | # integrate files to classpath 6 | -cp src 7 | 8 | # this class wil be used as entry point for your app. 9 | -main Main 10 | 11 | # JavaScript target 12 | -js bin/example.js 13 | 14 | # You can use -D source-map-content (requires Haxe 3.1+) to have the .hx 15 | # files directly embedded into the map file, this way you only have to 16 | # upload it, and it will be always in sync with the compiled .js even if 17 | # you modify your .hx files. 18 | -D source-map-content 19 | 20 | # Generate source map and add debug information 21 | -debug 22 | 23 | # dead code elimination : remove unused code 24 | # "-dce no" : do not remove unused code 25 | # "-dce std" : remove unused code in the std lib (default) 26 | # "-dce full" : remove all unused code 27 | -dce full 28 | 29 | # This is very cool, but not necessary for this project, you can create a package.json with the correct depencicies (https://github.com/clemos/haxe-js-kit# exporting-your-project-dependencies) 30 | --macro npm.Package.export("package.json") -------------------------------------------------------------------------------- /docs/11automation/code2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "license": "MIT", 3 | "description": "Create a website with express", 4 | "author": "Matthijs Kamstra aka [mck]", 5 | "private": true, 6 | "scripts": { 7 | "prewatch": "haxe javascript.hxml", 8 | "watch": "onchange '**/*.hx' '**/*.md' -v -- haxe javascript.hxml & nodemon bin/example.js & livereload bin/" 9 | }, 10 | "devDependencies": { 11 | "livereload": "^0.3.7", 12 | "nodemon": "^1.11.0", 13 | "onchange": "^2.0.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /docs/11automation/code2/src/Main.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | import js.Node; 4 | import js.node.Http; 5 | import js.node.http.ServerResponse; 6 | import js.node.http.IncomingMessage; 7 | 8 | /** 9 | * @author Matthijs Kamstra aka [mck] 10 | */ 11 | class Main { 12 | function new() { 13 | trace("Node.js Hello World Example"); 14 | 15 | Http.createServer(function(request:IncomingMessage, response:ServerResponse):Void { 16 | response.writeHead(200, {'Content-Type': 'text/html'}); 17 | 18 | #if debug 19 | response.write(''); 20 | #end 21 | 22 | response.end('Hello World
' + Date.now()); 23 | }).listen(8080); 24 | 25 | trace('Server started: '); 26 | trace('open http://localhost:8080'); 27 | trace('Close Node with CTRL + C'); 28 | } 29 | 30 | static public function main() { 31 | var main = new Main(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /docs/11automation/installation.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | 3 | Read the how to install **Node.js** and **Haxe** [here](../haxenode/download.md). 4 | Once you have installed **Haxe** you will automatically installed `haxelib`. 5 | The same goes for **Node.js**, you will have automatically installed `NPM`. 6 | 7 | This example is not about Node.js per se, but we use an node example to explain the workings of automation. 8 | And that's why we need to install js-kit. 9 | 10 | ## Install Node.js externs for Haxe 11 | 12 | Install the [official Haxe node.js externs](https://github.com/HaxeFoundation/hxnodejs) lib via [haxelib](http://lib.haxe.org/p/hxnodejs/). 13 | Haxelib is automatically installed when installing Haxe and you can see it as a sort of NPM. 14 | 15 | ```bash 16 | haxelib install hxnodejs 17 | ``` 18 | 19 | In this tutorial I use js-kit externs, there are more ways to get externs but the js-kit has a lot so it's more a one stop shop thing! 20 | 21 | ```bash 22 | haxelib git js-kit https://github.com/clemos/haxe-js-kit.git haxelib 23 | 24 | ``` 25 | 26 | ## Install Grunt with NPM 27 | 28 | You should read more about Grunt [here](http://gruntjs.com/getting-started), it will explain the workings of Grunt. 29 | But the quick-and-dirty install is the line below in your terminal. 30 | 31 | ``` 32 | npm install -g grunt-cli 33 | ``` 34 | 35 | ## Install Nodemon with NPM 36 | 37 | To restart node we will use [Nodemon](http://nodemon.io/). 38 | 39 | > Nodemon is a utility that will monitor for any changes in your source and automatically restart your server. Perfect for development. Install it using npm. 40 | > 41 | > Just use nodemon instead of node to run your code, and now your process will automatically restart when your code changes. 42 | 43 | ``` 44 | npm install -g nodemon 45 | ``` 46 | -------------------------------------------------------------------------------- /docs/11automation/installation2.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | 3 | Read the how to install **Node.js** and **Haxe** [here](../haxenode/download.md). 4 | Once you have installed **Haxe** you will automatically installed `haxelib`. 5 | The same goes for **Node.js**, you will have automatically installed `NPM`. 6 | 7 | This example is not about Node.js per se, but we use an node example to explain the workings of automation. 8 | And that's why we need to install js-kit. 9 | 10 | ## Install Node.js externs for Haxe 11 | 12 | Install the [official Haxe node.js externs](https://github.com/HaxeFoundation/hxnodejs) lib via [haxelib](http://lib.haxe.org/p/hxnodejs/). 13 | Haxelib is automaticly installed when installing Haxe and you can see it as a sort of NPM. 14 | 15 | ```bash 16 | haxelib install hxnodejs 17 | ``` 18 | 19 | In this tutorial I use mostly js-kit externs, there are more ways to get externs but the js-kit has a lot so it's more a one stop shop thing! 20 | 21 | ```bash 22 | haxelib git js-kit https://github.com/clemos/haxe-js-kit.git haxelib 23 | 24 | ``` 25 | -------------------------------------------------------------------------------- /docs/12socket/about.md: -------------------------------------------------------------------------------- 1 | # About Socket.io 2 | 3 | This chapter is a Haxe translation of 4 | 5 | ### What we primarily use are sockets. 6 | 7 | Socket.IO enables real-time bidirectional event-based communication. 8 | It works on every platform, browser or device, focusing equally on reliability and speed. 9 | 10 | _source: _ 11 | 12 | 13 | This example is a combination of 14 | 15 | 1. Express (read more about that [here](../05website/exampleAdvanced.md)) 16 | 2. Automation (read more about that [here](../11automation/example2.md) 17 | 3. Jade - node template system (I have not written about that, check this [site](http://jade-lang.com/)) 18 | 4. JQuery (you can find info about that [here](http://matthijskamstra.github.io/haxejs/01jquery/example.html)) 19 | 5. Vanilla js (you can find more info [here](http://matthijskamstra.github.io/haxejs/03vanillajs/example.html)) 20 | 21 | 22 | 23 | 24 | 25 | I have split the files in two different files, but you could combine them. 26 | 27 | 28 | To do this add `-D client` to the `.hxml` : 29 | ``` 30 | # add the conditinal to the client code: "#if client ... #end" 31 | -D client 32 | 33 | # add the conditinal to the server code: "#if server ... #end" 34 | -D server 35 | ``` 36 | 37 | 38 | ---- 39 | -------------------------------------------------------------------------------- /docs/12socket/bug.txt: -------------------------------------------------------------------------------- 1 | if (typeof process !== 'undefined' ) if (process.version < "v4.0.0") console.warn("Module " + (typeof(module) == "undefined" ? "" : module.filename) + " requires node.js version 4.0.0 or higher"); 2 | -------------------------------------------------------------------------------- /docs/12socket/code/bin/example.js: -------------------------------------------------------------------------------- 1 | // Generated by Haxe 3.4.4 2 | if (process.version < "v4.0.0") console.warn("Module " + (typeof(module) == "undefined" ? "" : module.filename) + " requires node.js version 4.0.0 or higher"); 3 | (function () { "use strict"; 4 | var Main = function() { 5 | this.PORT = 3700; 6 | console.log("Express website (Basic): open browser at http://localhost:" + this.PORT); 7 | console.log("Stop node.js : CTRL + c"); 8 | var app = new js_npm_Express(); 9 | var server = js_node_Http.createServer(app); 10 | var io = new js_npm_socketio_Server(server); 11 | app.set("views",__dirname + "/public/views"); 12 | app.set("view engine","jade"); 13 | app["use"](new js_npm_express_Static(__dirname + "/public")); 14 | app["use"](new js_npm_express_Morgan("dev")); 15 | app["use"](new js_npm_express_Favicon(__dirname + "/public/favicon.ico")); 16 | app.get("/",function(req,res) { 17 | var liveReload = ""; 18 | res.render("page",{ livereload : liveReload}); 19 | }); 20 | io.on("connection",function(socket) { 21 | socket.emit("message",{ message : "welcome to the chat"}); 22 | socket.on("send",function(data) { 23 | io.sockets.emit("message",data); 24 | }); 25 | }); 26 | console.log("Listening on port " + this.PORT); 27 | server.listen(this.PORT); 28 | }; 29 | Main.main = function() { 30 | var main = new Main(); 31 | }; 32 | var haxe_io_Bytes = function() { }; 33 | var js_node_Http = require("http"); 34 | var js_node_buffer_Buffer = require("buffer").Buffer; 35 | var js_npm_Express = require("express"); 36 | var js_npm_express_Favicon = require("serve-favicon"); 37 | var js_npm_express_Morgan = require("morgan"); 38 | var js_npm_express_Static = require("express").static; 39 | var js_npm_socketio_Server = require("socket.io"); 40 | Main.main(); 41 | })(); 42 | -------------------------------------------------------------------------------- /docs/12socket/code/bin/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthijsKamstra/haxenode/6930b222e50c101c9639ac26b72996c69f343e0b/docs/12socket/code/bin/public/favicon.ico -------------------------------------------------------------------------------- /docs/12socket/code/bin/public/views/page.jade: -------------------------------------------------------------------------------- 1 | doctype 2 | html 3 | head 4 | title= "Real time web chat" 5 | script(src='https://cdn.socket.io/socket.io-1.4.5.js') 6 | script(src='http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js') 7 | script(src='/js/client.js') 8 | // Bootstrap core CSS 9 | link(href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css', rel='stylesheet') 10 | body 11 | .container 12 | #content(style='width: 500px; height: 300px; margin: 0 0 20px 0; border: solid 1px #999; overflow-y: scroll;') 13 | .controls 14 | | Name: 15 | input#inputName(style='width:350px;') 16 | br 17 | input#inputField(style='width:350px;') 18 | input#sendBtn(type='button', value='send') 19 | script(src='#{livereload}') 20 | -------------------------------------------------------------------------------- /docs/12socket/code/build copy.hxml: -------------------------------------------------------------------------------- 1 | # -lib js-kit 2 | --library hxnodejs 3 | --class-path src 4 | --main Main 5 | --js bin/example.js 6 | --dce full 7 | -D js-es=6 8 | 9 | --next 10 | 11 | # Use terminal command to start Node.js! 12 | --cmd echo "use: 'node bin/example.js' to check script " 13 | --cmd cd bin 14 | --cmd node example.js 15 | --cmd echo exit -------------------------------------------------------------------------------- /docs/12socket/code/build.hxml: -------------------------------------------------------------------------------- 1 | -lib js-kit 2 | -lib hxnodejs 3 | -cp src 4 | -main Main 5 | -js bin/example.js 6 | -dce full -------------------------------------------------------------------------------- /docs/12socket/code/javascript.hxml: -------------------------------------------------------------------------------- 1 | # libs used in project 2 | -lib jQueryExtern 3 | -lib js-kit 4 | -lib hxnodejs 5 | # source folder 6 | -cp src 7 | # class entry point 8 | -main MainClient 9 | # JavaScript target 10 | -js bin/public/js/client.js 11 | -D source-map-content 12 | -debug 13 | -dce full 14 | -D hxnodejs_no_version_warning 15 | # --macro npm.Package.export("package.json") 16 | 17 | 18 | --next 19 | 20 | 21 | # libs used in project 22 | -lib js-kit 23 | -lib hxnodejs 24 | 25 | # integrate files to classpath 26 | -cp src 27 | 28 | # this class wil be used as entry point for your app. 29 | -main Main 30 | 31 | # JavaScript target 32 | -js bin/example.js 33 | 34 | # You can use -D source-map-content (requires Haxe 3.1+) to have the .hx 35 | # files directly embedded into the map file, this way you only have to 36 | # upload it, and it will be always in sync with the compiled .js even if 37 | # you modify your .hx files. 38 | # -D source-map-content 39 | 40 | # Generate source map and add debug information 41 | -debug 42 | 43 | # dead code elimination : remove unused code 44 | # "-dce no" : do not remove unused code 45 | # "-dce std" : remove unused code in the std lib (default) 46 | # "-dce full" : remove all unused code 47 | -dce full 48 | 49 | # This is very cool, but not necessary for this project, you can create a package.json with the correct depencicies (https://github.com/clemos/haxe-js-kit# exporting-your-project-dependencies) 50 | --macro npm.Package.export("package.json") 51 | 52 | 53 | 54 | 55 | 56 | # Use terminal command to start Node.js! 57 | # -cmd cd bin 58 | # -cmd node example.js 59 | 60 | -------------------------------------------------------------------------------- /docs/12socket/code/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "license": "MIT", 3 | "description": "Socket.io example", 4 | "author": "Matthijs Kamstra aka [mck]", 5 | "start": "node index.js", 6 | "private": true, 7 | "dependencies": { 8 | "jade": "*", 9 | "morgan": "^1.5.1", 10 | "socket.io": "1.0", 11 | "onchange": "^2.0.0", 12 | "socket.io-adapter": "0.3.1", 13 | "livereload": "^0.3.7", 14 | "nodemon": "^1.7.1", 15 | "serve-favicon": "*", 16 | "express": "~4.17" 17 | }, 18 | "scripts": { 19 | "watch": "onchange '**/*.hx' '**/*.md' -v -- haxe javascript.hxml & nodemon bin/example.js & livereload bin/", 20 | "prewatch": "haxe javascript.hxml" 21 | } 22 | } -------------------------------------------------------------------------------- /docs/12socket/code/src/Main.hx: -------------------------------------------------------------------------------- 1 | package ; 2 | 3 | import js.Node; 4 | import js.npm.Express; 5 | 6 | 7 | import js.npm.SocketIo; 8 | 9 | import js.Node; 10 | import js.node.Http; 11 | import js.node.Path; 12 | 13 | import js.npm.Express; 14 | import js.npm.express.*; 15 | import js.npm.Jade; 16 | 17 | /** 18 | * @author Matthijs Kamstra aka [mck] 19 | */ 20 | class Main 21 | { 22 | 23 | private var PORT = 3700; 24 | 25 | function new() 26 | { 27 | trace("Express website (Basic): open browser at http://localhost:" + PORT); 28 | trace("Stop node.js : CTRL + c"); 29 | 30 | var app = new js.npm.Express(); 31 | var server = js.node.Http.createServer( cast app ); 32 | var io = new js.npm.socketio.Server(server); 33 | 34 | app.set('views', Node.__dirname + '/public/views'); 35 | app.set('view engine', "jade"); 36 | 37 | app.use(new Static(Node.__dirname + '/public')); 38 | app.use(new Morgan('dev')); 39 | app.use(new Favicon(Node.__dirname + '/public/favicon.ico')); 40 | 41 | app.get("/", function(req : Request, res : Response ){ 42 | var liveReload = ""; 43 | #if debug 44 | // liveReload = ''; 45 | liveReload = 'http://0.0.0.0:35729/livereload.js'; 46 | #end 47 | res.render("page", {livereload : liveReload}); 48 | }); 49 | 50 | // app.use(BodyParser.json()); 51 | // app.use(BodyParser.urlencoded({ extended: true })); 52 | // app.use(new MethodOverride()); // can't find it in js-kit AND don't know what it does... 53 | // app.use(new Static(Path.join(Node.__dirname, 'public'))); 54 | 55 | io.on('connection', function (socket) { 56 | socket.emit('message', { message: 'welcome to the chat' }); 57 | socket.on('send', function (data) { 58 | io.sockets.emit('message', data); 59 | }); 60 | }); 61 | 62 | trace ("Listening on port " + PORT); 63 | 64 | server.listen(PORT); 65 | 66 | } 67 | 68 | static public function main() 69 | { 70 | var main = new Main(); 71 | } 72 | } -------------------------------------------------------------------------------- /docs/12socket/code/src/MainClient.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | import jQuery.*; 4 | import js.Browser; 5 | import js.html.*; 6 | 7 | class MainClient { 8 | 9 | private var _messages = []; 10 | private var _socket : Dynamic; 11 | private var _inputField : InputElement; 12 | private var _sendButton : Dynamic; 13 | private var _content : Element; 14 | private var _inputName : InputElement ; 15 | 16 | public function new() 17 | { 18 | 19 | new JQuery(Browser.document).ready ( function () 20 | { 21 | trace ("MainClient document ready!"); 22 | 23 | init(); 24 | 25 | new JQuery("#inputField").keyup( function (e : Dynamic) 26 | { 27 | if(e.keyCode == 13) { 28 | sendMessage(); 29 | } 30 | }); 31 | }); 32 | } 33 | 34 | 35 | private function init() : Void 36 | { 37 | _messages = []; 38 | _socket = js.browser.SocketIo.connect('http://localhost:3700'); 39 | _inputField = cast (Browser.document.getElementById("inputField") , InputElement); 40 | _sendButton = Browser.document.getElementById("sendBtn"); 41 | _content = Browser.document.getElementById("content"); 42 | _inputName = cast (Browser.document.getElementById("inputName") , InputElement); 43 | 44 | _socket.on('message', function (data) 45 | { 46 | if(data.message != null) 47 | { 48 | _messages.push(data); 49 | var html = ''; 50 | 51 | for (i in 0 ... _messages.length) 52 | { 53 | html += '' + (_messages[i].username != null ? _messages[i].username : 'Server') + ': '; 54 | html += _messages[i].message + '
'; 55 | } 56 | 57 | _content.innerHTML = html; 58 | } else { 59 | trace("There is a problem: " + data); 60 | } 61 | }); 62 | 63 | _sendButton.addEventListener('click', function() { 64 | if(_inputName.value == "") { 65 | Browser.alert("Please type your name!"); 66 | } else { 67 | sendMessage(); 68 | } 69 | },false); 70 | } 71 | 72 | private function sendMessage():Void 73 | { 74 | var text = _inputField.value; 75 | _socket.emit('send', { message: text, username: _inputName.value }); 76 | _inputField.value = ""; 77 | } 78 | 79 | 80 | static public function main() 81 | { 82 | var main = new MainClient(); 83 | } 84 | } -------------------------------------------------------------------------------- /docs/12socket/installation.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | 3 | Read the how to install **Node.js** and **Haxe** [here](../haxenode/download.md). 4 | Once you have installed **Haxe** you will automatically installed `haxelib`. 5 | The same goes for **Node.js**, you will have automatically installed `NPM`. 6 | 7 | ## Install Node.js externs for Haxe 8 | 9 | Install the [official Haxe node.js externs](https://github.com/HaxeFoundation/hxnodejs) lib via [haxelib](http://lib.haxe.org/p/hxnodejs/). 10 | Haxelib is automaticly installed when installing Haxe and you can see it as a sort of NPM. 11 | 12 | ```bash 13 | haxelib install hxnodejs 14 | ``` 15 | 16 | In this tutorial I use mostly js-kit externs, there are more ways to get externs but the js-kit has a lot so it's more a one stop shop thing! 17 | 18 | ```bash 19 | haxelib git js-kit https://github.com/clemos/haxe-js-kit.git haxelib 20 | 21 | ``` 22 | 23 | ## Install express via NPM : 24 | 25 | [Express](https://github.com/strongloop/express) 26 | 27 | > Fast, unopinionated, minimalist web framework for node. 28 | 29 | ``` 30 | npm install express 31 | ``` 32 | 33 | ## Install for the more Intermediate and Advance example 34 | 35 | Express uses more dependencies: 36 | 37 | ``` 38 | npm install morgan 39 | npm install body-parser 40 | npm install serve-favicon 41 | npm install express 42 | npm install jade 43 | ``` 44 | 45 | --- 46 | 47 | ## Install all modules with NPM via package.json 48 | 49 | If you have a package.json file in your directory and you run npm install, then npm will look at the dependencies that are listed in that file and download the latest versions satisfying semver rules for all of those. 50 | 51 | To do so, `cd` to the correct folder ( `cd path/to/correct/folder/with/package/dot/json/` ) 52 | 53 | ``` 54 | npm install 55 | ``` 56 | 57 | This will install everything in `node_modules`. 58 | -------------------------------------------------------------------------------- /docs/12socket/todo.md: -------------------------------------------------------------------------------- 1 | https://www.codementor.io/nodejs/tutorial/build-google-tv-raspberrypi-nodejs-socket-io 2 | 3 | 4 | https://github.com/clemos/haxe-js-kit/blob/develop/test/SocketIoTest.hx -------------------------------------------------------------------------------- /docs/13sequelize/about.md: -------------------------------------------------------------------------------- 1 | # About Sequelize 2 | 3 | > Sequelize is a promise-based ORM for Node.js and io.js. It supports the dialects PostgreSQL, MySQL, MariaDB, SQLite and MSSQL and features solid transaction support, relations, read replication and more. 4 | 5 | **source: ** 6 | 7 | ## Soooo what is ORM? 8 | 9 | > Object-relational mapping (ORM, O/RM, and O/R mapping tool) in computer science is a programming technique for converting data between incompatible type systems in object-oriented programming languages. This creates, in effect, a "virtual object database" that can be used from within the programming language. 10 | 11 | **source: ** 12 | 13 | In short: it will let you talk to different backends (PostgreSQL, MySQL, MariaDB, SQLite and MSSQL) in the same way. 14 | So if are testing, you could decide to work with SQLite. 15 | Later change the backend to PostgreSQL for production and your don't have to rewrite any calls made to the backend! 16 | -------------------------------------------------------------------------------- /docs/13sequelize/code/bin/db/database.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthijsKamstra/haxenode/6930b222e50c101c9639ac26b72996c69f343e0b/docs/13sequelize/code/bin/db/database.sqlite -------------------------------------------------------------------------------- /docs/13sequelize/code/bin/example.js: -------------------------------------------------------------------------------- 1 | // Generated by Haxe 3.3.0 (git build development @ 297c528) 2 | if (process.version < "v4.0.0") console.warn("Module " + (typeof(module) == "undefined" ? "" : module.filename) + " requires node.js version 4.0.0 or higher"); 3 | (function () { "use strict"; 4 | var Main = function() { 5 | var options = { host : "localhost", dialect : "sqlite", pool : { max : 5, min : 0, idle : 10000}, storage : __dirname + "/db/database.sqlite"}; 6 | var sequelize = new js_npm_sequelize_Sequelize("database","username","password",options); 7 | sequelize.authenticate().then(function(err) { 8 | console.log("Connection has been established successfully."); 9 | })["catch"](function(err1) { 10 | console.log("Unable to connect to the database:",err1); 11 | }); 12 | var fields = { firstName : { type : js_npm_sequelize_Sequelize.STRING()}, lastName : { type : js_npm_sequelize_Sequelize.STRING()}}; 13 | var user = sequelize.define("user",fields); 14 | user.sync({ force : false}).then(function() { 15 | return user.create({ firstName : "John", lastName : "Hancock"}); 16 | }); 17 | user.findAll().then(function(users) { 18 | console.log(users); 19 | }); 20 | user.findOne().then(function(user1) { 21 | console.log(user1.get("firstName")); 22 | }); 23 | }; 24 | Main.main = function() { 25 | new Main(); 26 | }; 27 | var haxe_io_Bytes = function() { }; 28 | var js_node_buffer_Buffer = require("buffer").Buffer; 29 | var js_npm_sequelize_Sequelize = require("sequelize"); 30 | Main.main(); 31 | })(); 32 | 33 | //#sourceMappingURL=example.js.map -------------------------------------------------------------------------------- /docs/13sequelize/code/bin/example.js.map: -------------------------------------------------------------------------------- 1 | { 2 | "version":3, 3 | "file":"example.js", 4 | "sourceRoot":"file:///", 5 | "sources":["/Users/matthijs/Documents/workingdir/haxe/haxenode/13sequelize/code/src/Main.hx"], 6 | "names":[], 7 | "mappings":";;;WAeC,WACA;AAAA,CAIC,cAAiC,SACzB,uBACK,iBAEN,QACA,SACA,UACC,kBAIE,YAAkB;CAG5B,gBAAgB,+BAAe,WAAY,WAAY,WAAW;CAIlE,8BAEO,cACL;AAAA,cAAa;aAEN,eACP;AAAA,cAAa,qCAAqC;;CAKpD,aAAwC,cAC5B,SACJ,iDAEG,SACH;CAGR,WAAW,iBAAkB,OAAO;CAGpC,UAAU,UAAQ,aAAa,WAE9B;AAAA,SAAO,YAAY,cACN,mBACD;;CAMb,oBAAoB,gBAClB;AAAA,cAAY;;CAKd,oBAAoB,gBACnB;AAAA,cAAY,UAAU;;;YAKV,WAEF;AAAA;;;;;;;;" 8 | } -------------------------------------------------------------------------------- /docs/13sequelize/code/build copy.hxml: -------------------------------------------------------------------------------- 1 | # -lib js-kit 2 | --library hxnodejs 3 | --class-path src 4 | --main Main 5 | --js bin/example.js 6 | --dce full 7 | -D js-es=6 8 | 9 | --next 10 | 11 | # Use terminal command to start Node.js! 12 | --cmd echo "use: 'node bin/example.js' to check script " 13 | --cmd cd bin 14 | --cmd node example.js 15 | --cmd echo exit -------------------------------------------------------------------------------- /docs/13sequelize/code/build.hxml: -------------------------------------------------------------------------------- 1 | -lib js-kit 2 | -lib hxnodejs 3 | -cp src 4 | -main Main 5 | -js bin/example.js 6 | -dce full -------------------------------------------------------------------------------- /docs/13sequelize/code/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "license": "MIT", 3 | "description": "Sequelize example", 4 | "author": "Matthijs Kamstra aka [mck]", 5 | "private": true, 6 | "devDependencies": { 7 | "onchange": "^2.0.0", 8 | "livereload": "^0.3.7", 9 | "nodemon": "^1.11.0" 10 | }, 11 | "dependencies": { 12 | "sqlite3": "*", 13 | "sequelize": "^5.21.2" 14 | }, 15 | "scripts": { 16 | "watch": "onchange '**/*.hx' '**/*.md' -v -- haxe build.hxml & nodemon bin/example.js & livereload bin/", 17 | "prewatch": "haxe build.hxml" 18 | } 19 | } -------------------------------------------------------------------------------- /docs/13sequelize/code/src/Main.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | import js.Node; 4 | import js.Node.*; 5 | import js.npm.sequelize.*; 6 | import js.npm.sequelize.Sequelize; 7 | 8 | /** 9 | * @author Matthijs Kamstra aka [mck] 10 | */ 11 | class Main { 12 | // http://sequelize.readthedocs.io/en/latest/docs/getting-started/ 13 | function new() { 14 | // Setting up a connection 15 | // http://sequelize.readthedocs.io/en/latest/docs/getting-started/#setting-up-a-connection 16 | var options:SequelizeOptions = { 17 | host: 'localhost', 18 | dialect: 'sqlite', 19 | 20 | pool: { 21 | max: 5, 22 | min: 0, 23 | idle: 10000 24 | }, 25 | 26 | // SQLite only 27 | storage: Node.__dirname + '/db/database.sqlite' 28 | } 29 | 30 | var sequelize = new Sequelize('database', 'username', 'password', options); 31 | 32 | // Test the connection 33 | // http://sequelize.readthedocs.io/en/latest/docs/getting-started/#test-the-connection 34 | sequelize.authenticate().then(function(err) { 35 | console.log('Connection has been established successfully.'); 36 | }).Catch(function(err) { 37 | console.log('Unable to connect to the database:', err); 38 | }); 39 | 40 | // Your first model 41 | // http://sequelize.readthedocs.io/en/latest/docs/getting-started/#your-first-model 42 | var fields:Dynamic = { 43 | firstName: { 44 | type: Sequelize.STRING() 45 | }, 46 | lastName: { 47 | type: Sequelize.STRING() 48 | } 49 | }; 50 | var user = sequelize.define('user', fields); 51 | 52 | // force: true will drop the table if it already exists 53 | user.sync({force: false}).then(function() { 54 | // Table created 55 | return user.create({ 56 | firstName: 'John', 57 | lastName: 'Hancock' 58 | }); 59 | }); 60 | 61 | // Your first query 62 | // http://sequelize.readthedocs.io/en/latest/docs/getting-started/#your-first-query 63 | user.findAll().then(function(users) { 64 | console.log(users); 65 | }); 66 | 67 | // Promises 68 | // http://sequelize.readthedocs.io/en/latest/docs/getting-started/#promises 69 | user.findOne().then(function(user) { 70 | console.log(user.get('firstName')); 71 | }); 72 | } 73 | 74 | static public function main() { 75 | var main = new Main(); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /docs/13sequelize/installation.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | 3 | Read the how to install **Node.js** and **Haxe** [here](../haxenode/download.md). 4 | Once you have installed **Haxe** you will automatically installed `haxelib`. 5 | The same goes for **Node.js**, you will have automatically installed `NPM`. 6 | 7 | ## Install Node.js externs for Haxe 8 | 9 | Install the [official Haxe node.js externs](https://github.com/HaxeFoundation/hxnodejs) lib via [haxelib](http://lib.haxe.org/p/hxnodejs/). 10 | Haxelib is automaticly installed when installing Haxe and you can see it as a sort of NPM. 11 | 12 | ```bash 13 | haxelib install hxnodejs 14 | ``` 15 | 16 | In this tutorial I use mostly js-kit externs, there are more ways to get externs but the js-kit has a lot so it's more a one stop shop thing! 17 | 18 | ```bash 19 | haxelib git js-kit https://github.com/clemos/haxe-js-kit.git haxelib 20 | 21 | ``` 22 | 23 | ## Install all modules with NPM via package.json 24 | 25 | If you have a package.json file in your directory and you run npm install, then npm will look at the dependencies that are listed in that file and download the latest versions satisfying semver rules for all of those. 26 | 27 | To do so, `cd` to the correct folder ( `cd path/to/correct/folder/with/package/dot/json/` ) 28 | 29 | ``` 30 | npm install 31 | ``` 32 | 33 | This will install everything in `node_modules`, also the npm packages `sqlite3' and `sequelize`. 34 | -------------------------------------------------------------------------------- /docs/14jsondb/code/bin/database.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "foo", 3 | "number": 1, 4 | "float": 1.1, 5 | "string": "foo", 6 | "array": [ 7 | 1, 8 | 2, 9 | 3 10 | ], 11 | "bool": true, 12 | "obj": { 13 | "one": 1, 14 | "two": 2 15 | }, 16 | "test1": 2, 17 | "test2": [ 18 | 1, 19 | 2, 20 | 3 21 | ], 22 | "test3": true, 23 | "test4": { 24 | "foo": "ss" 25 | } 26 | } -------------------------------------------------------------------------------- /docs/14jsondb/code/build copy.hxml: -------------------------------------------------------------------------------- 1 | # -lib js-kit 2 | --library hxnodejs 3 | --class-path src 4 | --main Main 5 | --js bin/example.js 6 | --dce full 7 | -D js-es=6 8 | 9 | --next 10 | 11 | # Use terminal command to start Node.js! 12 | --cmd echo "use: 'node bin/example.js' to check script " 13 | --cmd cd bin 14 | --cmd node example.js 15 | --cmd echo exit -------------------------------------------------------------------------------- /docs/14jsondb/code/build.hxml: -------------------------------------------------------------------------------- 1 | # -lib js-kit 2 | -lib hxnodejs 3 | -cp src 4 | -main Main 5 | -js bin/example.js 6 | # -dce full 7 | 8 | -cmd cd bin 9 | -cmd node example.js -------------------------------------------------------------------------------- /docs/14jsondb/code/src/Main.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | import js.node.Http; 4 | import js.Node.console; 5 | import js.Node.*; 6 | import js.node.Fs; 7 | import js.node.Url; 8 | import JsonDB; 9 | 10 | /** 11 | * @author Matthijs Kamstra aka [mck] 12 | */ 13 | class Main { 14 | function new() { 15 | var db = new JsonDB(); 16 | db.setData({ 17 | 'name': "foo", 18 | 'number': 1, 19 | 'float': 1.1, 20 | string: "foo", 21 | array: [1, 2, 3], 22 | bool: true, 23 | obj: {one: 1, two: 2} 24 | }); 25 | trace(db.getData()); 26 | db.set('test0', "one"); 27 | db.set('test1', 2); 28 | db.set('test2', [1, 2, 3]); 29 | db.set('test3', true); 30 | db.set('test4', {foo: 'ss'}); 31 | trace(db.getData()); 32 | trace(db.has('test0')); 33 | db.delete('test0'); 34 | trace(db.has('test0')); 35 | 36 | db.startServer(); 37 | 38 | // var db2 = new JsonDB('database2', false); 39 | // db2.setData({test:'xxx', test2:4}); 40 | } 41 | 42 | static public function main() { 43 | var main = new Main(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /docs/14jsondb/code/todo.md: -------------------------------------------------------------------------------- 1 | Simple JSON database with Node.JS 2 | 3 | 4 | https://gist.github.com/tomasgreen/aabb28becbdc6d7a36ab 5 | https://github.com/Belphemur/node-json-db/blob/master/JsonDB.js 6 | https://github.com/nmaggioni/Simple-JSONdb/blob/master/jsondb.js 7 | 8 | 9 | https://github.com/Belphemur/node-json-db 10 | https://github.com/usmakestwo/githubDB 11 | 12 | ## http 13 | 14 | https://gist.github.com/v3rse/d4c3d43fbe29751f58ca9407c5a5b9c3 15 | 16 | https://gist.github.com/brandonb927/9587436 17 | 18 | 19 | https://gist.github.com/celestelayne/01bf028851381819904bb7ccd37e0731 -------------------------------------------------------------------------------- /docs/GLOSSARY.md: -------------------------------------------------------------------------------- 1 | # wip 2 | Work in progress 3 | 4 | # terminal 5 | The terminal is an interface in which you can type and execute text based commands. 6 | Alternative names for the terminal: 7 | * Console 8 | * Shell 9 | * Command Line 10 | * Command Prompt 11 | 12 | # fixme 13 | This needs some more info, you could help me with that! 14 | 15 | # HelloWorld 16 | # Hello world 17 | A "Hello, World!" program is a computer program that outputs "Hello, World!" (or some variant thereof) on a display device. 18 | 19 | # foobar 20 | The terms foobar, fubar, or foo, bar, baz and qux (alternatively, quux) and sometimes norf and many others are sometimes used as placeholder names (also referred to as metasyntactic variables) in computer programming or computer-related documentation. 21 | 22 | # CDN 23 | A content delivery network or content distribution network (CDN) is a large distributed system of servers deployed in multiple data centers across the Internet. 24 | 25 | # hxml 26 | Haxe build file 27 | 28 | # DOM 29 | DOM is short for Document Object Model. 30 | It is a platform- and language-neutral interface that will allow programs and scripts to dynamically access and update the content, structure and style of documents. The document can be further processed and the results of that processing can be incorporated back into the presented page. 31 | 32 | # VanillaJS 33 | Is a name to refer to using plain JavaScript without any additional libraries like jQuery. People use it as a joke to remind other developers that many things can be done nowadays without the need for additional JavaScript libraries. 34 | 35 | # IDE 36 | An **integrated development environment** (IDE) is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of a source code editor, build automation tools and a debugger. Most modern IDEs have intelligent code completion. 37 | 38 | # API 39 | API (application program interface) is a set of routines, protocols, and tools for building software applications. The API specifies how software components should interact and APIs are used when programming graphical user interface (GUI) components. A good API makes it easier to develop a program by providing all the building blocks. A programmer then puts the blocks together. 40 | 41 | # CSS 42 | Cascading Style Sheets (CSS) is a style sheet language used for describing the presentation of a document written in a markup language. 43 | 44 | # json 45 | # JSON 46 | JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. 47 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # Haxe and Node.js 2 | 3 | I wanted to do a quick prototype with Node.js and my favorite programming language Haxe. 4 | But I couldn't find any documentation on how to start. 5 | -------------------------------------------------------------------------------- /docs/__express/app.js: -------------------------------------------------------------------------------- 1 | var createError = require('http-errors'); 2 | var express = require('express'); 3 | var path = require('path'); 4 | var cookieParser = require('cookie-parser'); 5 | var logger = require('morgan'); 6 | 7 | var indexRouter = require('./routes/index'); 8 | var usersRouter = require('./routes/users'); 9 | 10 | var app = express(); 11 | 12 | // view engine setup 13 | app.set('views', path.join(__dirname, 'views')); 14 | app.set('view engine', 'jade'); 15 | 16 | app.use(logger('dev')); 17 | app.use(express.json()); 18 | app.use(express.urlencoded({ extended: false })); 19 | app.use(cookieParser()); 20 | app.use(express.static(path.join(__dirname, 'public'))); 21 | 22 | app.use('/', indexRouter); 23 | app.use('/users', usersRouter); 24 | 25 | // catch 404 and forward to error handler 26 | app.use(function(req, res, next) { 27 | next(createError(404)); 28 | }); 29 | 30 | // error handler 31 | app.use(function(err, req, res, next) { 32 | // set locals, only providing error in development 33 | res.locals.message = err.message; 34 | res.locals.error = req.app.get('env') === 'development' ? err : {}; 35 | 36 | // render the error page 37 | res.status(err.status || 500); 38 | res.render('error'); 39 | }); 40 | 41 | module.exports = app; 42 | -------------------------------------------------------------------------------- /docs/__express/bin/www: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /** 4 | * Module dependencies. 5 | */ 6 | 7 | var app = require('../app'); 8 | var debug = require('debug')('express:server'); 9 | var http = require('http'); 10 | 11 | /** 12 | * Get port from environment and store in Express. 13 | */ 14 | 15 | var port = normalizePort(process.env.PORT || '3000'); 16 | app.set('port', port); 17 | 18 | /** 19 | * Create HTTP server. 20 | */ 21 | 22 | var server = http.createServer(app); 23 | 24 | /** 25 | * Listen on provided port, on all network interfaces. 26 | */ 27 | 28 | server.listen(port); 29 | server.on('error', onError); 30 | server.on('listening', onListening); 31 | 32 | /** 33 | * Normalize a port into a number, string, or false. 34 | */ 35 | 36 | function normalizePort(val) { 37 | var port = parseInt(val, 10); 38 | 39 | if (isNaN(port)) { 40 | // named pipe 41 | return val; 42 | } 43 | 44 | if (port >= 0) { 45 | // port number 46 | return port; 47 | } 48 | 49 | return false; 50 | } 51 | 52 | /** 53 | * Event listener for HTTP server "error" event. 54 | */ 55 | 56 | function onError(error) { 57 | if (error.syscall !== 'listen') { 58 | throw error; 59 | } 60 | 61 | var bind = typeof port === 'string' 62 | ? 'Pipe ' + port 63 | : 'Port ' + port; 64 | 65 | // handle specific listen errors with friendly messages 66 | switch (error.code) { 67 | case 'EACCES': 68 | console.error(bind + ' requires elevated privileges'); 69 | process.exit(1); 70 | break; 71 | case 'EADDRINUSE': 72 | console.error(bind + ' is already in use'); 73 | process.exit(1); 74 | break; 75 | default: 76 | throw error; 77 | } 78 | } 79 | 80 | /** 81 | * Event listener for HTTP server "listening" event. 82 | */ 83 | 84 | function onListening() { 85 | var addr = server.address(); 86 | var bind = typeof addr === 'string' 87 | ? 'pipe ' + addr 88 | : 'port ' + addr.port; 89 | debug('Listening on ' + bind); 90 | } 91 | -------------------------------------------------------------------------------- /docs/__express/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "express", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "start": "node ./bin/www" 7 | }, 8 | "dependencies": { 9 | "cookie-parser": "~1.4.4", 10 | "debug": "~2.6.9", 11 | "express": "~4.16.1", 12 | "http-errors": "~1.6.3", 13 | "jade": "~1.11.0", 14 | "morgan": "~1.9.1" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /docs/__express/public/stylesheets/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding: 50px; 3 | font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; 4 | } 5 | 6 | a { 7 | color: #00B7FF; 8 | } 9 | -------------------------------------------------------------------------------- /docs/__express/routes/index.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var router = express.Router(); 3 | 4 | /* GET home page. */ 5 | router.get('/', function(req, res, next) { 6 | res.render('index', { title: 'Express' }); 7 | }); 8 | 9 | module.exports = router; 10 | -------------------------------------------------------------------------------- /docs/__express/routes/users.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var router = express.Router(); 3 | 4 | /* GET users listing. */ 5 | router.get('/', function(req, res, next) { 6 | res.send('respond with a resource'); 7 | }); 8 | 9 | module.exports = router; 10 | -------------------------------------------------------------------------------- /docs/__express/views/error.jade: -------------------------------------------------------------------------------- 1 | extends layout 2 | 3 | block content 4 | h1= message 5 | h2= error.status 6 | pre #{error.stack} 7 | -------------------------------------------------------------------------------- /docs/__express/views/index.jade: -------------------------------------------------------------------------------- 1 | extends layout 2 | 3 | block content 4 | h1= title 5 | p Welcome to #{title} 6 | -------------------------------------------------------------------------------- /docs/__express/views/layout.jade: -------------------------------------------------------------------------------- 1 | doctype html 2 | html 3 | head 4 | title= title 5 | link(rel='stylesheet', href='/stylesheets/style.css') 6 | body 7 | block content 8 | -------------------------------------------------------------------------------- /docs/_sidebar.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | - [Home](/) 4 | 5 | - [Introduction](intro.md) 6 | - [Level of Difficulty](level.md) 7 | - [Haxe basics](haxe/about.md) 8 | - [Quick install](haxe/quick-install.md) 9 | - [Installation](haxe/installation.md) 10 | - [Code editor](haxe/choosing-a-code-editor.md) 11 | - [Hello world](haxe/hello-world.md) 12 | - [Learn Haxe](haxe/learn-haxe.md) 13 | - [Haxe and Node.js](haxenode/about.md) 14 | - [Installation](haxenode/installation.md) 15 | - [Why Haxe?](haxenode/why.md) 16 | - [What is it](haxenode/what.md) 17 | - [Download](haxenode/download.md) 18 | - [More info](haxenode/about.md) 19 | - [Resources](haxenode/resource.md) 20 | - [Cheatsheet](haxenode/cheatsheet.md) 21 | - [Copy & Paste](haxenode/copy_paste.md) 22 | - [Example Hello World](00helloworld/example.md) 23 | - [Installation](00helloworld/installation.md) 24 | - [More info](00helloworld/about.md) 25 | - [Example Writing](01writing/example.md) 26 | - [Installation](01writing/installation.md) 27 | - [More info](01writing/about.md) 28 | - [Example Reading](02reading/example.md) 29 | - [Installation](02reading/installation.md) 30 | - [More info](02reading/about.md) 31 | 32 | 33 | 34 | - [Example HaxeLow](04haxelow/example.md) 35 | - [Installation](04haxelow/installation.md) 36 | - [More info](04haxelow/about.md) 37 | - [Example Website](05website/exampleBasic.md) 38 | - [Installation](05website/installation.md) 39 | - [Example Basic](05website/exampleBasic.md) 40 | - [Example Intermediate](05website/exampleIntermediate.md) 41 | - [Example Advanced](05website/exampleAdvanced.md) 42 | - [Example NeDB](06nedb/example.md) 43 | - [Installation](06nedb/installation.md) 44 | - [More info](06nedb/about.md) 45 | - [Example 2](06nedb/example2.md) 46 | - [Example Slack bot](09slackbot/example.md) 47 | - [Installation](09slackbot/installation.md) 48 | - [More info](09slackbot/about.md) 49 | - [Example Scraping](10scraping/example.md) 50 | - [Installation](10scraping/installation.md) 51 | - [More info](10scraping/about.md) 52 | - [Example Automation](11automation/example.md) 53 | - [Installation](11automation/installation.md) 54 | - [More info](11automation/about.md) 55 | - [Better Example](11automation/example2.md) 56 | - [Example Socket](12socket/example.md) 57 | - [Installation](12socket/installation.md) 58 | - [More info](12socket/about.md) 59 | - [Example Sequelize](13sequelize/example.md) 60 | - [Installation](13sequelize/installation.md) 61 | - [More info](13sequelize/about.md) 62 | - Resources 63 | - [Who to follow](resources/follow.md) 64 | - [More like this](resources/more.md) 65 | - [Try Haxe!](https://try.haxe.org/) 66 | - [Community](http://community.haxe.org/) 67 | - [Contribute](https://github.com/MatthijsKamstra/haxenode/blob/master/docs/contribute.md) 68 | - [Source](https://github.com/MatthijsKamstra/haxenode/) 69 | - [Suggestion Box](https://github.com/MatthijsKamstra/haxenode/issues/1) 70 | -------------------------------------------------------------------------------- /docs/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthijsKamstra/haxenode/6930b222e50c101c9639ac26b72996c69f343e0b/docs/favicon.ico -------------------------------------------------------------------------------- /docs/haxe/_terminal.md: -------------------------------------------------------------------------------- 1 | # Terminal 2 | 3 | A part of working with Haxe is the terminal. 4 | You don't have to be very experienced with it to get it working for Haxe. 5 | 6 | There are two ways to use the terminal it regarding Haxe: 7 | 8 | 1. Haxe compiler 9 | 2. Haxelib 10 | 11 | ## Open the terminal 12 | 13 | ### Osx: 14 | How to open the terminal on Osx 15 | 16 | 1. press CMD + space 17 | 2. that will open `Spotlight Search` 18 | 3. type "terminal" (without quotes) 19 | 4. press enter. 20 | 21 | And you are done. 22 | 23 | ### Linux 24 | fixme 25 | 26 | ### Window 27 | fixme 28 | 29 | 30 | ## Open folder in terminal 31 | 32 | Once you started the terminal, you need to direct it to the correct folder 33 | 34 | 1. open the folder in the finder 35 | 2. Type `cd ` in your terminal 36 | 3. drag the folder from the finder to the terminal 37 | 4. press enter 38 | 39 | It will look something like this: 40 | 41 | ``` 42 | → cd /path/to/folder/projectName 43 | ``` 44 | 45 | 46 | 47 | 48 | ## Resources 49 | 50 | *Osx* 51 | 52 | * -------------------------------------------------------------------------------- /docs/haxe/code/Test.hx: -------------------------------------------------------------------------------- 1 | class Test { 2 | static function main() { 3 | trace("Hello World !"); 4 | } 5 | } -------------------------------------------------------------------------------- /docs/haxe/code/compile.hxml: -------------------------------------------------------------------------------- 1 | -js test.js 2 | -main Test -------------------------------------------------------------------------------- /docs/haxe/code/test.html: -------------------------------------------------------------------------------- 1 | 2 | Haxe JS 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /docs/haxe/code/test.js: -------------------------------------------------------------------------------- 1 | (function (console) { "use strict"; 2 | var Test = function() { }; 3 | Test.main = function() { 4 | console.log("Hello World !"); 5 | }; 6 | Test.main(); 7 | })(typeof console != "undefined" ? console : {log:function(){}}); 8 | -------------------------------------------------------------------------------- /docs/haxe/hello-world.md: -------------------------------------------------------------------------------- 1 | # Hello world 2 | 3 | ![](../img/helloworld.png) 4 | 5 | Developing JavaScript code is easy with Haxe. Let's see our first HelloWorld example : 6 | 7 | ```haxe 8 | class Test { 9 | static function main() { 10 | trace("Hello World !"); 11 | } 12 | } 13 | ``` 14 | 15 | Put this class into a file named `Test.hx` and create the file `compile.hxml` in the same directory with the following content: 16 | 17 | ``` 18 | -js test.js 19 | -main Test 20 | ``` 21 | 22 | To compile open you terminal and type: 23 | 24 | cd 25 | 26 | And drag the folder where you saved the files, into the terminal. 27 | It will look something like this: 28 | 29 | cd /path/to/folder/ 30 | 31 | Press enter and type: 32 | 33 | haxe compile.hxml 34 | 35 | If an error occurs, the terminal will display that. 36 | If everything went smoothly like it should, this will produce a `test.js` file that can be embedded into an HTML page such as this one : 37 | 38 | ```html 39 | 40 | Haxe JS 41 | 42 | 43 | 44 | 45 | 46 | 47 | ``` 48 | 49 | 1. Put this code into a `test.html` file. 50 | 2. Open it with your browser (like Google Chrome) 51 | 3. It will display **Hello World** in your Console. 52 | 4. (Google Chrome > Hamburger menu > More Tools > Developers tools) 53 | 54 | 55 | ## try.haxe 56 | 57 | If you want to experiment with this code, you can do that without installing Haxe. 58 | 59 | Below you can see and try the same example code at [try.haxe.org](https://try.haxe.org/) without installing Haxe. 60 | 61 | 64 | 65 | 66 | *Based upon [old.haxe.org - manual](http://old.haxe.org/doc/start/js)* 67 | -------------------------------------------------------------------------------- /docs/haxe/installation.md: -------------------------------------------------------------------------------- 1 | # Installing Haxe 2 | 3 | 4 | ![](../img/install.jpg) 5 | 6 | 7 | First, you will need to install Haxe (Neko and Haxelib). 8 | There are a couple ways to install Haxe: 9 | 10 | * Get the [installer](#haxe) from [haxe.org](http://haxe.org/download/) (original) 11 | * Use [NPM](#npm) 12 | * Use [Homebrew](#brew) 13 | * Use [Chocolatey](#chocolatey) 14 | 15 | 16 | Although all the installation methods _should_ work. I have use the original installer from haxe.org, and didn't try the other methods. 17 | 18 | My suggestion would be to use that one! 19 | 20 | 21 | 22 | ## Installer (original) from haxe.org 23 | 24 | You can find installers and binaries for Windows, OS X and Linux on [http://haxe.org/download/](http://haxe.org/download/). 25 | 26 | 27 | 28 | ## Install with NPM (node) 29 | 30 | Before you can install Haxe, you have to install Node.js (and thus NPM). 31 | Installing Haxe with NPM makes sense if you have NPM installed already. 32 | 33 | But here is the link to install Node.js: [https://nodejs.org/](https://nodejs.org/) 34 | 35 | After installation use: 36 | 37 | npm install -g haxe 38 | 39 | *[read more about Haxe at NPM](https://www.npmjs.com/package/haxe)* 40 | AND check out all the [Haxe related projects](https://www.npmjs.com/browse/keyword/haxe) on NPM. 41 | 42 | 43 | ## Install with Homebrew 44 | 45 | Same as with Node.js, you probably want to use Homebrew if you have this already installed. 46 | Worth mentioning: this works on OS X. 47 | 48 | Visit [http://brew.sh/](http://brew.sh/) to get instruction how to install Homebrew. 49 | 50 | After installation use: (install latest from git with --HEAD) 51 | 52 | brew install haxe --HEAD 53 | 54 | 55 | 56 | ## Install with chocolatey 57 | 58 | This is a Windows install method. You can get your Chocolatey install instructions from [chocolatey.org](https://chocolatey.org/) 59 | 60 | After installation use: 61 | 62 | choco install haxe 63 | 64 | --- 65 | -------------------------------------------------------------------------------- /docs/haxenode/about.md: -------------------------------------------------------------------------------- 1 | # About haxenode (Haxe and Node.js) 2 | 3 | ![Haxe logo](../img/haxe_nodejs_logos.png) 4 | 5 | JavaScript is **one** of the targets you can use when you work with [Haxe](http://haxe.org/). 6 | And JavaScript is becoming one of the most powerful and [popular](https://github.com/blog/2047-language-trends-on-github) languages you can learn. 7 | 8 | ![](https://cloud.githubusercontent.com/assets/2623954/9098640/f15e22b4-3b7f-11e5-9496-12b6d811f0ea.jpg) 9 | 10 | 11 | One of the reasons it's becoming so popular is Node.js! 12 | With node you write JavaScript for the back-end. 13 | 14 | With JavaScript and node.js you are able to write front-end AND back-end. 15 | 16 | 17 | 18 | You would say the (Haxe) documentation about the JavaScript target would we **very** big. 19 | 20 | **Well, you guessed it, it's not.** 21 | The information scattered across the web on blogs, forums, tweets, etc. 22 | 23 | 24 | ![](http://www.reactiongifs.com/r/do.gif) 25 | 26 | I can bitch about it, or do something about it... I choose the second. 27 | 28 | ---- 29 | 30 | There used to be a website (an old one, from when Haxe spelled "haXe") that got you started. 31 | 32 | But that is no more. So I decided to get some of that back. 33 | Based upon the information from the old site and my own need to document this. 34 | 35 | --- 36 | 37 | I started with the information from the old site. A simple copy, paste. Most of the content of this site/book is from different sources (with permission of the writers). Eventually (that means in the future) I will rewrite it (or not). 38 | 39 | The rewrite will focus on getting the old information/tutorials updated to current use of Haxe and JavaScript. 40 | *And more motivational gif :D !* 41 | 42 | 43 | ---- 44 | 45 | ### Original Haxenode.org? 46 | You can find the original data at the github account of [theRemix](https://github.com/theRemix/haxenode.org/tree/ajaxloaded/views) in `.jade` files -------------------------------------------------------------------------------- /docs/haxenode/download.md: -------------------------------------------------------------------------------- 1 | # Install Haxe and Node.js 2 | 3 | Before you can use there are a couple of thing you need to do. 4 | 5 | You need to install Haxe. There are a [couple of ways to do it](../haxe/installation.md), but in this document I will send you to the [official place](# haxe). 6 | 7 | Don't want to kick in some open doors, but before you can use Node.js ... you need to [install](# node) that also. 8 | 9 | And a [code editor](# ide) will be useful! 10 | 11 | Last but not least, you need to install the [Haxe Externs](# externs). These are the "translators" from `untyped` node.js code to typed Haxe code. You need to install the Node.js externs but get other fun stuff as well. You will need them further on these documentation. 12 | 13 | --- 14 | 15 | Current versions are: 16 | 17 | - **Haxe** v3.2.1 18 | - **Node.js** v0.12.7 19 | 20 | But if the version numbers changed, it means I haven't updated this part of the document in some time :D 21 | 22 | 23 | 24 | ## Download Haxe 25 | 26 | ![](../img/haxe_logo.png) 27 | 28 | - Get your version here: [http://haxe.org/download/](http://haxe.org/download/) 29 | 30 | 31 | 32 | ## Download Node.js 33 | 34 | ![](../img/nodejs_logo.png) 35 | 36 | - Get your version here: [https://nodejs.org/](https://nodejs.org/) 37 | 38 | 39 | 40 | ## Code editor 41 | 42 | If you work on Windows you should install [FlashDevelop](http://www.flashdevelop.org), on other platforms you should read this chapter: [Choosing a Code Editor](../haxe/choosing-a-code-editor.md) 43 | 44 | 45 | 46 | ## Externs 47 | 48 | Install the [official Haxe node.js externs](https://github.com/HaxeFoundation/hxnodejs) lib via [haxelib](http://lib.haxe.org/p/hxnodejs/). 49 | Haxelib is automatically installed when installing Haxe and you can see it as a sort of NPM. 50 | 51 | ```bash 52 | haxelib install hxnodejs 53 | ``` 54 | 55 | In this tutorial I use the js-kit externs, there are more ways to get externs but the js-kit has a lot so it's more a one stop shop thing! 56 | 57 | ```bash 58 | haxelib git js-kit https://github.com/clemos/haxe-js-kit.git haxelib 59 | 60 | ``` 61 | -------------------------------------------------------------------------------- /docs/haxenode/example.md: -------------------------------------------------------------------------------- 1 | # Node.js example 2 | 3 | Here you will see an original node.js code and the Haxe version of the same code. 4 | I will not do that every time, so this is just an example to show you that there is not a lot of difference between the two ways. 5 | 6 | ---- 7 | 8 | ### Node.js 9 | ``` 10 | // example.js 11 | 12 | var http = require('http'); 13 | var server = http.createServer( 14 | function (req, res) { 15 | res.writeHead(200, {'Content-Type': 'text/plain'}); 16 | res.end('Hello World\\n'); 17 | } 18 | ) 19 | 20 | server.listen(1337, "127.0.0.1"); 21 | console.log('Server running at http://127.0.0.1:1337/'); 22 | ``` 23 | 24 | ### Run 25 | 26 | In terminal: 27 | 28 | ``` 29 | node example.js 30 | # Server running at http://127.0.0.1:1337/ 31 | ``` 32 | 33 | ---- 34 | 35 | # Haxe example 36 | 37 | ### haxe node 38 | 39 | ``` 40 | // Haxenode.hx 41 | 42 | package ; 43 | 44 | import js.Node; 45 | import js.node.Http; 46 | import js.node.http.ServerResponse; 47 | import js.node.http.IncomingMessage; 48 | 49 | class Haxenode 50 | { 51 | static public function main() 52 | { 53 | var server = Http.createServer(function (request:IncomingMessage, response:ServerResponse):Void 54 | { 55 | response.setHeader("Content-Type","text/plain"); 56 | response.writeHead(200); 57 | response.end('Hello World\\n'); 58 | }); 59 | server.listen(1337,"localhost"); 60 | 61 | trace( 'Server running at http://127.0.0.1:1337/' ); 62 | } 63 | } 64 | 65 | ``` 66 | 67 | 68 | ### Compile & run 69 | 70 | In terminal: 71 | 72 | ``` 73 | haxe -lib hxnodejs -js haxenode.js -main Haxenode 74 | node haxenode.js 75 | # Server running at http://127.0.0.1:1337/ 76 | ``` 77 | -------------------------------------------------------------------------------- /docs/haxenode/externs.md: -------------------------------------------------------------------------------- 1 | # Externs 2 | 3 | Tell something more about the externs 4 | [todo] [fixme] 5 | 6 | ### Haxe externs (NPM types for Haxe) 7 | 8 | 9 | 10 | ```bash 11 | haxelib git js-kit https://github.com/clemos/haxe-js-kit.git haxelib 12 | ``` 13 | 14 | [https://github.com/abedev/npm](https://github.com/abedev/npm) 15 | 16 | ```bash 17 | haxelib git npm https://github.com/abedev/npm 18 | ``` 19 | 20 | Documentation can be found [here](https://rawgit.com/abedev/npm/master/docs/index.html) 21 | 22 | ### Honorable mention 23 | 24 | I am not sure about how good these externs are. They have been converted from typescript to hx. 25 | 26 | > DefinitelyTyped repository converted with ts2hx 27 | 28 | But even they are not working a 100%, it's a really good place to start from. 29 | And it's **a lot of externs** 30 | 31 | - 32 | 33 | fixme 34 | -------------------------------------------------------------------------------- /docs/haxenode/installation.md: -------------------------------------------------------------------------------- 1 | # Installing 2 | 3 | Okay I don't want to mention this again, but you need to install Node.js and Haxe first (read more about that [here](download.md)) 4 | 5 | ## Install Node externs for Haxe 6 | 7 | The HaxeFoundation maintains the [hxnodejs](https://github.com/HaxeFoundation/hxnodejs) externs. 8 | 9 | Beside the node externs I suggest you install [https://github.com/clemos/haxe-js-kit](https://github.com/clemos/haxe-js-kit) as well. It has all the externs this documentation based upon. 10 | 11 | ## Install hxnodejs 12 | 13 | Install [hxnodejs](http://lib.haxe.org/p/hxnodejs) via haxelib: 14 | 15 | ```bash 16 | haxelib install hxnodejs 17 | ``` 18 | 19 | ## Install **js-kit** using haxelib: 20 | 21 | You install via git: 22 | 23 | ```bash 24 | haxelib git js-kit https://github.com/clemos/haxe-js-kit.git haxelib 25 | ``` 26 | 27 | Optional, check that js-kit installed correctly: 28 | 29 | ```bash 30 | haxelib list 31 | ``` 32 | 33 | Search for js-kit: 34 | 35 | ``` 36 | ... 37 | js-kit: git [dev:/usr/lib/haxe/lib/js-kit/git] 38 | ... 39 | ``` 40 | -------------------------------------------------------------------------------- /docs/haxenode/resource.md: -------------------------------------------------------------------------------- 1 | # Resources 2 | 3 | Extra information about Haxe, Node.js **and** the combination from the two. 4 | 5 | ### Haxe resources 6 | 7 | * [Haxe.org](http://haxe.org) 8 | * [Haxe api](http://haxe.org/api) 9 | * [Haxelib](http://lib.haxe.org/) 10 | * [Libraries & Frameworks](http://haxe.org/doc/libraries) 11 | * [Documentation & Tutorials](http://haxe.org/doc) 12 | 13 | ### Node.js resources 14 | 15 | * [Node.js](http://nodejs.org/) 16 | * [Node.js api](http://nodejs.org/docs/latest/api/) 17 | * [npm packages](http://search.npmjs.org/) 18 | * [Node.js mailing list](http://groups.google.com/group/nodejs) 19 | 20 | ### Haxe / node resources 21 | 22 | * [https://github.com/clemos/haxe-js-kit](https://github.com/clemos/haxe-js-kit). 23 | * [haxenode-js mailing list](https://groups.google.com/forum/#!forum/haxe-nodejs) 24 | * [http://www.sublimetext.com/](http://www.sublimetext.com/) 25 | * [Other IDE/Editors](http://haxe.org/com/ide) 26 | -------------------------------------------------------------------------------- /docs/haxenode/why.md: -------------------------------------------------------------------------------- 1 | # Why use Haxe? 2 | 3 | ### You can create apps using a single unified programming language. 4 | 5 | ## Use existing Haxe & JavaScript code 6 | You can take advantage of the many other Haxe, JavaScript, and node.js libraries such as JQuery, express, & mongo db. including many others from [Haxelib](href="http://lib.Haxe.org") 7 | 8 | ## JavaScript2 (ECMA4) features 9 | JavaScript2 promised a lot of great features for the future. Haxe provides a very similar experience now & is fully compatible with current browsers. 10 | 11 | ## Elegant Remoting between platforms 12 | Pass objects between different platforms using remoting classes from the same codebase. Successful de-serialization makes remoting between platforms elegant and fast. 13 | 14 | ## Benefits type checking 15 | Strict type checking & compile-time checks allows you to catch errors before testing in the browser or vm. This means a faster work-flow for dynamically typed targets (like JavaScript). 16 | 17 | ## ECMA style programming 18 | ECMA style programming for client-side, server-side & desktop. The Haxe syntax is familiar to those coming from ActionScript and JavaScript. 19 | 20 | ## Extremely fast compiling 21 | **It would be awesome to have proof!** -------------------------------------------------------------------------------- /docs/img/cover.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthijsKamstra/haxenode/6930b222e50c101c9639ac26b72996c69f343e0b/docs/img/cover.jpg -------------------------------------------------------------------------------- /docs/img/cover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthijsKamstra/haxenode/6930b222e50c101c9639ac26b72996c69f343e0b/docs/img/cover.png -------------------------------------------------------------------------------- /docs/img/cover_small.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthijsKamstra/haxenode/6930b222e50c101c9639ac26b72996c69f343e0b/docs/img/cover_small.jpg -------------------------------------------------------------------------------- /docs/img/haxe-logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/img/haxe_javascript_logos.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthijsKamstra/haxenode/6930b222e50c101c9639ac26b72996c69f343e0b/docs/img/haxe_javascript_logos.png -------------------------------------------------------------------------------- /docs/img/haxe_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthijsKamstra/haxenode/6930b222e50c101c9639ac26b72996c69f343e0b/docs/img/haxe_logo.png -------------------------------------------------------------------------------- /docs/img/haxe_nodejs_logos.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthijsKamstra/haxenode/6930b222e50c101c9639ac26b72996c69f343e0b/docs/img/haxe_nodejs_logos.png -------------------------------------------------------------------------------- /docs/img/haxe_php_logos.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthijsKamstra/haxenode/6930b222e50c101c9639ac26b72996c69f343e0b/docs/img/haxe_php_logos.png -------------------------------------------------------------------------------- /docs/img/haxe_python_logos.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthijsKamstra/haxenode/6930b222e50c101c9639ac26b72996c69f343e0b/docs/img/haxe_python_logos.png -------------------------------------------------------------------------------- /docs/img/helloworld.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthijsKamstra/haxenode/6930b222e50c101c9639ac26b72996c69f343e0b/docs/img/helloworld.png -------------------------------------------------------------------------------- /docs/img/install.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthijsKamstra/haxenode/6930b222e50c101c9639ac26b72996c69f343e0b/docs/img/install.jpg -------------------------------------------------------------------------------- /docs/img/javascript_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthijsKamstra/haxenode/6930b222e50c101c9639ac26b72996c69f343e0b/docs/img/javascript_logo.png -------------------------------------------------------------------------------- /docs/img/macdown-logo-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthijsKamstra/haxenode/6930b222e50c101c9639ac26b72996c69f343e0b/docs/img/macdown-logo-200.png -------------------------------------------------------------------------------- /docs/img/macdown-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthijsKamstra/haxenode/6930b222e50c101c9639ac26b72996c69f343e0b/docs/img/macdown-logo.png -------------------------------------------------------------------------------- /docs/img/markdown-logo-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthijsKamstra/haxenode/6930b222e50c101c9639ac26b72996c69f343e0b/docs/img/markdown-logo-200.png -------------------------------------------------------------------------------- /docs/img/markdown-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthijsKamstra/haxenode/6930b222e50c101c9639ac26b72996c69f343e0b/docs/img/markdown-logo.png -------------------------------------------------------------------------------- /docs/img/nodejs-light.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthijsKamstra/haxenode/6930b222e50c101c9639ac26b72996c69f343e0b/docs/img/nodejs-light.eps -------------------------------------------------------------------------------- /docs/img/nodejs_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthijsKamstra/haxenode/6930b222e50c101c9639ac26b72996c69f343e0b/docs/img/nodejs_logo.png -------------------------------------------------------------------------------- /docs/img/npm-logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/img/tldr.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthijsKamstra/haxenode/6930b222e50c101c9639ac26b72996c69f343e0b/docs/img/tldr.gif -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Haxe and Node.js 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /docs/level.md: -------------------------------------------------------------------------------- 1 | # Level of Difficulty 2 | 3 | I thought it would be useful to have some idea what sort of level the examples have here. 4 | 5 | 6 | How to define your level on a specific topic? 7 | 8 | - **Beginner:** No knowledge at all of the topic 9 | - **Basic:** A very basic knowledge of the topic but no professional usage 10 | - **Intermediate:** A basic knowledge of the topic but no regular professional usage 11 | - **Advanced:** A good knowledge of the topic and a regular professional usage 12 | - **Expert:** A perfect knowledge of the topic and a daily professional usage 13 | 14 | 15 | How does that translate to these examples? 16 | 17 | ## Beginner 18 | **No knowledge at all of the topic.** 19 | These examples start with the simplest code. 20 | But I don't think you will have any use of these examples without knowledge of Haxe or JavaScript. 21 | Start learning the basics of JavaScript and Haxe. 22 | To get you start I have a little chapter about [learning Haxe](haxe/learn-haxe.md). 23 | 24 | 25 | ## Basic 26 | **A very basic knowledge of the topic but no professional usage** 27 | 28 | * [Example Hello World](00helloworld/about.md) 29 | * [Example Writing](01writing/about.md) 30 | * [Example Reading](02reading/about.md) 31 | 32 | ## Intermediate 33 | **A basic knowledge of the topic but no regular professional usage** 34 | 35 | * [Example Lowdb](03lowdb/about.md) 36 | * [Example HaxeLow](04haxelow/about.md) 37 | * [Example Website](05website/about.md) 38 | * [Example NeDB](06nedb/about.md) 39 | 40 | ## Advanced 41 | **A good knowledge of the topic and a regular professional usage** 42 | 43 | * [Example Slack bot](09slackbot/about.md) 44 | * [Example Scraping](10scraping/about.md) 45 | * [Example Automation](11automation/about.md) 46 | * [Example Sockets](12socket/about.md) 47 | * [Example Sequelize](13sequelize/about.md) 48 | 49 | 50 | ## Expert 51 | **a perfect knowledge of the topic and a daily professional usage** 52 | 53 | Go away, you're done. 54 | 55 | ![](https://s-media-cache-ak0.pinimg.com/originals/4b/bc/13/4bbc13ea757ccbcf384279f40b6091d4.gif) 56 | 57 | ----- 58 | -------------------------------------------------------------------------------- /docs/resources/more.md: -------------------------------------------------------------------------------- 1 | # More more more!!!! 2 | 3 | So you want more... 4 | 5 | 6 | ## Haxe and Node.js 7 | 8 | ![Haxe logo](../img/haxe_nodejs_logos.png) 9 | 10 | [haxenode](http://matthijskamstra.github.io/haxenode/) 11 | 12 | ## Haxe and JavaScript 13 | 14 | ![Haxe logo](../img/haxe_javascript_logos.png) 15 | 16 | [haxejs](http://matthijskamstra.github.io/haxejs/) 17 | 18 | ## Haxe and PHP 19 | 20 | ![Haxe logo](../img/haxe_php_logos.png) 21 | 22 | [haxephp](http://matthijskamstra.github.io/haxephp/) 23 | 24 | ## Haxe and Python 25 | 26 | ![Haxe logo](../img/haxe_python_logos.png) 27 | 28 | [haxepython](http://matthijskamstra.github.io/haxepython/) 29 | 30 | -------------------------------------------------------------------------------- /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthijsKamstra/haxenode/6930b222e50c101c9639ac26b72996c69f343e0b/icon.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "haxenode", 3 | "version": "2.0.0", 4 | "description": "Documenting Haxe and Node.js", 5 | "scripts": { 6 | "deploy": "npm run git:commit && npm run git:push", 7 | "git:commit": "git add -A . && git commit -a -m 'update docs haxejs documentation'", 8 | "git:push": "git push", 9 | "docsify:init": "npm install && npm docsify", 10 | "docsify": "cd docs && docsify serve" 11 | }, 12 | "dependencies": { 13 | "docsify-cli": "^4.4.3" 14 | }, 15 | "repository": { 16 | "type": "git", 17 | "url": "git+https://github.com/MatthijsKamstra/haxenode.git" 18 | }, 19 | "keywords": [ 20 | "js", 21 | "haxe", 22 | "Haxe", 23 | "javascript", 24 | "node.js", 25 | "wip" 26 | ], 27 | "author": "Matthijs Kamstra aka [mck]", 28 | "license": "MIT", 29 | "bugs": { 30 | "url": "https://github.com/MatthijsKamstra/haxenode/issues" 31 | }, 32 | "homepage": "https://github.com/MatthijsKamstra/haxenode#readme" 33 | } 34 | --------------------------------------------------------------------------------