Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Node examples for ThisService <http://wafflesoftware.net/thisservice/>
#!/usr/local/bin/node
// ThisService node.js service script example, by Christian Eager
// Service type: Acts on input
//
// Node.js does *not* ship with OS X
// Download and installation instructions are available at http://nodejs.org
process.stdin.resume()
// Makes the data event emit a string instead of a Buffer
process.stdin.setEncoding('utf8')
var input = ""
process.stdin.on('data', function (chunk) {
input += chunk
})
process.stdin.on('end', function () {
// input now contains the contents of STDIN
// Write your script here
})
#!/usr/local/bin/node
// ThisService node.js service script example, by Christian Eager
// Service type: Filter
//
// Node.js does *not* ship with OS X
// Download and installation instructions are available at http://nodejs.org
process.stdin.resume()
// Makes the data event emit a string instead of a Buffer
process.stdin.setEncoding('utf8')
var input = ""
process.stdin.on('data', function (chunk) {
input += chunk
})
process.stdin.on('end', function () {
// input now contains the contents of STDIN
// Write your script here
// Be sure to print anything you want the service to output
})
#!/usr/local/bin/node
// ThisService node.js service script example, by Christian Eager
// Service type: Produces output
//
// Node.js does *not* ship with OS X
// Download and installation instructions are available at http://nodejs.org
// Write your script here
// Be sure to print anything you want the service to output
// e.g. process.stdout.write("Hello, world")
@matthewkremer

This comment has been minimized.

Show comment
Hide comment
@matthewkremer

matthewkremer Oct 9, 2014

I know that this was almost two years ago, but any idea why it's having problems with global includes?

If I have a node file with:

var mymodule = require("mymodule");

And I run node test.js it works fine, however, if I include that line in the "Acts on input.js" it doesn't work. Would appreciate any ideas you have :)

EDIT: Problem has to do with #!/usr/local/bin/node vs #!/usr/bin/env node. Script will only run if local, but in order to find globals, apparently can only run with env :(

matthewkremer commented Oct 9, 2014

I know that this was almost two years ago, but any idea why it's having problems with global includes?

If I have a node file with:

var mymodule = require("mymodule");

And I run node test.js it works fine, however, if I include that line in the "Acts on input.js" it doesn't work. Would appreciate any ideas you have :)

EDIT: Problem has to do with #!/usr/local/bin/node vs #!/usr/bin/env node. Script will only run if local, but in order to find globals, apparently can only run with env :(

@eager

This comment has been minimized.

Show comment
Hide comment
@eager

eager Oct 11, 2014

any idea why it's having problems with global includes?

@matthewkremer I’m not quite sure what you mean by global. Were they installed using npm install -g?

Problem has to do with #!/usr/local/bin/node vs #!/usr/bin/env node

I think the root of the need to hard-code the path to node, rather than using env, is that NSTask, which ThisService uses to spawn the scripts, doesn’t take the user’s environment (e.g., ~/.bashrc) into account. Looking into this issue further has been on my list of interesting things to solve for…the past two years.

Owner

eager commented Oct 11, 2014

any idea why it's having problems with global includes?

@matthewkremer I’m not quite sure what you mean by global. Were they installed using npm install -g?

Problem has to do with #!/usr/local/bin/node vs #!/usr/bin/env node

I think the root of the need to hard-code the path to node, rather than using env, is that NSTask, which ThisService uses to spawn the scripts, doesn’t take the user’s environment (e.g., ~/.bashrc) into account. Looking into this issue further has been on my list of interesting things to solve for…the past two years.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment