{"id":29333,"date":"2021-02-22T17:19:26","date_gmt":"2021-02-23T01:19:26","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=29333"},"modified":"2021-03-29T04:20:49","modified_gmt":"2021-03-29T11:20:49","slug":"npm-init","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/npm-init\/","title":{"rendered":"What is npm init?"},"content":{"rendered":"\n<p>The npm init command in the JSON language creates a package.json file for your project\u2019s frontend. A package.json file is a file that contains information about the project\u2019s packages and dependencies. It also contains metadata for the project such as version number, author, and description.&nbsp;<br><\/p>\n\n\n\n<p>Using npm commands occurs through the command line tool and init is just one of many commands npm responds to. In this introduction, we will learn what npm is, what a package.json file is, and what the npm init command does. By the end of this guide, you\u2019ll have a clearer picture of how to use the npm init command.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is npm?<\/h2>\n\n\n\n<p>Built as a package manager and installer, <a href=\"https:\/\/careerkarma.com\/blog\/how-to-learn-npm\/\">npm<\/a> (Node Package Manager) is also the world\u2019s largest code library, containing over 800,000 code packages which can be installed through the command line. Npm itself is installed through Node.js. To use npm in the command line, you must have Node.js installed.<br><\/p>\n\n\n\n<p>Npm also acts as a dependency manager. A dependency is a library your project relies on to function properly. React is an example of a dependency. These are kept track of in the package.json file mentioned in the introduction.<br><\/p>\n\n\n\n<p>Let\u2019s take a look at how to use the npm init command.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Use npm init<\/h2>\n\n\n\n<p>The command init is short for initialize. Before building a new project, we need to specify some of the project\u2019s attributes. These attributes include the project\u2019s name, initial version, and description. There are more attributes such as the project\u2019s main file, github repository, keywords, and license information, but the name and version number are the most important here.<br><\/p>\n\n\n\n<p>Using npm init is straightforward. First make sure to have Node.js installed, as stated in the previous section. When npm is installed, using the init command in the command line tool will initialize your project.<br><\/p>\n\n\n\n<p><em>npm init&nbsp;<\/em><br><\/p>\n\n\n\n<p>This will begin the initialization process. During the process, you will be prompted to provide the above information about your project. After completing the prompts, a package.json file will be created in your current directory. A best practice is to run this command while in the root directory of your project.<br><\/p>\n\n\n\n<p>A package.json file is a file containing the above information about your project. It must be written in <a href=\"https:\/\/careerkarma.com\/blog\/json\/\">JSON<\/a>. Structuring the package file in this way makes it easy to read by the developers and easy for the computers to parse the information.<br><\/p>\n\n\n\n<p>An example package.json file may look like this:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>{\n  &quot;name&quot;: &quot;storefront-frontend&quot;,\n  &quot;version&quot;: &quot;0.1.0&quot;,\n  &quot;private&quot;: true,\n  &quot;dependencies&quot;: {\n    &quot;@testing-library\/jest-dom&quot;: &quot;^4.2.4&quot;,\n    &quot;@testing-library\/react&quot;: &quot;^9.3.2&quot;,\n    &quot;@testing-library\/user-event&quot;: &quot;^7.1.2&quot;,\n    &quot;react&quot;: &quot;^16.12.0&quot;,\n    &quot;react-dom&quot;: &quot;^16.12.0&quot;,\n    &quot;react-scripts&quot;: &quot;3.4.0&quot;\n  },\n  &quot;scripts&quot;: {\n    &quot;start&quot;: &quot;react-scripts start&quot;,\n    &quot;build&quot;: &quot;react-scripts build&quot;,\n    &quot;test&quot;: &quot;react-scripts test&quot;,\n    &quot;eject&quot;: &quot;react-scripts eject&quot;\n  },\n  &quot;eslintConfig&quot;: {\n    &quot;extends&quot;: &quot;react-app&quot;\n  },\n  &quot;browserslist&quot;: {\n    &quot;production&quot;: [\n      &quot;&gt;0.2%&quot;,\n      &quot;not dead&quot;,\n      &quot;not op_mini all&quot;\n    ],\n    &quot;development&quot;: [\n      &quot;last 1 chrome version&quot;,\n      &quot;last 1 firefox version&quot;,\n      &quot;last 1 safari version&quot;\n    ]\n  }\n}<\/pre><\/div>\n\n\n\n<p>Here, we can see that only the name and version number are included from the list of prompts. These are the only ones required, but in general, providing more information is considered a best practice. Then we see the list of dependencies this particular project needs to run.<br><\/p>\n\n\n\n<p>The structure of the dependency is a nested JSON object with key\/value pairs. The keys are the name of the dependency and the values point to their respective version numbers. In this example, there are different testing packages as well as packages for React.&nbsp;<br><\/p>\n\n\n\n<p>Since this frontend is built with React, the project needs to know that it depends on React to function. And with the React packages listed in the package.json file, they can be installed from the command line as well.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Using npm init from the command line initializes the project\u2019s package.json file. In this file is information on the project itself such as name and version number. Listed alongside this information are the project\u2019s dependencies.&nbsp;<br><\/p>\n\n\n\n<p>Dependencies are packages the project requires to function properly. Listing them in the package.json file allows them to be installed before building the project. The package.json file generated from calling npm init must be written in JSON format.<br><\/p>\n\n\n\n<p>Now that you\u2019ve had an introduction to using npm init and what a package.json file is, try initializing your next project by using npm init.<\/p>\n","protected":false},"excerpt":{"rendered":"The npm init command in the JSON language creates a package.json file for your project\u2019s frontend. A package.json file is a file that contains information about the project\u2019s packages and dependencies. It also contains metadata for the project such as version number, author, and description.&nbsp; Using npm commands occurs through the command line tool and&hellip;","protected":false},"author":104,"featured_media":11907,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[11933],"tags":[],"class_list":{"0":"post-29333","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-javascript"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"JavaScript","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":null,"is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.4 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>What is npm init? | Career Karma<\/title>\n<meta name=\"description\" content=\"The npm init command creates a package.json file for your project. Find out more in this guide.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/npm-init\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is npm init?\" \/>\n<meta property=\"og:description\" content=\"The npm init command creates a package.json file for your project. Find out more in this guide.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/npm-init\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2021-02-23T01:19:26+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-03-29T11:20:49+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/JavaScript.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"667\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Ryan Manchester\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ryan Manchester\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/npm-init\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/npm-init\\\/\"},\"author\":{\"name\":\"Ryan Manchester\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/92fd52a503f77fc058ec2d0666da9bd5\"},\"headline\":\"What is npm init?\",\"datePublished\":\"2021-02-23T01:19:26+00:00\",\"dateModified\":\"2021-03-29T11:20:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/npm-init\\\/\"},\"wordCount\":675,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/npm-init\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/02\\\/JavaScript.jpg\",\"articleSection\":[\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/npm-init\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/npm-init\\\/\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/npm-init\\\/\",\"name\":\"What is npm init? | Career Karma\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/npm-init\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/npm-init\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/02\\\/JavaScript.jpg\",\"datePublished\":\"2021-02-23T01:19:26+00:00\",\"dateModified\":\"2021-03-29T11:20:49+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/92fd52a503f77fc058ec2d0666da9bd5\"},\"description\":\"The npm init command creates a package.json file for your project. Find out more in this guide.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/npm-init\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/npm-init\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/npm-init\\\/#primaryimage\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/02\\\/JavaScript.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/02\\\/JavaScript.jpg\",\"width\":1000,\"height\":667},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/npm-init\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"What is npm init?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/92fd52a503f77fc058ec2d0666da9bd5\",\"name\":\"Ryan Manchester\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/ryan-manchester-150x150.jpg\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/ryan-manchester-150x150.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/ryan-manchester-150x150.jpg\",\"caption\":\"Ryan Manchester\"},\"description\":\"Ryan is a technical writer at Career Karma, where he covers programming languages, technology, and web development. The Texas native earned his Bachelor's of Music Composition from the University of North Texas. Ryan is currently pursuing further education in web development, aiming to graduate from Flatiron School with a certification in full stack web development. Since joining the Career Karma team in November 2020, Ryan has used his expertise to cover topics like React and Ruby on Rails.\",\"sameAs\":[\"http:\\\/\\\/www.ryanmanchester.info\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/ryan-manchester-6537a630\\\/\"],\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/author\\\/ryan-manchester\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"What is npm init? | Career Karma","description":"The npm init command creates a package.json file for your project. Find out more in this guide.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/careerkarma.com\/blog\/npm-init\/","og_locale":"en_US","og_type":"article","og_title":"What is npm init?","og_description":"The npm init command creates a package.json file for your project. Find out more in this guide.","og_url":"https:\/\/careerkarma.com\/blog\/npm-init\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2021-02-23T01:19:26+00:00","article_modified_time":"2021-03-29T11:20:49+00:00","og_image":[{"width":1000,"height":667,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/JavaScript.jpg","type":"image\/jpeg"}],"author":"Ryan Manchester","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"Ryan Manchester","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/npm-init\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/npm-init\/"},"author":{"name":"Ryan Manchester","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/92fd52a503f77fc058ec2d0666da9bd5"},"headline":"What is npm init?","datePublished":"2021-02-23T01:19:26+00:00","dateModified":"2021-03-29T11:20:49+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/npm-init\/"},"wordCount":675,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/npm-init\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/JavaScript.jpg","articleSection":["JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/npm-init\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/npm-init\/","url":"https:\/\/careerkarma.com\/blog\/npm-init\/","name":"What is npm init? | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/npm-init\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/npm-init\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/JavaScript.jpg","datePublished":"2021-02-23T01:19:26+00:00","dateModified":"2021-03-29T11:20:49+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/92fd52a503f77fc058ec2d0666da9bd5"},"description":"The npm init command creates a package.json file for your project. Find out more in this guide.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/npm-init\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/npm-init\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/npm-init\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/JavaScript.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/JavaScript.jpg","width":1000,"height":667},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/npm-init\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"JavaScript","item":"https:\/\/careerkarma.com\/blog\/javascript\/"},{"@type":"ListItem","position":3,"name":"What is npm init?"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/92fd52a503f77fc058ec2d0666da9bd5","name":"Ryan Manchester","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/12\/ryan-manchester-150x150.jpg","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/12\/ryan-manchester-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/12\/ryan-manchester-150x150.jpg","caption":"Ryan Manchester"},"description":"Ryan is a technical writer at Career Karma, where he covers programming languages, technology, and web development. The Texas native earned his Bachelor's of Music Composition from the University of North Texas. Ryan is currently pursuing further education in web development, aiming to graduate from Flatiron School with a certification in full stack web development. Since joining the Career Karma team in November 2020, Ryan has used his expertise to cover topics like React and Ruby on Rails.","sameAs":["http:\/\/www.ryanmanchester.info\/","https:\/\/www.linkedin.com\/in\/ryan-manchester-6537a630\/"],"url":"https:\/\/careerkarma.com\/blog\/author\/ryan-manchester\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/29333","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/104"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=29333"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/29333\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/11907"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=29333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=29333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=29333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}