闲来无事下个nodejs玩
安装
Node.js安装教程及在vscode中的配置(超详细)_vscode nodejs-优快云博客
他的超详细我就不填了
然后到vscode部分 示例代码
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World\n');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
vscode本人是新手,所以发现无法编译 并提示
"launch.json" 找不到 Node.js 二进制文件“node”: 路径不存在。请确保 Node.js 已安装且位于你的路径中,或者在 launch.json 中设置 "runtimeExecutable"在launch.json中加入即可。
然后打开 launch.json 设置
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${file}",
"runtimeExecutable": "D:/Program Files/nodejs/node.exe" // Windows 示例
// "runtimeExecutable": "/usr/local/bin/node" // macOS/Linux 示例
}
]
}
或者打开设置搜索
- 找到vscode 设置
- 搜索 runtimeExecutable
- 点击 editInSettings.json
"debug.javascript.defaultRuntimeExecutable": {
"pwa-node": "D:/Program Files/nodejs/node.exe"
}
层主当时都用了,发现还是不行,结果是因为盘符反了 蠢爆了
比如"D:\Program Files\nodejs\node.exe" 错误
不过也是完成hello,world了