Node.js Alert Causes Crash

Solution 1:

The alert() function is a property of browser window 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");

Solution 2:

alert() function is only available when you execute JavaScript in the special context of browser windows. It is available through the window 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.

  • Electron
  • NW.js (previously, node-webkit)

    NW.js is an app runtime based on Chromium and node.js. You can write native apps in HTML and JavaScript with NW.js. It also lets you call Node.js modules directly from the DOM and enables a new way of writing native applications with all Web technologies.

  • AppJS

    Available as an standalone distributable and an npm package


Meanwhile, you can use console.log() to output a message in Node.js.

console.log('hello');