【Tool】IntelliJ 搭建Node.js环境

IntelliJ IDEA 开发 Node.js


2019-07-29  14:12:34  by冲冲

1. 配置插件

在IDEA的 file -> setting -> Plugins,右边手动输入“node.js”搜索,然后点击下载,安装完成后要求重启。

注意:存在 Intellij IDEA 汉化之后无法打开“设置(T)...”的问题

解决方案参考 https://jingyan.baidu.com/article/fb48e8bef2bcb66e622e14d2.html

① 前往Intellij安装包的lib文件夹下,找到汉化文件(resources_cn.jar),用压缩软件打开(不用解压缩)。

② 将其messages文件夹内的 IdeBundle.properties(系统设置(setting)外观选项加载不出来)、VcsBundle.properties(系统设置(setting)打不开)、UIBundle.properties(定位按钮找不到) 这三个配置文件删除就可以解决对应问题。

③ 删除后关闭,确保jar文件还在lib目录下,启动Intellij IDEA。

2. Demo测试

① 点击新建项目,提供node的2个选项: Node.js 基础模板 和 Node.js Express App 网站

② 创建server.js文件

var http = require("http");
http.createServer(function(request, response) {
    response.writeHead(200, {"Content-Type": "text/plain"});
    response.write("Hello World");
    response.end();
}).listen(8888);
console.log("nodejs start listen 8888 port!");

③ 完成 Run/Debug 配置

注意:存在 Intellij IDEA 汉化之后无法正常使用 “编辑结构...(R)” 的问题

解决参考 https://blog.csdn.net/atomjob/article/details/89462096

① 前往Intellij安装包的lib文件夹下,找到汉化文件(resources_cn.jar),用压缩软件打开(不用解压缩)。

② 将其messages文件夹内的 ExecutionBundle.properties 删除。

③ 删除后关闭,确保jar文件还在lib目录下,启动Intellij IDEA。

填写需要运行的JS文件

3. 运行

控制台输出 node js start listen 8888 port! ,则成功。

打开页面  http://127.0.0.1:8888 或者 localhost:8888 可以看到结果。

参考:https://www.cnblogs.com/duhuo/p/4217083.html

原文地址:https://www.cnblogs.com/yadiel-cc/p/11263860.html