roberto tomás roberto tomás - 3 years ago 328
Node.js Question

intellij idea setting up blank node.js project

I'm kinda new to intellij idea.

The node.js project template with intellij IDEA is a node.js express project — which is nice (you get web server hooked up to run your project with, etc), but with all sorts of ugly stuff in it like jade. I just want a no-frills, no nonsense node.js project... even http is optional.

I could see wanting a node.js project with basic web handling stuff like: body-parser, cookie-parser, serve-favicon, method-override, and morgan (which does http logging) — but that is really a bonus question/question for another day. Right now I just want a project template where I can press run afterwards and see the output on a console or something.

Answer Source

From my reckoning you currently have 2 choices:

1: Create an empty project and run the app using a Node.js interpreter.
This would mean going through the New Project wizard and selecting the Empty Project option. Then start developing your Node.js application.

When it comes to running the application, you'll need to define a new Run/Debug Configuration or edit one you might currently have.
When doing this, click the green + button, select Node.js.
From there you can name your configuration, ensure "Activate Tool Window" is checked and configure which JavaScript file is your main file (e.g. app.js).

This method can be a bit fiddly (especially at the beginning with folder/package creation) as you're not using a Node.js module so IntelliJ doesn't really know that you're trying to create a Node.js application.


2: Create an Node.js Express App, Clear it out and Save it as a Project Templat
First of all, go through the New Project wizard and create a Node.js Express App. Once your IDE has finished indexing and installing any Node.js packages it needs: Start deleting folders!
Node.js is designed to be used in a modular way so you can pretty much remove everything. I recommend deleting everything except for:

.idea/ because this is an IntelliJ thing and is needed.
node_modules/ because IntelliJ configures this as your library root so all future modules you use will be imported into this automatically. You can delete everything inside the node_modules/ directory though.
app.js because most Node.js application have a main JS file which is called app.js so you might as well keep this one. Still delete everything inside but keep the file.
<ProjectName>.iml because this is an IntelliJ thing and is needed.
package.json because this is your dependency management file. You can delete everything inside of the scripts and dependencies JSON objects.

Now if you're doing this in IntelliJ (i.e. NOT WebStorm) you have the option to save this as a Project Template.
This essentially means that when you come to developing your next Node.js application, instead of doing the above all over again, you can just select this custom template and get developing!.
To save the project as a Project Template, go to:

Tools > Save Project as Template...

Then fill in the boxes with whatever you want need/want and click OK.

If you're running WebStorm, you'll have to save the project somewhere (easily accessible folder, Github, etc.) and then make a clone/fork it when you want to develop a new application.


One of the important things to remember is that Node.js is still a pretty new language.

Express Apps are very common in the Node.js development world and so creating a Template/Framework for them is a simple, good business move for Jetbrains.

I'm sure (and on forums Jetbrains has indicated) that Jetbrains will continue to make more Node.js templates/frameworks supported on their IDE(s) but I suspect most will be added into WebStorm as that is their main IDE for JavaScript development.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download