intellij idea setting up blank node.js project

18,002

Solution 1

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 Template
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.

Solution 2

What you see by default ("body-parser", "cookie-parser", "debug", "express", "jade", "morgan", "serve-favicon") are all npm dependencies, so you can remove them using npm as well.

Complementing @Harmelodic answer, first remove these dependencies one by one:

Assuming you already have npm installed in your system (comes with NodeJS), go to your project root folder:

$ cd my/project/folder

Then use npm uninstall:

$npm uninstall body-parser
$npm uninstall cookie-parser
$npm uninstall debug
... etc.

After removing all the dependencies, you will see the "dependencies" JSON object of the project.json file empty:

"dependencies": {}

Also, the node_modules folder will be emty, and the package-lock.json file will be just a skeleton.

After this create your project template.

Share:
18,002

Related videos on Youtube

roberto tomás
Author by

roberto tomás

I am working on courseware and certifications for language.

Updated on June 18, 2022

Comments

  • roberto tomás
    roberto tomás almost 2 years

    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.

  • Harmelodic
    Harmelodic about 8 years
    The question explicitly states: 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. Why would this be an acceptable answer?
  • roberto tomás
    roberto tomás about 8 years
    I want to mark this as the answer. would you change #1 to say "edit the run/debug configuration" to set that up. Click the "+" plus icon to add a new configuration, and select node.js from there. Configure the javascript file to run to be the main app, like app.js. Ensure "Activate Tool Window" is checked. And name the configuration.