NetBeans

Before using NetBeans for Node.js projects, you need to make sure that NetBeans is correctly configured, as shown below:

Create A NetBeans Project From An Existing Source

We can open an existing Node.js project folder in NetBeans. To do this, set up a new project that uses the option "Node.js Application with Existing Sources", as shown below.

Set the project name and location to match the projects folders, as shown below:

You can now use NetBeans to launch the index.html in debug mode. As shown in the image below, the NetBeans debug code does not run off port 3000. Instead, it runs from a NetBeans designated port (set to 8383 in the example below).

Create A New NetBeans Project

We can also use NetBeans to create a new Node.js project from scratch.

 

We shall skip the option of installing "express" via NetBeans. Instead, we shall install it using npm (see question 1 below).

Copy the index.html and server.js files from the "server_test" example into this project's folder. Install the "express" package into this project using the npm within the cmd window.

Run the server-side code (server.js) using npm.

Run index.html in debug mode within NetBeans.

NetBeans with Express

You need to install "express.cmd" before you can use "express" with NetBeans. To install "express.cmd" type the cmd line below:

npm install express-generator -g

When you run this command, it will identify the path where "express.cmd" has been installed. In the example below, the path where "express.cmd" will be stored is "C:\Users\Derek\AppData\Roaming\npm\express.cmd".

Once "express.cmd" has been installed, we can set up a NetBeans Express enable project. As with the previous example, we select the option "HTML/JS Application with Node.js".

Select a project name. In this example, I used the name "server_netbeans_with_express".

Select "Next" instead of selecting "Finish".

Check the "Enable Express" tab. The first time you do this, you will get the error message "Express must be selected".

Click on the "Options..." link to enable express.

You will see the window that is shown below.

Fill in the path name for the "Express.cmd" file. This was identified at the start of this section when you installed the "express.cmd" file.

Select the "Apply" and then the "OK" buttons. Then finish the installation.

Copy the "server.js" and "index.html" files into the "server_netbeans_with_express" project. Start the server and open the localhost:3000 in your browser. This will work. However, you should notice that the cmd output from the command "npm start" is more detailed than in our previous examples.

Try to run the file "index.html" from NetBeans. It will not work. Run the "server.js" file first and then run the file "index.html" again. It will now work. Notice that the url is now pointing to port 3000. This is the port that was declared in "server.js".

Remove the file "server.js" from the project. Restart the project in the cmd window and open the url "localhost:3000" in your browser. It should still work. Hint. The "npm start" cmd has been overwritten in the "package.json" file. Take a look inside "package.json" and try to identify which file is being called by the command "npm start".

Try to run the file "index.html" from inside NetBeans. It will not work. You must first run the server file that you will have identified in the previous question.

Including "Express" in the setting up of our project has resulted in the creation of a detailed template for a full Express application. We shall discuss the details of Express applations at a later stage in these notes.

 
<div align="center"><a href="../../versionC/index.html" title="DKIT Lecture notes homepage for Derek O&#39; Reilly, Dundalk Institute of Technology (DKIT), Dundalk, County Louth, Ireland. Copyright Derek O&#39; Reilly, DKIT." target="_parent" style='font-size:0;color:white;background-color:white'>&nbsp;</a></div>