Create a project
Set up a real Node.js project from scratch
⏱ Est. ~9 min
01 · Read
Every piece of software you've ever used — from phone apps to massive websites — started exactly like this: someone created an empty folder and set up a project inside it. That's what you're about to do.
Setting up a project properly from the start saves you a lot of headaches later. A project in Node.js isn't anything special — it's just a folder with a package.json config file that tracks your project's name, version, and dependencies. Without it, tools like npm have no idea what your project needs or how to run it.
Think of it like moving into a new apartment. Before you can decorate or invite friends over, you need to sign a lease and get the keys. npm init is signing the lease — it creates the official document (package.json) that says "this folder is a real project".
💡 Picture thisStarting a project is like moving into a new apartment. Before you can decorate or build anything, you sign the lease (npm init) and get the official document that makes it real (package.json).
Key points
- Every Node.js project starts with a folder and a package.json
- package.json tracks the project's identity and dependencies
- Setting it up right from the start keeps things tidy as the project grows
02 · Real-machine exercise
Every project starts with a folder. Create one called my-server, then go into it. These two commands create the directory and switch into it.
mkdir my-server && cd my-server
03 · Real-machine exercise
Now initialize your project with npm. The -y flag means "use all defaults" — skip the Q&A and just create the config file.
npm init -y
04 · Quiz
What does the -y flag do in npm init -y?
- Installs the latest version of npm
- Creates a yarn.lock file
- Skips all the questions and uses defaults
- Yes, delete existing files
05 · Real-machine exercise
Let's see what npm created. package.json is the heart of every Node.js project — it describes your project and tracks its dependencies.
cat package.json
06 · Fill in the blank
The file that tracks your project's dependencies is called _____.
07 · Read
What each field in package.json means:- name — your project's name (defaults to the folder name) - version — the project's version number (starts at 1.0.0) - description — a short explanation of what the project does - main — the entry point file (which file runs when others import your project) - scripts — custom commands you can run with npm run <name> - keywords — search tags for when you publish to npm - license — how others can use your code
The most important field you'll use shortly is dependencies — it'll list every package your project needs. It's empty now because we haven't installed anything yet.
Key points
- package.json is the config file for every Node.js project
- npm init -y creates it with sensible defaults
- The dependencies field tracks which packages your project uses
08 · Quiz
You try to run npm install express, but get an error saying there's no package.json. What do you need to do first?
- Install Node.js again
- Manually create a file called express.js
- Run node install express instead
- Run npm init -y to create a package.json file
Other lessons in this chapter
⚠ The full interactive experience needs JavaScript. Please enable it and reload.
※ This is an independent Traditional Chinese teaching project — not an official Anthropic product. Claude™ is a trademark of Anthropic, PBC.