Lesson 51 of 55
javascriptNode.js Fundamentals & npm
15 mins
Course progress93%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 51 of 55
javascript15 mins
Keep these ideas in mind as you work through the lesson.
Node.js is a server‑side JavaScript runtime built on Chrome’s V8 engine. It lets you run JavaScript outside the browser and power APIs, CLI tools, servers, and more.
nvm install --lts).node -v # e.g. v20.8.0
npm -v # npm version
$ node
> console.log('Hello from Node');
> process.argv // command‑line arguments array
> __dirname // directory of the current module
> __filename // absolute path of the current file
require/module.exports)// utils.js
function add(a,b){ return a+b; }
module.exports = { add };
// app.js
const {add} = require('./utils');
console.log(add(2,3));
# initialise a project (creates package.json)
npm init -y
# install a library as a runtime dependency
npm install axios
# install a dev‑only tool
npm install --save-dev jest
package.json scripts let you run commands easily:
"scripts": { "start": "node app.js", "test": "jest" }
Run with npm start or npm test.
Create a .env file and load it with dotenv:
npm install dotenv
require('dotenv').config();
console.log(process.env.API_KEY);
Node gives you full access to the file system, networking, and many built‑in modules (fs, http, path, etc.).