Skip to content

Instantly share code, notes, and snippets.

@acidtone
Last active October 30, 2023 15:00
Show Gist options
  • Save acidtone/f2e901fb4b04bd41aa59755e2de9af4f to your computer and use it in GitHub Desktop.
Save acidtone/f2e901fb4b04bd41aa59755e2de9af4f to your computer and use it in GitHub Desktop.
npm: Initialize a new npm project

npm: Initialize a new project

First-time Setup

If you've just installed npm, it'll save you some time later if you set some defaults in your config:

  1. Set your name

    $ npm config set init-author-name "your name"
    
  2. Optional: Set your preferred license type (default is ISC):

    $ npm config set init-license "MIT"
    
  3. Add the following to a .gitignore file in the root of your project:

    node_modules
    npm-debug.log
    
    • One of the advantages of using npm is that we don't need to commit dependencies to our projects. Instead we git pull and then npm install.

Instructions

  1. Download or clone this project into your workspace;

  2. Initialize an npm project by creating a package.json file:

    $ npm init
    
    • You will be asked to confirm the details of your project.

    • See Anatomy of a package.json file for more details.

    • You can skip these questions with the -y flag:

      $ npm init -y
      
  3. Once complete, you should have a new package.json file in your project directory.

  4. Install your first package!

    $ npm install <project-name>
    

Activity: Starter packages

  1. Install one or all of these packages:
  2. For any given package, create an example app by following the usage instructions.
  3. Have one of your classmates clone and run your demo app without including node_modules.

Related resources:

// Try adding a downloaded package to this file using `require()` or `import`
console.log('Hello World!');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment