我使用 nitrous.io 创建了一个 Node 环境。我在他们的终端内部安装了 yeoman 。
如果我尝试运行 grunt server
我收到一条错误消息:
Fatal error: Unable to find local grunt.
If you're seeing this message, either a Gruntfile wasn't found or grunt
hasn't been installed locally to your project. For more information about
installing and configuring grunt, please see the Getting Started guide:
http://gruntjs.com/getting-started
如果我去预览而不是连接到端口 3000,我会得到这个
引用状态 Node 将 127.0.0.1 或“localhost”更改为 0.0.0.0
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(3000, '0.0.0.0');
console.log('Server running at http://0.0.0.0:3000/');
Grunt 语法对于服务器来说有点不同
connect: {
options: {
port: 3000,
// Change this to '0.0.0.0' to access the server from outside.
hostname: '0.0.0.0' //
},
即使进行此更改后,错误仍然存在。当我运行 grunt server
或转到预览端口 3000
关于我做错了什么有什么想法吗?如何运行我的 grunt 服务器以便我可以在浏览器中看到我的网站?
最佳答案
您是否仔细阅读了收到的第一条错误消息的建议?您需要 Gruntfile.js
和 package.json
(Grunt 列为依赖项); this is covered in the official documentation 。然后,通过运行 npm install
您将能够将本地 Grunt 拉到您的项目中。
关于node.js - Grunt 服务器在 Nitrous.io 中无法工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18670812/