Skip to content

Hello Node - Our First Package

Every living thing has DNA. Every citizen has an identity card. And every Node.js project has a package.json.

Without this file, your directory is just a folder of loose JavaScript files with no identity, no dependencies, and no purpose. It’s what transforms a “folder” into a “package.” It tells Node (and npm) exactly who your project is, who built it, and how to run it.

A neon-retro technical illustration showing a JSON document morphing into a DNA double helix. Figure 1: The package.json file determines the genetic makeup of your application.

We could create this file manually, but we have tools for that. Open your terminal or PowerShell, navigate to your HelloNode directory, and run the initialization wizard:

Terminal window
npm init

This utility will ask you a series of questions. It’s an interview for your code.

  1. package name: Press Enter to accept hellonode. (Pro-tip: npm hates capital letters).
  2. version: Press Enter for 1.0.0.
  3. description: “My first Node app” (or something equally profound).
  4. entry point: CRITICAL STEP. Type app.js and hit Enter. This tells Node where the brain of your application lives.
  5. test command: Skip (Enter).
  6. git repository: Skip (Enter).
  7. keywords: Skip (Enter).
  8. author: Your name (Sign your work!).
  9. license: Press Enter (defaults to ISC).

When it asks Is this OK? (yes), hit Enter one last time.

[!NOTE] If you’re feeling dangerous (or lazy), you can run npm init -y to skip the interview and accept all defaults immediately. But where’s the romance in that?

You now have a package.json file in your root. It might look small now, but this JSON object is the heart of your project. We’ll be visiting it frequently to add dependencies (libraries we borrow) and scripts (commands we run).

If you haven’t already, ensure you have your app.js file ready to go.

app.js
'use strict';
console.log('Hello Node');

Hello Node Demo Repo

Official npm init Docs

We have the DNA, now let’s spark the life into this Frankenstein’s monster.