How to run the node.js file in net beans?

In net beans i have installed node.js pulgin.But my sample node program is not working.Im getting error. This is my sample code

    var http = require("http");
    http.createServer(function (req, res) {
    res.writeHead(200, {"Content-Type": "text/plain"});

    res.end("Hai! welcome to node.js...!\n");

      }).listen(3030, "localhost");



   console.log("Server running at http://127.0.0.1:3030/");/* 

While running the above program.Im getting following error.

                  module.js:340
                 throw err;
                     ^
         Error: Cannot find module 'C:\Program Files\NetBeans 7.0.1\hello.js'
        at Function.Module._resolveFilename (module.js:338:15)
        at Function.Module._load (module.js:280:25)
        at Function.Module.runMain (module.js:497:10)
        at startup (node.js:119:16)
        at node.js:903:3

But the above program works from the terminal.

From my knowledge, currently there are 2 netbeans plugins for Node.js

The one you're using http://plugins.netbeans.org/plugin/36653/nodejs

(very simple plugin, it doesn't do much (I used it on an older version of netbeans), and I can't get it to work on netbeans 7.4)

and a second one:

NetBeans NodeJS Plugin https://github.com/timboudreau/nb-nodejs

I want to suggest that you switch to the second one, because:

  • it actually works
  • it provides a "node project type"
  • more

Netbeans Node support does not appear quite ready for prime time. Problem: the "standard" (danielkec) Node plugin does not know about projects, so you will have to create a bogus (Html5??) project to use it. Problem2: Tim Boudreau's Node plugin does nicely with project creation and code completion but it has zero support for debugging (Tim prefers inserting print statements in the code). So at this point (Netbeans 8), I would not recommend Netbeans for Node.js work.

Your Node code looks fine. Have you really created the hello.js file in the NetBeans folder as it looks like Node cannot find the file in this folder?

If you go to the node options in NetBeans, you need to make sure you are changing directory to the folder that contains your application source. This is done in NetBeans by setting the "Default Run Command" to be something like:

cd ${workingdir};

/usr/local/bin/node ${selectedfile};

Where you need to set the path to node as appropriate.

In NetBeans go to Tools >> Options >> Miscellaneous >> Node.js

and change default command to

node ${workingdir}\${selectedfile}

In NetBeans go to Tools >> Options >> Miscellaneous >> Node.js

and change default command to:

node ${workingdir}\${selectedfile}

You should also add lessc file path to your netbeans. In netbeans go to:

Tools >> Options >> Miscellaneous >> CSS Preprossessors

And add path to your node lessc file path.

It will be located in C:\Users\{your user name}\AppData\Roaming\npm\lessc.cmd

If it is not found then you have to install it by command prompt by following code:

npm install less -g