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.
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
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
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.
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
$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:
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.
You can use Express Application Generator. You can generate app skeleton quickly and you have many option to select template engine like jade, ejs, hbs & more.
npm install express-generator -g
After that, express [AppName] and open into Intellij.