Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 无法运行node server.js_Node.js - Fatal编程技术网

Node.js 无法运行node server.js

Node.js 无法运行node server.js,node.js,Node.js,我正在使用上面的代码创建一个简单的服务器 但当我运行它时,我会出错 Nileshs MacBook Pro:azureSocketServer njha$node server.js 内部/modules/cjs/loader.js:796 犯错误; ^ 错误:找不到模块“/Users/njha/Documents/AzureSample/azureSocketServer/server.js” 在Function.Module.\u解析文件名(internal/modules/cjs/load

我正在使用上面的代码创建一个简单的服务器

但当我运行它时,我会出错

Nileshs MacBook Pro:azureSocketServer njha$node server.js 内部/modules/cjs/loader.js:796 犯错误; ^

错误:找不到模块“/Users/njha/Documents/AzureSample/azureSocketServer/server.js” 在Function.Module.\u解析文件名(internal/modules/cjs/loader.js:793:17) at Function.Module._load(内部/modules/cjs/loader.js:686:27) 位于Function.Module.runMain(internal/modules/cjs/loader.js:1043:10) 在internal/main/run\u main\u module.js:17:11{ 代码:“未找到模块”, requireStack:[] }

我的文件夹结构。

我这边没有错误,您使用的是哪个版本的node?我们可以看到更多的stacktrace吗?需要更多的描述请现在查看。。节点版本(12.14.1),所以您需要运行
Node src/server.js
@NileshJha您发布的代码就是
server.js
文件中的所有内容吗?
const http = require('http');

// Create an instance of the http server to handle HTTP requests
let app = http.createServer((req, res) => {
    // Set a response type of plain text for the response
    res.writeHead(200, {'Content-Type': 'text/plain'});

    // Send back a response and end the connection
    res.end('Hello World!\n');
});

// Start the server on port 3000
app.listen(3000, '127.0.0.1');
console.log('Node server running on port 3000');