{"id":18961587,"url":"https://github.com/pixiedust/pixiedust_node","last_synced_at":"2025-06-16T08:11:08.383Z","repository":{"id":47796339,"uuid":"90713379","full_name":"pixiedust/pixiedust_node","owner":"pixiedust","description":"Jupyter magic to allow Node.js code to run in a notebook","archived":false,"fork":false,"pushed_at":"2020-10-20T13:18:50.000Z","size":90,"stargazers_count":212,"open_issues_count":24,"forks_count":24,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-06-02T15:17:58.386Z","etag":null,"topics":["javascript","jupyter","nodejs","notebook","pixiedust-node"],"latest_commit_sha":null,"homepage":"https://medium.com/ibm-watson-data-lab/running-node-js-notebooks-in-watson-studio-a8f6545d8299","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pixiedust.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-09T07:03:10.000Z","updated_at":"2025-03-21T15:16:52.000Z","dependencies_parsed_at":"2022-09-05T22:22:04.488Z","dependency_job_id":null,"html_url":"https://github.com/pixiedust/pixiedust_node","commit_stats":null,"previous_names":["ibm-watson-data-lab/pixiedust_node"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/pixiedust/pixiedust_node","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pixiedust%2Fpixiedust_node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pixiedust%2Fpixiedust_node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pixiedust%2Fpixiedust_node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pixiedust%2Fpixiedust_node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pixiedust","download_url":"https://codeload.github.com/pixiedust/pixiedust_node/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pixiedust%2Fpixiedust_node/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260124097,"owners_count":22962207,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","jupyter","nodejs","notebook","pixiedust-node"],"created_at":"2024-11-08T14:13:32.252Z","updated_at":"2025-06-16T08:11:08.202Z","avatar_url":"https://github.com/pixiedust.png","language":"Python","readme":"# pixiedust_node\n\nPixieDust extension that enable a Jupyter Notebook user to invoke Node.js commands.\n\n![schematic](images/pixiedust_node_schematic.png)\n\n\n## How it works\n\nThe `pixiedust_node` Python module has access to Pixiedust's *display* API to render charts and maps. When `pixiedust_node` is imported into a notebook, a Node.js sub-process is setup and the notebook is configured so that cells beginning with '%%node' may contain JavaScript code: that code is piped to the Node.js sub-process automatically. The output of the Node.js process is parsed by `pixiedust_node` to handle the use of functions display/print/store/html/image. The `pixiedust_node` module also allows npm installs to be initiated from within the notebook. This achieved with further npm sub-processes whose output appears in the notebook. \n\n## Prerequisites\n\nTo use `pixiedust_node` you need to be running a Jupyter notebooks with the [Pixedust](https://github.com/pixiedust/pixiedust) extension installed. Notebooks can be run locally by [installing Pixiedust and its prerequisites](https://pixiedust.github.io/pixiedust/install.html).\n\n\nYou also need Node.js/npm installed. See the [Node.js downloads](https://nodejs.org/en/download/) page to find an installer for your platform.\n\n## Installation\n\nInside your Jupyter notebook, install *pixiedust_node*  with\n\n```python\n!pip install pixiedust_node\n```\n\n## Running\n\nOnce installed, a notebook can start up *pixiedust_node* with:\n\n```python\nimport pixiedust_node\n```\n\n## Using %%node\n\nUse the `%%node` prefix in a notebook cell to indicate that the content that follows is JavaScript.\n\n```js\n%%node\nprint(new Date());\n```\n\n## Installing npm modules\n\nYou can install any [npm](https://www.npmjs.com/) module to use in your Node.js code from your notebook. To install npm modules, in a Python cell:\n\n```python\nnpm.install('silverlining')\n```\n\nor install multiple libraries in one go:\n\n```python\nnpm.install( ('request', 'request-promise') )\n```\n\nand then \"require\" the modules in your Node.js code.\n\n```js\n%%node\nvar silverlining = require('silverlining');\nvar request = require('request-promise');\n```\n\nYou may also do :\n\n- `npm.uninstall('packagename')` - to remove an npm module (or `npm.remove('packagename')`)\n- `npm.list()` - to list the installed modules\n\n## Node.js helper functions\n\nNode.js functions are available to interact with the Notebook\n\n- `print(x)` - print out the value of variable x \n- `display(x)` - use Pixiedust's `display` function to visualise an array of data\n- `store(x,'y')` - turn a JavaScript array x into a Pandas data frame and store in Python variable y\n- `html(x)` - render HTML string x in a notebook cell\n- `image(x)` - render image URL x in a notebook cell\n- `help()` - show help\n\n### print\n\n```js\n%%node\n// connect to Cloudant using Silverlining\nvar url = 'https://reader.cloudant.com/cities';\nvar cities = silverlining(url);\n\n// fetch number of cities per country\ncities.count('country').then(print);\n```\n\n### display\n\n```js\n%%node\n\n// fetch cities called York\ncities.query({name: 'York'}).then(display);\n```\n\n### store\n\n** This function is deprecated as Node.js global variables are copied to the Python environment automatically **\n\n```js\n%%node\n\n// fetch the data and store in Pandas dataframe called 'x'\ncities.all({limit: 2500}).then(function(data) {\n  store(data, 'x');\n});\n```\n\nThe dataframe 'x' is now available to use in a Python cell:\n\n```python\nx['population'].sum()\n```\n\n### html\n\n```js\n%%node\nvar str = 'Sales are up \u003cb\u003e25%\u003c/b\u003e';\nhtml(str);\n```\n\n### image\n\n```js\n%%node\nvar url = 'http://myserver.com/path/to/image.jpg';\nimage(url);\n```\n\n### help\n\n```js\n%%node\nhelp();\n```\n\n## Node.js-Python bridge\n\nAny *global* variables that you create in your `%%node` cells will be automatically copied to equivalent variables in Python. e.g if you create some variables in a Node.js cell:\n\n```\n%%node\nvar str = \"hello world\";\nvar n1 = 4.1515;\nvar n2 = 42;\nvar tf = true;\nvar obj = { name:\"Frank\", age: 42 };\nvar array_of_strings = [\"hello\", \"world\"];\nvar array_of_objects = [{a:1,b:2}, {a:3, b:4}];\n```\n\nThen these variables can be used in Python:\n\n```\n# Python cell\nprint str, n1, n2, tf\nprint obj\nprint array_of_strings\nprint array_of_objects\n```\n\nStrings, numbers, booleans and arrays of such are converted to their equivalent in Python. Objects are converted into Python dictionaries and arrays of objects are automatically converted into a Pandas DataFrames.\n\nNote that only variables declared with `var` are moved to Python, not constants declared with `const`.\n\n\nIf you want to move data from an asynchronous Node.js callback, remember to write it to a *global variable*:\n\n```js\n%%node\nvar googlehomepage = '';\nrequest.get('http://www.google.com').then(function(data) {\n  googlehomepage = data;\n  print('Fetched Google homepage');\n});\n```\n\nSimilarly, Python variables of type `str`, `int`, `float`, `bool`, `unicode`, `dict` or `list` will be moved to Node.js when a cell is executed:\n\n```\n# Python cell\na = 'hello'\nb = 2\nb = 3\nc= False\nd = {}\nd[\"x\"] = 1\nd[\"y\"] = 2\ne = 3.142\n```\n\nThe variables can then be used in Node.js:\n\n```\n%%node\nconsole.log(a,b,c,d,e);\n// hello 3 false { y: 2, x: 1 } 3.142\n```\n\n## Managing the Node.js process\n\nIf enter some invalid syntax into a `%%node` cell, such as code with more opening brackets than closing brackes, then the Node.js interpreter may not think you have finished typing and you receive no output.\n\nYou can cancel execution by running the following command in a Python cell:\n\n```python\nnode.cancel()\n```\n\nIf you need to clear your Node.js variables and restart from the beginning then issue the following command in an Python cell:\n\n```python\nnode.clear()\n```\n\n## Help\n\nYou can view the help in a Python cell:\n\n```python\nnode.help()\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpixiedust%2Fpixiedust_node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpixiedust%2Fpixiedust_node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpixiedust%2Fpixiedust_node/lists"}