User Tools

Site Tools


programming:javascript:npm

NPM

Create a project

npm init

Start project

OPTIONAL Pick the repository

Pick teh repository from which you serve the dependencies

npm config set -- "//code.siemens.com/api/v4/packages/npm/:_authToken" 12345-abcdefgH1234XYz12J

Build first

# install modules from package.json
npm install
# advanced build
npm install --legacy-peer-deps --no-audit --prefer-offline --registry "https://registry.npmjs.org/"
–legacy-peer-deps avoids error “Conflicting peer dependency”, when modules transitively depend on older npm-libs to be installed. And there are none in the repository, cause they were replaced by new versions. Then the build falls back to new versions of npm-lib and hopes they work too.
–no-audit skip vulnerability scan
–prefer-offline Stale data is an artifact of caching, in which an object in the cache is not the most recent version committed to the data source. If true, staleness checks for cached data will be bypassed, but missing data will be requested from the server.
–registry –registry “https://registry.npmjs.org/

OPTIONAL test

# starts the tests defined in 
npm test

start

npm run start -- --configuration mock --host 0.0.0.0 --disable-host-check  --port 4300
allows passing arguments to the “script”, without writing them directly into the oackage.json . Here run executes “ng serve”
–configuration mock angular configuration defined in angular.json
–host 0.0.0.0 –disable-host-check angular “serve” argument. Dont bind to localhost. Allows calling from another host, like host of VM.
–port 4300 angular “serve” argument. starts angular app on different port.

Using NPM in browser

Setting the default registry

npm config set registry https://yoururl.com/artifactory/api/npm/npm-all
npm config get registry

The file, where the config is stored is in your home dir and is called '.npmrc'

Making the npm use a special registry for some package namespace is done as following

Opens the '.npmrc' file

npm config edit

And configure the registry e.g. for the `@simpl` pacakges.

Somewhere in `.nprc` add

@simpl:registry=https://code.yourdomain.com/api/v4/packages/npm/
@simpl-labs:registry=https://code.yourdomain.com/api/v4/packages/npm/

If the repository requires authentication - there is some weird syntax allowing to add a token as authentication for a repository, using the `domain` notation <code> @simpl:registry=https://code.yourdomain.com/api/v4/packages/npm/ @simpl-labs:registry=https://code.yourdomain.com/api/v4/packages/npm/ code.yourdomain.com/api/v4/packages/npm/:_authToken=CSC-y-79x5babLxHyeWyE1xJ </code>

programming/javascript/npm.txt · Last modified: 2023/11/01 07:31 by skipidar