gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 03:22:10 25 4
gpt4 key购买 nike

我在 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

浏览器同步现在安装了吗?为什么我收到这么多警告?这应该是这样的吗?我是 Nodejs 新手...

最佳答案

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

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

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

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

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 的可选依赖项(想要 {"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'

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

关于node.js - ubuntu 16.04 上的 Nodejs - 正确安装 browser-sync gulp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48853786/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com