I'm trying to create a node.js app and
alert('Sample Alert');
is causing my program to crash. Node says
ReferenceError: alert is not defined
and then quits. I can use the alert
function when running javascript on a regular html page, so I'm at a loss to understand why this is... Is this a separate module that I have to use with node.js?
Thanks in advance.
The
alert()
function is a property of browserwindow
objects. It is not really part of JavaScript; it's just a facility available to JavaScript code in that environment.Try
console.log("Hello World");
While these answers are "correct", as there is no alert function available outside of the browser, there's no reason you can't create one and then use it:
results:
Then you might not need to change your existing code or example or whatever.
You'll also need code to wait for a key. Here's a start:
The alert() property is only allowed by browsers not javascript.
alert()
function is only available when you execute JavaScript in the special context of browser windows. It is available through thewindow
object.Node.js is not intended for writing desktop applications (directly). It is mainly intended for writing server-side JavaScript applications. You can use following frameworks/packages (and many more) if you want to develop true desktop applications.
NW.js (previously, node-webkit)
AppJS
Meanwhile, you can use
console.log()
to output a message in Node.js.alert function is for browsers. means front end..in nodejs for printing in cmd or bash you should use this one..
you can print any variable or constant here... for printing variables just remove comma..