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

What to do if node server.js reports an error

藏色散人
Release: 2022-12-29 16:19:20
Original
2371 people have browsed it

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/');
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template