Home  >  Article  >  Web Front-end  >  What to do if node server.js reports an error

What to do if node server.js reports an error

藏色散人
藏色散人Original
2022-12-29 16:19:202270browse

The node server.js error is because the path is incorrect. The solution is: 1. Enter the cmd window; 2. Switch to "server.js" under the project path; 3. Re-execute "node server.js" This command can solve the error problem.

What to do if node server.js reports an error

#The operating environment of this tutorial: Windows 10 system, node v10.16.0 version, Dell G3 computer.

What should I do if node server.js reports an error?

Specific problem description:

NodeJS running server.js error

I tested it with the sample code, how can I get an error?

var http = require('http');
http.createServer(function (request, response) {
    // 发送 HTTP 头部
    // HTTP 状态值: 200 : OK
    // 内容类型: text/plain
    response.writeHead(200, {'Content-Type': 'text/plain'});
    // 发送响应数据 "Hello World"
    response.end('Hello World\n');
}).listen(8000);
// 终端打印如下信息
console.log('Server running at http://127.0.0.1:8000/');

What to do if node server.js reports an error

Problem solution:

Found that the path is wrong!

First switch to server.js in the project path using cmd, and then node server.js can be accessed normally!

Recommended learning: "node.js Video Tutorial"

The above is the detailed content of What to do if node server.js reports an error. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn