ubuntu 16.04上的Nodejs - 正确安装browser-sync gulp

时间:2018-02-18 16:14:57

标签: node.js apache ubuntu-16.04

我在ubuntu 16.04上安装了nodejs,如下所示:

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-16-04

我在apache上运行它。

我的第一个应用程序hello.js(保存在/ var / www / html / nodejs /中)是:

#!/usr/bin/env nodejs
var http = require('http');
http.createServer(function (request, response) {
   response.writeHead(200, {'Content-Type': 'text/plain'});
   response.end('Hello World! Node.js is working correctly!\n');
}).listen(8080);
console.log('Server running at http://localhost:8080/');

当我进入浏览器http://localhost:8080/时,我得到:

Hello World! Node.js is working correctly! 

现在我想安装浏览器同步,如下所示:

Using browser-sync with node.js app

但是当我跑步时:

$ sudo npm install browser-sync gulp --save-dev

我得到以下内容:

npm WARN registry Using stale data from https://registry.npmjs.org/ because the host is inaccessible -- are you offline?
npm WARN registry Using stale package data from https://registry.npmjs.org/ due to a request error during revalidation.
npm WARN deprecated gulp-util@3.0.8: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
npm WARN deprecated graceful-fs@3.0.11: please upgrade to graceful-fs 4 for compatibility with current and future versions of Node.js
npm WARN deprecated minimatch@2.0.10: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated minimatch@0.2.14: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated graceful-fs@1.2.3: please upgrade to graceful-fs 4 for compatibility with current and future versions of Node.js

> uws@9.14.0 install /home/sven/node_modules/uws
> node-gyp rebuild > build_log.txt 2>&1 || exit 0

sh: 1: cannot create build_log.txt: Permission denied
npm WARN saveError ENOENT: no such file or directory, open '/home/sven/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/home/sven/package.json'
npm WARN sven No description
npm WARN sven No repository field.
npm WARN sven No README data
npm WARN sven No license field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"ia32"})

+ browser-sync@2.23.6
+ gulp@3.9.1
added 547 packages in 57.958s

现在是否已安装浏览器同步?为什么我得到这么多WARN?这个假设是这样的吗?我是nodejs的新手......

2 个答案:

答案 0 :(得分:2)

不要在sudo本地安装模块。决不。这是不必要的,它会导致权限错误。相反,你应该使用:

$ npm install browser-sync gulp --save-dev

安装节点模块时,警告非常典型。提供的是为了帮助您在出现任何错误时进行调试。

其中一些通知您模块依赖于已弃用的依赖项:

npm WARN deprecated gulp-util@3.0.8: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
npm WARN deprecated graceful-fs@3.0.11: please upgrade to graceful-fs 4 for compatibility with current and future versions of Node.js
npm WARN deprecated minimatch@2.0.10: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated minimatch@0.2.14: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated graceful-fs@1.2.3: please upgrade to graceful-fs 4 for compatibility with current and future versions of Node.js

但这是包开发人员的问题。你可以忽略那部分。

其他人告诉您有关跳过可选依赖项的信息:​​

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"ia32"})

此警告表示npm未安装fsevents。但是你不应该关心它,因为它是OS X的可选依赖项(wanted {"os":"darwin","arch":"any"}; darwin是OS X的代码名称。)

所以你可以忽略大多数警告。

但这是日志的重要部分:

sh: 1: cannot create build_log.txt: Permission denied

主页目录中可能存在一些权限问题。

npm WARN saveError ENOENT: no such file or directory, open '/home/sven/package.json'

在这里,我可以看到您尝试从主目录安装软件包。在项目目录中安装本地依赖项。在这种情况下,您应该在npm install browser-sync gulp --save-dev中使用/var/www/html/nodejs/,而不是/home/sven/

npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/home/sven/package.json'
npm WARN sven No description
npm WARN sven No repository field.
npm WARN sven No README data
npm WARN sven No license field.

这些警告意味着您的主目录文件package.json不存在。首先,从项目目录中安装本地包。其次,使用$ npm init初始化项目目录中的包是个好主意。

答案 1 :(得分:1)

回答你的问题:

  

现在是否已安装浏览器同步?

是的,已安装,要确认,您可以运行browser-sync --version gulp --version。这应该显示您安装的版本,因为它已经显示在您的日志中

  
      
  • browser-sync@2.23.6
  •   
  • gulp@3.9.1
  •   

正如您从日志中看到的那样,它们只是警告,它不会阻止您的模块正常运行。

  

npm WARN注册表使用https://registry.npmjs.org/中的陈旧数据,因为主机无法访问 - 您是否处于离线状态?   npm WARN注册表由于重新验证期间发生请求错误,使用来自https://registry.npmjs.org/的陈旧包数据。   npm WARN弃用了gulp-util@3.0.8:不推荐使用gulp-util - 按照https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5的指导原则替换它   npm WARN弃用graceful-fs@3.0.11:请升级到graceful-fs 4以兼容当前和未来版本的Node.js   npm WARN弃用minimatch@2.0.10:请更新到minimatch 3.0.2或更高版本以避免RegExp DoS问题   npm WARN弃用minimatch@0.2.14:请更新到minimatch 3.0.2或更高版本以避免RegExp DoS问题   npm WARN弃用graceful-fs@1.2.3:请升级到graceful-fs 4以兼容当前和未来版本的Node.js

     

uws@9.14.0 install / home / sven / node_modules / uws   node-gyp rebuild> build_log.txt 2>& 1 ||退出0

它们基本上是不推荐使用的模块,由Browsersync使用。

  

sh:1:无法创建build_log.txt:权限被拒绝   npm WARN saveError ENOENT:没有这样的文件或目录,打开'/home/sven/package.json'   npm notice创建了一个lockfile作为package-lock.json。你应该提交这个文件。   npm WARN enoent ENOENT:没有这样的文件或目录,打开'/home/sven/package.json'   npm WARN sven没有描述   npm WARN sven没有存储库字段。   npm WARN sven没有README数据   npm WARN sven没有许可证字段。   npm WARN可选SKIPPING OPTIONAL DEPENDENCY:fsevents@1.1.3(node_modules / fsevents):   npm WARN notsup SKIPPING OPTIONAL DEPENDENCY:不支持的fsevents@1.1.3平台:想要{“os”:“darwin”,“arch”:“any”}(当前:{“os”:“linux”,“arch”: “IA32”})

是许可的事情。可能

  • 该目录启用了不可变标志。或

  • 使用只读权限挂载目录。

或其他一些原因。

我希望这会有所帮助。