Node.js Can';不运行这个nodejs代码吗?
我试着运行这个简单的代码,但我总是出错…我真的不知道是什么问题。我觉得很好。。。?谢谢Node.js Can';不运行这个nodejs代码吗?,node.js,Node.js,我试着运行这个简单的代码,但我总是出错…我真的不知道是什么问题。我觉得很好。。。?谢谢 var http = require(http); console.log('Starting'); var host = '127.0.0.1'; var port = 1337; var server = http.createServer(function(request, response){ console.log('Receive
var http = require(http);
console.log('Starting');
var host = '127.0.0.1';
var port = 1337;
var server = http.createServer(function(request, response){
console.log('Receive request: '+ request.url);
response.writeHead(200, {"Content-type" : "text/plain"});
response.end("Hello world");
});
server.listen(port, host, function(){
console.log('Listening: ' + host + ':' + port);
});
控制台错误如下:
assert.js:98
throw new assert.AssertionError({
^
AssertionError: path must be a string: path must be a string
at Module.require (module.js:362:3)
at require (module.js:380:17)
at Object.<anonymous> (/Users/yoniPacheko/PhpstormProjects/angularJS/nodeJS/server.js:9:12)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3
assert.js:98
抛出新的assert.AssertionError({
^
AssertionError:path必须是字符串:path必须是字符串
at Module.require(Module.js:362:3)
根据需要(模块js:380:17)
在对象上。(/Users/yoniPacheko/PhpstormProjects/angularJS/nodeJS/server.js:9:12)
在模块处编译(Module.js:456:26)
在Object.Module.\u extensions..js(Module.js:474:10)
在Module.load(Module.js:356:32)
在Function.Module.\u加载(Module.js:312:12)
位于Function.Module.runMain(Module.js:497:10)
启动时(node.js:119:16)
在node.js:901:3
在您的第一行中,http周围缺少引号:
var http = require('http');
就我而言,我有
var http = require('http');
var path= require('path');
我一删除http线路,它就对我起作用了。所以,我只留下了
var path=require('path')
我在处理express、mongodb和socket.io