© Jörg Krause 2017

Jörg Krause, Programming Web Applications with Node, Express and Pug , 10.1007/978-1-4842-2511-0_1

1. Installation Problems

Jörg Krause

(1)Berlin, Germany

All instructions, which you find on the Internet about Node, NPM and other modules presuppose one thing: transparent Internet access—which at first sight is worth hardly a mention. Indeed, it represents a problem for many users. Not for the lack of Internet, but for the restrictions in enterprise networks.

Node.Js

Node itself stands as an installation package of choice and can also be installed without the Internet. Since NPM is included, it works just fine online, too. All further components of the application, like Express and Pug, can be installed with npm.

Problems with NPM

It’s possible that npm can’t access the Internet the way you expect it. This can be because of missing SSL support or local proxy servers.

Proxy

You can instruct npm to use a proxy server :

1   npm config set proxy http://proxy.company.com:8080 -g            
2   npm config set https-proxy http://proxy.company.com:8080 -g

The option -g stops the changes globally. Otherwise, it is only valid for the current project and it must be located in the same folder, where a file called .npmrc exists. If this is missing, you’ll place it there, which is perhaps senseless if you don’t plan on using further npm commands.

If a username and a password are necessary, it might looks as follows:

1   npm config set proxy http://domain%5Cuser:pass@host:port            

Special characters must become URL encoded here:

  • ” -> %22

  • @ -> %40

  • : -> %3A

  • -> %5C

SSL

Access to the Repository is standard. Go around this as follows:

1   npm config set strict-ssl false            
2   npm config set registry "http://registry.npmjs.org/"

Perhaps this combination with the installation procedure can help:

1   npm --proxy http://<user>:<pwd>@<proxy>:<port>
2       --without-ssl
3       --insecure
4        -g install <paketname>

Problems with Git

Git is needed if you fetch packages via Bower or over direct connections from Github. There are two hurdles in enterprise networks :

  • A local Proxy is used.

  • The protocol git:// is blocked. (That is a moniker for a special port.)

Many administrators are of the opinion that HTTP and port 80 are enough. However, we developers want more. Thus, Git must be configured accordingly.

You receive the local Git installation under Linux as follows:

$ sudo apt-get install git              

Under Windows you should use an installer, which can also bring along a Shell, which contains a part of the not-local function. One does not have to switch a lot mentally, and can invariably use most Linux commands this way.

Here you find the suitable package: https://git-scm.com/download/win Configure the options as shown on the following screens:

A435076_1_En_1_Fig1_HTML.jpg
Figure 1-1. Installation options
A435076_1_En_1_Fig2_HTML.jpg
Figure 1-2. Starting options
A435076_1_En_1_Fig3_HTML.jpg
Figure 1-3. Behavior of the line break characters

Leave all other options unchanged.

The installation for Windows comprehensively has no graphic surface. This must be procured separately. In the long run, however, the command line is the better and faster way.

Proxy

In order to use a proxy , you enter the following command (in a line):

1   git config
2       --global
3       http.proxy
4       http://<proxyuser>:<proxypwd>@<proxy.server.com>:<port>

Replace the place holders with suitable values. <proxyuser> and <proxywd> are only necessary if the Proxy requires an authentication. The other placeholders mark the proxy.

Git protocols

With the following command (again in a line) you can switch to https:

1   git config
2       --global
3       url."https://<username>@".insteadOf git://

The placeholder <username> marks a private Repository in Git. The quotation marks protect the name in the case of blanks:

You can omit the value for the glocal access completely and instead use Github:

1   git config
2       --global
3       url.https://github.com/.insteadOf git://

Online installation

Even if the information of a proxy is not sufficient, the online access remains. The classic way thereby exists in downloading an installation package and the local installation. For Windows users, those are the MSI packages ; for Linux users, it’s usually DEB packages (Debian, Ubuntu, Mint, etc.) or RPM packages (Suse, Fedora, RedHat, etc.).

However, NPM packages are not part of package collections, but instructions over source and dependence. With the installation, the specified fragments from the Internet are downloaded.

Preparation

The dependence of an Internet connection can’t fundamentally be absolutely avoided. But it is sufficient to have “other” machines with Internet access. They can use a detour. That can be done for individual packages anyway, but many packages have dozens of hundreds of dependences, sometimes over several stages. Here it is meaningful to have something automatic.

The solution is the package npmbox. It consists of two command line tools: npmbox for downloading and packing, and npmunbox for unpacking. If you can receive brief access to the Internet on the search machine, install npmbox there. It simplifies handling substantially. Even if that cannot be done, you find more instructions for hard cases below.

First you install npmbox on the source machine with Internet access:

npm install npmbox -g                

In order to check if it worked, you enter the following command:

npmbox --help                

You receive a quick guide of a very simple tool .

Hard cases

So that you can access npmbox on the desired machine, you must package it yourself. That is a kind of recursive approach—npmbox packs itself:

npmbox npmbox                

The result is a file with the file extension .npmbox.

Copy the file on the desired machine. The package is a so-called tarball. npm can directly go around Tar und usually needs no other software. If you packed something before with npmbox, you need npmunbox for unpacking.

Access to Tar

Tarball

Tar is an archives software. The name comes from “Tape of archives” (archiving on tape drive). In order to store data on volumes, one combines many small files into a large file. Contrary to ZIP, TAR is a pure combination method, which does thereby becomes a compressed file. The format receives the original meta data of the files, such as rights and link information. You can find more on Wikipedia:

https://en.wikipedia.org/wiki/Tar_(computing )

On Linux, tar is a standard device which is always available.

tar -xvf yourfile.tar                  

On Windows, there are several options. To the standard environments, which are used in Node installations, Git shall be included. Git is available at first as described, but also as MSI. The installer comes with a rudimentary BASH Shell. This cannot do everything as under Linux, but it can use tar. Open Bash Shell under Windows and then use the same command:

$tar -xvf yourfile.tar                  
A435076_1_En_1_Fig4_HTML.jpg
Figure 1-4. Bash with tar command on Windows

If that does not fit, well-known archive programs like 7-Zip are suitable too .

Installing NpmBox

After the command is implemented, all files are in the folder .npmbox-cache.

A435076_1_En_1_Figa_HTML.jpg If you unpack several packages, all this will be copied into the same folder. That is because there can be repetitions by dependence.

Now it’s npm’s turn (in a line):

1   npm install --global
2               --cache ./.npmbox-cache
3               --optional
4               --cache-min 999999
5               --fetch-retries 0
6               --fetch-retry-factor 0
7               --fetch-retry-mintimeout 1
8               --fetch-retry-maxtimeout 2
9   npmbox
A435076_1_En_1_Figb_HTML.jpg  or /

Under Linux you always use the information of a path, like /. Under Windows, you use . However, if you use the Git Bash under windows, then also works. Under Windows 10, it works with cmd.exe and /, but with some problems, like no longer having a functioning TAB key.

The last line contains the actual package . The option ‘–cache’ is there to determine that npm won’t access the Repository, but the local folder. Often a short version is enough:

npm i -cache ./.npmbox-cache                

Installing Packages

Now this pedantic npm command isn’t quite what developers want to type frequently. Therefore, npmunbox exists. This is a future device for the command line, which simplifies the unpacking procedure.

npmunbox <packagename>                

As package name <packagename> you use the name, which was also used during the package procedure.

A435076_1_En_1_Figc_HTML.jpg If there’s a problem, the npmbox version of the source machine most likely doesn’t match the one on the desired machine. Check that carefully, before you go further.

npmunbox has a few more options, since a part of the behavior of npm must be simulated here:

  • -v, -verbose: Show npm expenditures (standard).

  • -s, -silent: Additional expenditures are suppressed.

  • -g, -global: Install packages globally (in the path, not in the protect folder).

  • -C, -prefix: The switch ‘npm –prefix’ shows the standard listing.

  • -S, -save: The switch ‘npm –save’ is stored in package.json in dependencies.

  • -D, -save-dev: The switch ‘npm –save dev’ is stored in package.json in devDependencies.

  • -O, -save-optional: The switch ‘npm –save-optional’ is stored in package.json in optionalDependencies.

  • -E, -save-exact: The switch ‘npm –save exact’ leads to versions in the SemVer format being placed with the exact number.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.182.73