Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 729
roberto tomás Avatar asked Mar 26 '16 15:03

roberto tomás


People also ask

How do I enable JavaScript in IntelliJ?

In the Settings/Preferences dialog ( Ctrl+Alt+S ), go to Languages & Frameworks | JavaScript. The JavaScript page opens. From the list, choose one of the supported JavaScript language versions: ECMAScript 5.1.

How to install Node JS in IntelliJ IDEA?

With IntelliJ IDEA, you can have several installations of Node.js and switch between them while working on the same project. Press Ctrl+Alt+S to open IDE settings and select Languages and Frameworks | Node.js and NPM. On the Node.js and NPM page that opens, select the required Node.js installation from the Node Interpreter list.

Can IntelliJ IDEA run on Windows Subsystem for Linux?

IntelliJ IDEA lets you run and debug Node.js applications using Node.js on Windows Subsystem for Linux. You can choose Node.js on WSL as the default interpreter for the current project or you can configure and use this node version in a Node.js Run/Debug configuration. Configure Node.js on WSL as the default project node interpreter

How do I create an empty project in IntelliJ IDEA?

To create an empty IntelliJ IDEA project Select from the main menu or click the New Project button on the Welcome screen. In the Project Category and Options dialog, which is the first page of the New Project wizard, select Static Web in the left-hand pane. In the right-hand pane, again select Static Web and click Next.

How do I set up a Node JS project?

In this Node.js tutorial, you’ll learn how to go about setting up a Node.js project. For creating a Node.js project you need to make sure you have Node installed and running in your system. For installing Node.js in Ubuntu you can follow the Node.js installing instructions from the official documentation.


1 Answers

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.

like image 187
Harmelodic Avatar answered Nov 07 '22 15:11

Harmelodic