Doesn't print anything when executed in node #1

Closed
opened 2017-07-14 06:40:15 +00:00 by raghavgujjar · 1 comment
raghavgujjar commented 2017-07-14 06:40:15 +00:00 (Migrated from github.com)

I'm on node version 6.11. I'm just using the basic example PRINTJ.sprintf("Hello %s", SheetJS);

I save this code in a file and run node <filename>. Doesn't print anything. console.log however still prints something

I'm on node version 6.11. I'm just using the basic example `PRINTJ.sprintf("Hello %s", SheetJS)`; I save this code in a file and run `node <filename>`. Doesn't print anything. `console.log` however still prints something
reviewher commented 2017-07-14 06:56:35 +00:00 (Migrated from github.com)

sprintf and vsprintf don't actually print anything to console. They just return the resulting string. It's explained in the JS Interface section of the README:

Instead of replicating the original C signature and errno, functions directly return the output string and throw Errors:

The documentation shows examples from a REPL session, where the REPL evaluates and prints out the result. To run a REPL, just run node:

$ node
> require('printj').sprintf("Hello %s", "SheetJS")
'Hello SheetJS'

Running node with -pe arguments evaluates and prints the result:

$ node -pe 'require("printj").sprintf("Hello %s", "SheetJS")'
Hello SheetJS

Running from a file, you need to explicitly console.log.

$ cat test.js
var PRINTJ = require("printj");
var output = PRINTJ.sprintf("Hello %s", "SheetJS"); // <-- this line does not print to console
console.log(output); // <-- must be forced
$ node test.js
Hello SheetJS

The documentation is somewhat confusing. It has the > prompt to indicate that the commands were run in the REPL but it's not explained anywhere. If you have any thoughts for improving the docs, we'd love to improve them!

`sprintf` and `vsprintf` don't actually print anything to console. They just return the resulting string. It's explained in the [JS Interface](https://github.com/sheetjs/printj#js-interface) section of the README: > Instead of replicating the original C signature and `errno`, functions directly return the output string and throw Errors: The documentation shows examples from a REPL session, where the REPL evaluates and prints out the result. To run a REPL, just run `node`: ``` $ node > require('printj').sprintf("Hello %s", "SheetJS") 'Hello SheetJS' ``` Running node with `-pe` arguments evaluates and prints the result: ``` $ node -pe 'require("printj").sprintf("Hello %s", "SheetJS")' Hello SheetJS ``` Running from a file, you need to explicitly console.log. ``` $ cat test.js var PRINTJ = require("printj"); var output = PRINTJ.sprintf("Hello %s", "SheetJS"); // <-- this line does not print to console console.log(output); // <-- must be forced $ node test.js Hello SheetJS ``` The documentation is somewhat confusing. It has the `>` prompt to indicate that the commands were run in the REPL but it's not explained anywhere. If you have any thoughts for improving the docs, we'd love to improve them!
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/printj#1
No description provided.