• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

节点js服务器不启动

node.js 来源:Joseph Charles 3次浏览

我是节点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); 
}); 

版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)