要求没有定义?的node.js [英] require is not defined? node.js
问题描述
在我的app / js文件中,我正在做类似这样的事情。
app.js
var http = require('http');
http.createServer(function(request,response){
response.writeHead(200,{'Content-Type':'text / plain'});
response。结束('我真的在运行服务器?!');
})。listen(8080,'127.0.0.1');
console.log('running server!');
当我在我的终端并运行 控制台吐出 但是在我的浏览器中, Can有人向我解释为什么在终端中,它工作正常,但在浏览器中,它不? 我使用npm http-server来为我的页面提供服务。 Node.JS是服务器端技术,而不是浏览器技术。 因此,节点特定的调用,如 请参阅 browserify 或 webpack 如果您希望为浏览器专用模块来自Node。 Started working with nodej.s In my app/js file, I am doing something like this app.js When I'm in my terminal and run The console spits out But in my browser i get, Can someone explain to me why in the terminal, it works correctly but in the browser, it doesnt? I am using npm http-server to serve my page. Node.JS is a server-side technology, not a browser technology. Thus, Node-specific calls, like See browserify or webpack if you wish to serve browser-specific modules from Node. 这篇关于要求没有定义?的node.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! node app.js < code $ $ b
'running server!'
未捕获的ReferenceError:require未定义
require()
,在浏览器中不起作用。
var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Am I really running a server?!');
}).listen(8080, '127.0.0.1');
console.log('running server!');
node app.js
'running server!'
Uncaught ReferenceError: require is not defined
require()
, do not work in the browser.