Node JS

Part 3 : NPM INIT

NPM INIT

  1. NPM INIT
  2. NPM START
  3. NPM RUN <SCRIPT>
  4. NPM INSTALL
  5. NPM CREATE
  6. NPX <PACKAGE>

1. NPM INIT

What is npm ?

NPM is the package manager for Node.js. It was created in 2009 as an open source project to help JavaScript developers easily share packaged modules of code.

1. NPM INIT

What are packages ?

A package in Node.js contains all the files you need for a module.

Modules are JavaScript libraries you can include in your project.

1. NPM INIT

Starting a project ! ( INITIALISING )

> npm init
package name: (npm-test)
version: (1.0.0)
description:
entry point: (app.js)
test command:
git repository:
keywords:
author:
license: (ISC)

1. NPM INIT

Starting a project !

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "dependencies": {},
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

package.json

2. NPM START

Setting the start point

{
  "scripts": {
    "start": "node app.js"
  }
}

package.json

> npm start

3. NPM RUN <SCRIPT>

Setting a script

{
  "scripts": {
    "start": "node app.js",
    "test": "node test.js"
  }
}

package.json

> npm run test

4. NPM INSTALL

Installing packages.

> npm install cat-me

5. NPM CREATE

Creating a project from a generator.

> npm create vite@latest

6. NPX <PACKAGE>

RUNNING A NODE CLI

> npx create-react-app

NPM INIT

Ends

Node js Chapter 3

By Youcef Madadi

Node js Chapter 3

  • 346