# npm

Using npm & working with dusted projects.

# Installing npm

You can install the latest version of npm through your command line by running:

npm install -g npm

To check npm has installed, you can check the versions using:

node -v

npm -v

You can also update using

npm update

# Usage of npm in dusted projects

Platform Sites

Upon cloning down a website, change to your local theme directory:

cd repos/project/custom/themes/project-theme/

(not) Platform Sites

Upon cloning down a website, change to your local theme directory:

cd repos/project/themes/project-theme/

Begin by running npm install

If this errors, it will usually be because of your npm version, platform works well with 10, you can swap your version by using sudo n 10 or for more information read more here: Versions npm

when certain items become outdated, these will flag upon running npm install. you can run npm audit then npm audit fix to fix these versions & make them compatible.

When completed, you can run npm start

When finishing any edits within scss or js you can finally run npm run build

This will then generate new files which will need to be pushed with your changes to the repo.

These usually are named:

primary.css

main.css

app.css

functions.js

& others.

Things to note git & troubleshooting

Occasionally running git pull will give you merge conflicts depending if more than one person is editing the website, after resolving any merge conflicts and before adding and commiting, you will need to run npm run build to ensure that the lasted versions of the generated files above are pushed.

If your npm install fails & causes some errors, or if you have begun the install with the incorrect version, you can simply delete the directory created named node_modules and start again.

# Versions of npm & switching versions

# Node on mac

To change between versions of node, we can install n

You can install n by running npm install -g n from your command line.

Once installed, you can run sudo n 10 to install and use version 10.

You can read more about installing n and other configurations here (opens new window).

# Node on Windows

Changing & managing node versions can be done on windows using nvm

You can install nvm using command prompt and running the following:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

or if you have wget, running:

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

To check the install has worked, run command -v nvm

Install node: nvm install node

Install specific version: nvm install 14.7.0 (example version)

View available versions: nvm ls-remote

& finally to view the path of install you can run nvm which 12.22

View more information and details here (opens new window)