Introduction to Package Managers, npm, and Express in Node.js
Explore npm, ES6 modules, and Express to kickstart your server-side development journey

I am an Enthusiastic and self-motivated web-Developer . Currently i am learning to build end-to-end web-apps.
Learn how to manage dependencies, write modular code, and build a server using npm, ES6 modules, and Express.js
1. Package Managers and npm
What is a Package Manager?
A package manager is a tool that automates the installation, updating, and management of software packages (modules) in a project. In Node.js, the primary package manager is npm (Node Package Manager).
Why npm?
npm allows you to:
Access thousands of open-source packages that add functionality to your project.
Manage project dependencies in one file (
package.json).Easily install, uninstall, or update packages.
Key npm Commands
1. Initialize a Project
To create a new Node.js project, you need a package.json file, which holds metadata about the project and its dependencies.
npm init -y
The -y flag automatically accepts default settings.
2. Installing Packages
Use npm install or npm i to install packages. For example, to install Express:
npm install express
This creates a node_modules folder to store packages and a package-lock.json file for dependency tracking.
3. node_modules:
This folder contains all the installed packages and their dependencies. It’s not recommended to modify this folder manually.
4. npx:
npx allows you to run Node packages directly from the command line without installing them globally. For example, you can run a development server directly with npx:
npx create-react-app my-app
2. package.json and Dependencies
package.json
The core file in a Node project that lists your project's dependencies, scripts, and metadata. Here’s a sample:
{
"name": "movie-api",
"version": "1.0.0",
"main": "index.js",
"dependencies": {
"express": "^4.17.1"
},
"scripts": {
"start": "node index.js"
}
}
Dependencies:
Packages required for your project to run, listed under "dependencies" in package.json. They are installed using npm install .
3. ES6 Modules (type="module") and Import/Export Syntax
JavaScript ES6 introduced a modular syntax for code reusability:
Add type="module" to package.json to enable ES6 modules.
Named Exports
Allow multiple exports from a file.
// math.js
export function add(x, y) {
return x + y;
}
export function subtract(x, y) {
return x - y;
}
Default Export allows one default export per file.
// greeting.js
export default function greeting() {
return "Hello!";
}
Importing in ES6:
import greeting from './greeting.js'; // default import
import { add, subtract } from './math.js'; // named imports
4. Creating a Server Using Express
Express is a minimal Node.js framework that simplifies building web servers.
Setting Up an Express Server
- Install Express:
npm install express
2.Create index.js:
import express from 'express';
const app = express(); const PORT = 3000;
app.listen(PORT, () => { console.log(`Server is running on http://localhost:${PORT}`); });
The Importance of Listening
The app.listen function makes your server start listening for requests on a specified port, allowing your application to receive and process client requests.
Summary
1.npm is the default package manager for Node.js, used to install and manage project dependencies.
2.package.json stores project metadata and dependencies, enabling easier collaboration and automation.
3.ES6 modules (import/export) improve code structure and reusability.
4.Express.js provides a lightweight and efficient way to create servers and APIs in Node.js.
5.Key tools like npx and folders like node_modules play essential roles in modern JavaScript development.




