0

I installed nodejs on ubuntu 16.04 like this:

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

I run it on an apache though.

My first application hello.js (saved in /var/www/html/nodejs/) is:

#!/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/');

When I enter in the browser http://localhost:8080/ I get:

Hello World! Node.js is working correctly! 

Now I want to install browser-sync like suggested here:

Using browser-sync with node.js app

But when I run:

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

I get the following:

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 [email protected]: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
npm WARN deprecated [email protected]: please upgrade to graceful-fs 4 for compatibility with current and future versions of Node.js
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated [email protected]: please upgrade to graceful-fs 4 for compatibility with current and future versions of Node.js

> [email protected] 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: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"ia32"})

+ [email protected]
+ [email protected]
added 547 packages in 57.958s

Is browser-sync now installed? And why am I getting so many WARN? Is this suppose to be like this? I'm new to nodejs ...

1
  • Yea, it is installed.
    – antzshrek
    Feb 18, 2018 at 17:12

2 Answers 2

2

Do not install modules locally with sudo. Never. It's unnecessary and it'll cause permissions errors. Instead, you should use:

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

Warnings are pretty typical when you install node modules. There are provided in order to help you debug in case of any errors.

Some of them inform you that module depends on deprecated dependencies:

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

But this is an issue of package developer. You can ignore that part.

Others inform you about skipped optional dependency:

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

This warning mean that npm didn't install fsevents. But you shouldn't care about that because it's the optional dependency for OS X (wanted {"os":"darwin","arch":"any"}; darwin is code name of OS X).

So you can ignore most of warnings.

But here is an important part of logs for you:

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

Probably you have some permissions issue in the home directory.

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

Here I can see that you tried to install packages from your home directory. Install local dependencies in the project directory. In this case you should use npm install browser-sync gulp --save-dev in /var/www/html/nodejs/, not in /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.

Those warnings means that in your home directory file package.json don't exist. First, install local packages from your project directory. Second, it is a good idea to initialize package in your project directory with $ npm init.

5
  • Thanks for the explanation. Since I already installed it with sudo ... should I remove it first and then install it in the project folder /var/www/html/nodejs/ ?
    – Philipp M
    Feb 18, 2018 at 18:29
  • and what about the other so far installed libraries? nodejs, build-essential, npm2 ... should I also install them without sudo? ... and in the project folder?
    – Philipp M
    Feb 18, 2018 at 18:33
  • Yes, you should remove these node modules in home directory with sudo rm -r ~/node_modules/. I don't know where did you install those modules. If you instaled in ` /var/www/html/nodejs/` you don't need to remove them. You can only change privileges to all files in ` /var/www/html/nodejs/` with: $ cd /var/www/html/nodejs/ && sudo chown -R seven:sever * If you installed them in home directory you should install this modules again in /var/www/html/nodejs/. In general: you should locate all project files and install all modules from /var/www/html/nodejs/. Feb 18, 2018 at 18:46
  • Great thanks. I'll do that. To double check ... nodejs (so node js itself), build-essential, npm2 should be also installed in /var/www/html/nodejs/ ?
    – Philipp M
    Feb 18, 2018 at 18:56
  • Only node packages (node_modules) - things you install with $ npm install .... Feb 18, 2018 at 22:24
1

To answer your question:

Is browser-sync now installed?

Yes, it installed, and to confirm that, you can run browser-sync --version and gulp --version. this should show you the versions you installed, as it is already shown in your log

And as you saw it from the log, they are only warnings, it won't stop your modules from functioning properly.

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 [email protected]: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5 npm WARN deprecated [email protected]: please upgrade to graceful-fs 4 for compatibility with current and future versions of Node.js npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue npm WARN deprecated [email protected]: please upgrade to graceful-fs 4 for compatibility with current and future versions of Node.js

[email protected] install /home/sven/node_modules/uws node-gyp rebuild > build_log.txt 2>&1 || exit 0

They are basically deprecated module which is used by Browsersync.

And:

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: [email protected] (node_modules/fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"ia32"})

Is a permission thing. Possibly

  • the directory has the immutable flag enabled. Or

  • the directory is mounted with read-only permissions.

Or some other reasons.

I hope this helps.

4
  • thanks for the explanation ... when runing sven@sven-MS-7664:~$ browser-sync --version .... I'm getting .... browser-sync: command not found .... though. Why so?
    – Philipp M
    Feb 18, 2018 at 18:28
  • wow! this kinda look like there was a problem with the installation. Maybe you might need to run sudo npm install browser-sync gulp --save-dev and see what we get as a result.
    – antzshrek
    Feb 18, 2018 at 18:31
  • I actually did that. See above. Pawel in the other answer says I should install with sudo? I'm confused
    – Philipp M
    Feb 18, 2018 at 18:34
  • @PhilippM yea, it might be kinda risky using sudo, but notwithstanding, you can still change the ownership of the node_modules by running sudo chown -R whoami` /usr/local/lib/node_modules` else on difualt, you will have to use sudo anytime you wanna run npm -g.
    – antzshrek
    Feb 19, 2018 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.