Why "print" doesn't work in node.js?
Solution 1
The print
or window.print()
opens the Print Dialog to print the current document.
In Contrast, the console.log()
outputs a message to the Web Console.
If your intention was to actually print a file to a 'hardware printer', from Node.js then have a look at projects such as node-printer
.
Solution 2
window.print()
opens the printer dialog of the browser to print the current page. It does not print something to the console. See the mdn docs. Hence it is not what you expect.
Daniel
I write blogs in English https://preciselab.io and Polish https://gustawdaniel.com
Updated on June 24, 2022Comments
-
Daniel almost 2 years
I have
JavsScript
code with functionprint
. It works correctly in console of web browser, but when I run this code using node i obtain error:ReferenceError: print is not defined
Of course I can use
console.log
, but I would like to know whyprint
is not implemented innode
?-
Maxx almost 8 yearsProvide some code, please.
-
Daniel almost 8 yearsProgram with code:
print("test");
gives errorReferenceError: print is not defined at Object.<anonymous> (/home/daniel/print.js:1:63) at Module._compile (module.js:410:26) at Object.Module._extensions..js (module.js:417:10) at Module.load (module.js:344:32) at Function.Module._load (module.js:301:12) at Function.Module.runMain (module.js:442:10) at startup (node.js:136:18) at node.js:966:3
-
Jaromanda X almost 8 yearswhat does print do in the console of the browser for you? ... because global print in a browser sends the current page to a printer - not sure how this can translate to a node.js application - what exactly would that send to a printer?
-
Jaromanda X almost 8 years@Daniel - what would you like print to actually do?
-
Iceman almost 8 years@Daniel edit the code into your question, don't put them in comments.
-
Daniel almost 8 yearsThis has nothing to do with printing by printer. I study javascript from probably to old book... I checked that in other one only "colsole.log" is used... Any way I was interested only if print is depreciated or maybe there is other reason.
-
-
Quentin over 5 yearsThe question is asking why Node.js doesn't support the
print
function. Your answer is about installing SpiderMonkey (which is not Node.js) and doesn't mention theprint
function at all. Did you type your answer in the answer box on the wrong question? -
Quentin over 5 yearsThe question is asking why Node.js doesn't support the
print
function. Your answer is about installing SpiderMonkey (which is not Node.js) and doesn't mention theprint
function at all. Did you type your answer in the answer box on the wrong question? -
noobninja almost 4 yearsSpeaking of
console.log()
, was able to getconsole.log fooFunction(x)
(without braces) to print to terminal emulator using acoffeescript
interactive shell from the Debian repo. And usedcoffee
command to run a script.