node.js - Grunt 服务器在 Nitrous.io 中无法工作

标签 node.js angularjs gruntjs yeoman nitrousio

我使用 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,我会得到这个

error message

引用状态 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.jspackage.json (Grunt 列为依赖项); this is covered in the official documentation 。然后,通过运行 npm install 您将能够将本地 Grunt 拉到您的项目中。

关于node.js - Grunt 服务器在 Nitrous.io 中无法工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18670812/

相关文章:

node.js - 集群工作人员不在 Debug模式下监听

javascript - Angular.js : change a class with ng-class and a click function

node.js - Grunt watch正在运行 "watch"任务正在等待

javascript - 语法错误 : Unexpected token function

javascript - 为什么 fs.js 返回 [object Object] 并关闭我的机器人?

css - 单击以缩放使用 ng-repeat 创建的 div

javascript - 如何将选择 "text"的 SELECT 框发送到按钮上的函数以使用 angular 进行 ng-click?

node.js - 是否可以使用 grunt js 和/或 less css 将所有 css 放在一行中?

javascript - 如何用 grunt 替换副本上的模板变量?

javascript - svelte electron 中的 JS 文件中不能需要 Node 模块