LIVE SERVER package installations through npm (node package managers)

LIVE SERVER package installations through npm (node package managers)

Live Server is a local development tool that automatically reloads your web applications when you make changes to your codebase. The live server package is installed either through npm or as an extension, depending on your specific requirements and the development environment you are working with. In this article you will learn:

  • How to install live server package through npm.

  • Modes of installing live server package.

  • Why you should consider installing a live server package through npm.

    1.Live Server package installation

Before you begin with the installation of a live server package, make sure you have Nodejs installed on your system πŸ’». Nodejs is a run-time environment that allows you to run javascript on both frontend and backend. You can download and install Node.js from the official website: https://nodejs.org. and select the installer for your operating system, (you probably want the .msi for Windows and the .pkg for Mac. While Nodejs is been installed, an additional command line is also installed along with it, known as NPM; Npm is a package manager for the Javascript programming language, mainly for managing and installing packages in Node.js projects.

NB: Live Server is one out of the many javascript packages, so we need npm to install it.

Once Nodejs is installed on your systemπŸ’», you can proceed with the installations of the live server package following the steps below πŸ‘‡. However, You must have Created and Opened a project folder πŸ“‚ from your preferred code editor e.g. Vscode , in other to follow the steps below.

vcode editor

a. Open your terminal and navigate to your project folder πŸ“.

vscode editor navigating to the folder created

b. Run npm init –y to initialize your project folder πŸ“.

run npm init to initialize project

c. Run npm install live-server -D to install Live Server in the development phase of your project.

Installing live server package

d. After the installation is completed, it's time to start the live server.

i. Firstly, navigate and add a start command to the scripts section of the package.json file of your project folder πŸ“.

ii. Save and close the package.json file.

save the file

iii. Run npm startto start the live server.

npm start command starts the live server, makes your web application accessible throughout the local server, and automatically reloads your WEB BROWSER whenever you make changes to the HTML, CSS, AND JAVASCRIPT FILE.

live server in the browser

2. Modes of installing live server package

The live server package can be installed in one of the two methods listed below:

  • global

  • development

Let's discuss the difference between these two methods

Global installation

Global installation simply means the live server package is installed globally on your machine rather than installed locally within a specific project. This mode of installation allows you to run the live server from any folder πŸ“ on your machine.

Below is the command to install the live server globally πŸ‘‡

npm install live-server –g

The -g option stands for global, and when it is specified, the live server package is installed globally and made available as a global command line tool on your system πŸ’».

Development installation

Development mode installation means the package is installed locally within a specific project. Development mode installation ensures that your project has its version of the live server and makes it very easy for other developers to collaborate with you on the same project, by simply installing all the required packages listed in your project.

Here is the command line to install a live server in development mode πŸ‘‡

npm install live-server -D

-D is known as a development dependency. Set -D option only when you need to install a live server in the development phase of your project.

3. Why you should consider installing the Live Server package through npm?

Installing a Live Server package using npm offers a variety of benefits including:

  • PORTABILITY: when you install a live server package through npm, you can easily set up your project on any machine that has Nodejs installed, Also when you share the project with other developers, all the dependencies listed in your project are easily installed using npm.

  • DEPENDENCIES HANDLING: Your project dependencies are easily managed in a package.json file when you installed a live server package through npm. This makes team collaboration easier and ensures consistent environments across different development setups.

  • VERSION CONTROL: By relying on npm, you can specify the exact version of the live server you want to use in your project. This helps in maintaining consistency across different development environments and ensures that all team member uses the same version of the live server.

  • BACKEND FUNCTIONALITY: If you are working on a web development project that requires backend functionality, such as handling API requests. Interactions with database and server-side rendering. you should consider installing a live server using npm in other to get the live preview of your project in the front end. This is something a live server extension is not capable of handling.

  • COMPACTIBILITY: Npm is supported by a wide range of operating systems, including Windows, macOS, and Linux. Installing a live server using npm ensures cross-platform compatibility across different development environments.

Summary

Live Server package is a local development tool with live reload capability for HTML, CSS and JavaScript files. Live Server package is installed either globally or in development mode.However,before installing a live server package using npm , your system πŸ’» must have Node.js installed. Live Server installation as an npm package offers variety of benefits including dependencies handling, version control, compatibility e.t.c

Β