Skip to content

Commit

Permalink
Add sample helloworld code
Browse files Browse the repository at this point in the history
  • Loading branch information
isc-ddo committed Feb 28, 2019
0 parents commit b1b7981
Show file tree
Hide file tree
Showing 19 changed files with 132 additions and 0 deletions.
13 changes: 13 additions & 0 deletions HelloWorld.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const irisnative = require('intersystems-iris-native')

var host = "localhost"
var port = 51773
var namespace = "USER"
var username = "SuperUSer"
var password = "SYS"

const connection = irisnative.createConnection(
{host:host, port:port, ns:namespace, user:username, pwd:password}
)
const iris = connection.createIris()
console.log("Hello World! You have successfully connected to InterSystems IRIS via NodeJS.")
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 InterSystems Corporation

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Samples-nodejs-helloworld
Simple hello world code to show a Node.js connection to InterSystems IRIS
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
47 changes: 47 additions & 0 deletions intersystems-iris-native/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
var native = null;

if(process.platform == "win32" && process.arch == "x64") {
// winx64
native = require('./bin/winx64/irisnative.node');
} else if (process.platform == "win32" && process.arch == "ia32") {
native = require('./bin/winx86/irisnative.node');
} else if (process.platform == "darwin") {
native = require('./bin/macx64/irisnative.node');
} else if (process.platform == "linux") {
let distro = getLinuxDistro()
console.log('platform = ' + process.platform + ': ' + distro)
if (distro == 'ubuntu') {
native = require('./bin/lnxubuntux64/irisnative.node');
} else if (distro = 'fedora') {
native = require('./bin/lnxrhx64/irisnative.node');
} else if (distro == 'rhx64') {
native = require('./bin/lnxrhx64/irisnative.node');
} else {
// test for AIX?
native = require('./bin/ppcx64/irisnative.node');
}
}

function getLinuxDistro() {
const { execSync } = require('child_process');
try {
let distro = execSync('lsb_release -is',{encoding:'utf8',stdio:'pipe'});
return distro.replace(/(\r\n\t|\n|\r\t)/gm,"").toLowerCase();
} catch (e) {
return getDistroFromFile();
}
}

function getDistroFromFile() {
const fs = require('fs')
try {
let osv = fs.readFileSync('/etc/os-release','utf8');
let lines = osv.split('\n');
let distro = lines.find((element) => { return element.substring(0,element.indexOf('=')) == 'ID' })
return distro.substring(3);
} catch (e) {
return null;
}
}

module.exports = native;
16 changes: 16 additions & 0 deletions intersystems-iris-native/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "intersystems-iris-native",
"version": "1.0.0",
"description": "InterSystems IRIS Native API for Node.js",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"files": [
"bin"
],
"author": "",
"repository": "",
"license": "ISC"
}

11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "Samples_nodejs_helloworld",
"version": "1.0.0",
"description": "First, clone the repo. You will have two items:\r 1. `HelloWorld.js`: Sample Node.js file to connect to InterSystems\r 2. `intersystems-iris-native`: InterSystems module for NodeJS",
"main": "HelloWorld.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/intersystems/Samples-nodejs-helloworld.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/intersystems/Samples-nodejs-helloworld/issues"
},
"homepage": "https://github.com/intersystems/Samples-nodejs-helloworld#readme",
"dependencies": {
"intersystems-iris-native": "file:intersystems-iris-native"
}
}

0 comments on commit b1b7981

Please sign in to comment.