节点js服务器不启动

我是节点js的新手。刚开始学习节点js。当我创建自己的服务器时,它不会初始化。有人可以帮我解决这个错误。节点js服务器不启动

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!');

});

server.listen(port, hostname,() => {

console.log('server started on port '*port);

});

错误:

C:\test\app.js:1 

(function (exports, require, module, __filename, __dirname) { const http * requi

re('http');

^^^^

SyntaxError: Missing initializer in const declaration

at createScript (vm.js:80:10)

at Object.runInThisContext (vm.js:152:10)

at Module._compile (module.js:605:28)

at Object.Module._extensions..js (module.js:652:10)

at Module.load (module.js:560:32)

at tryModuleLoad (module.js:503:12)

at Function.Module._load (module.js:495:3)

at Function.Module.runMain (module.js:682:10)

at startup (bootstrap_node.js:191:16)

at bootstrap_node.js:613:3

回答:

变化*=

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!');

});

server.listen(port, hostname,() => {

console.log('server started on port ', port);

});

回答:

这个 '=' 操作起来再努力一次,并运行代码..

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!');

});

server.listen(port, hostname,() => {

console.log('server started on port '*port);

});

以上是 节点js服务器不启动 的全部内容, 来源链接: utcz.com/qa/262442.html

回到顶部