{"id":5055,"date":"2020-09-25T17:52:34","date_gmt":"2020-09-25T12:22:34","guid":{"rendered":"https:\/\/www.h2kinfosys.com\/blog\/?p=5055"},"modified":"2020-09-25T17:53:15","modified_gmt":"2020-09-25T12:23:15","slug":"how-to-set-up-node-npm","status":"publish","type":"post","link":"https:\/\/www.h2kinfosys.com\/blog\/how-to-set-up-node-npm\/","title":{"rendered":"How to Set Up Node\/NPM?"},"content":{"rendered":"\n<p>NPM package manager for the Node.js using the packages, or modules if you like.<strong> <\/strong>www.npmjs.com hosts thousands of free packages to download and use.<strong> <\/strong>NPM program should be installed on your computer when you install Node.js.<strong> <\/strong>Now, NPM is ready to run on your computer!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What is a Package?<\/strong><\/h2>\n\n\n\n<p>A package in Node.js which contains all the files which are required for a module. Modules are the <a href=\"https:\/\/en.wikipedia.org\/wiki\/List_of_JavaScript_libraries\" rel=\"nofollow noopener\" target=\"_blank\">JavaScript libraries <\/a>that we can include in your project.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Introduction to React:<\/strong><\/h2>\n\n\n\n<p>The React is a front-end framework that is used to create a UI. JSX is a JavaScript syntax extension, which is typically used to React to describe the UI elements. A web pack is a pack of the <a href=\"https:\/\/www.h2kinfosys.com\/blog\/what-is-javascript\/\">JavaScript <\/a>files which can run in a browser.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Setting up node<\/strong><\/h2>\n\n\n\n<p><strong>Step 1:<\/strong> Once you have the project directory, navigate to the project directory, and initialize the project using npm.<\/p>\n\n\n\n<p>mkdir node-project<\/p>\n\n\n\n<p>cd node-project<\/p>\n\n\n\n<p>npm init<\/p>\n\n\n\n<p>The above command will ask for a couple of details like name, version, git, etc. related to the Node.js project. Enter the details, and you will have the project created with a package.json file.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{\n&nbsp;&nbsp;\"name\": \"project\",\n&nbsp;&nbsp;\"version\": \"1.0.1\",\n&nbsp;&nbsp;\"description\": \"Test\",\n&nbsp;&nbsp;\"main\": \"home.js\",\n&nbsp;&nbsp;\"scripts\": {\n&nbsp;&nbsp;&nbsp;&nbsp;\"test\": \"echo \\\"Error: no test&nbsp; is specified\\\" &amp;&amp; exit 1\"\n&nbsp;&nbsp;},\n&nbsp;&nbsp;\"author\": \"\",\n&nbsp;&nbsp;\"license\": \"IS.\"\n}\n<\/pre>\n\n\n\n<p>The package1.json file will have all the information related to the Node.js project. Information related to all node package modules installed in the project can be saved to the package.json file using the \u2013save option.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Creating Node.js Express Project<\/strong><\/h2>\n\n\n\n<p>Let&#8217;s start by installing the express framework to the Node.js project. Using npm, install the express framework.<\/p>\n\n\n\n<p><code># installing express web framework<br>npm install express --save<\/code><\/p>\n\n\n\n<p>The above command installs the express framework to the node-project. Now, if you check the package1.json file, you will have the express module details saved in the package1.json file as a dependency.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{\n&nbsp;&nbsp;\"name\": \"project\",\n&nbsp;&nbsp;\"version\": \"1.0.1\",\n&nbsp;&nbsp;\"description\": \"Test\",\n&nbsp;&nbsp;\"main\": \"home.js\",\n&nbsp;&nbsp;\"scripts\": {\n&nbsp;&nbsp;&nbsp;&nbsp;\"test\": \"echo \\\"Error: no test is specified\\\" &amp;&amp; exit 1\"\n&nbsp;&nbsp;},\n&nbsp;&nbsp;\"author\": \"\",\n&nbsp;&nbsp;\"license\": \"IS\",\n&nbsp;&nbsp;\"dependencies\": {\n&nbsp;&nbsp;&nbsp;&nbsp;\"express\": \"^4.16.4\"\n&nbsp;&nbsp;}\n}\n<\/pre>\n\n\n\n<p>Create a file called app1.js and add the following code to it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">const express = require('express')\nconst app = express()\nconst port = 3000\napp.get('\/', (req, res) =&gt; res.send(\"Welcome to setting up Node.js project !'))\napp.listen(port, () =&gt; console.log(`Application listen\n<\/pre>\n\n\n\n<p><strong>Step 2: <\/strong>Installing create-react-app<\/p>\n\n\n\n<p>By using NodeJS\/NPM should be installed on your machine, so you can run the command:<\/p>\n\n\n\n<p><code>npm install -g create-react-app<\/code><\/p>\n\n\n\n<p>Now, install create-react-app globally so we can use it anywhere.<\/p>\n\n\n\n<p>Let&#8217;s Create a New React App<\/p>\n\n\n\n<p>Use create-react-app installed, so we can create a new app by running this command:<\/p>\n\n\n\n<p><code>create-react-app my-react-tutorial-app<br>cd my-react-tutorial-app<\/code><\/p>\n\n\n\n<p>The above command will use to create a new directory.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">my-react-tutorial-app\n{\n&nbsp;\"name\": \"my-react-tutorial-app\",\n&nbsp;\"version\": \"0.1.0\",&nbsp;&nbsp;\n&nbsp;\"private\": true,\n&nbsp;\"dependencies\": {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"react\": \"^16.5.2\",\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"react-dom\": \"^16.5.2\",\n&nbsp;},\n&nbsp;\"devDependencies\": {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"react-scripts\": \"1.0.7\"\n&nbsp;&nbsp;&nbsp;},\n&nbsp;&nbsp;&nbsp;\"scripts\": {\n&nbsp;&nbsp;\"start\": \"react-scripts start\",\n&nbsp;&nbsp;\"build\": \"react-scripts build\",\n&nbsp;&nbsp;\"test\": \"react-scripts test --env=jsdom\",\n&nbsp;&nbsp;\"eject\": \"react-scripts eject\"\n&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;\n}\n{\n&nbsp;&nbsp;\"name\": \"my-react-tutorial-app\",\n&nbsp;&nbsp;\"version\": \"0.1.0\",\n&nbsp;&nbsp;\"private\": true,\n&nbsp;&nbsp;\"dependencies\": {\n&nbsp;&nbsp;&nbsp;&nbsp;\"@babel\/core\": \"7.1.0\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"@svgr\/webpack\": \"2.4.1\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"babel-core\": \"7.0.0-bridge.0\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"babel-eslint\": \"9.0.0\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"babel-jest\": \"23.6.0\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"babel-loader\": \"8.0.4\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"babel-plugin-named-asset-import\": \"^0.2.2\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"babel-preset-react-app\": \"^5.0.2\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"bfj\": \"6.1.1\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"case-sensitive-paths-webpack-plugin\": \"2.1.2\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"chalk\": \"2.4.1\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"css-loader\": \"1.0.0\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"dotenv\": \"6.0.0\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"dotenv-expand\": \"4.2.0\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"eslint\": \"5.6.0\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"eslint-config-react-app\": \"^3.0.3\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"eslint-loader\": \"2.1.1\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"eslint-plugin-flowtype\": \"2.50.1\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"eslint-plugin-import\": \"2.14.0\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"eslint-plugin-jsx-a11y\": \"6.1.1\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"eslint-plugin-react\": \"7.11.1\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"file-loader\": \"2.0.0\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"fs-extra\": \"7.0.0\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"html-webpack-plugin\": \"4.0.0-alpha.2\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"identity-obj-proxy\": \"3.0.0\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"jest\": \"23.6.0\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"jest-pnp-resolver\": \"1.0.1\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"jest-resolve\": \"23.6.0\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"mini-css-extract-plugin\": \"0.4.3\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"optimize-css-assets-webpack-plugin\": \"5.0.1\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"pnp-webpack-plugin\": \"1.1.0\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"postcss-flexbugs-fixes\": \"4.1.0\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"postcss-loader\": \"3.0.0\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"postcss-preset-env\": \"6.0.6\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"postcss-safe-parser\": \"4.0.1\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"react\": \"^16.5.2\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"react-app-polyfill\": \"^0.1.3\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"react-dev-utils\": \"^6.0.3\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"react-dom\": \"^16.5.2\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"resolve\": \"1.8.1\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"sass-loader\": \"7.1.0\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"style-loader\": \"0.23.0\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"terser-webpack-plugin\": \"1.1.0\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"url-loader\": \"1.1.1\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"webpack\": \"4.19.1\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"webpack-dev-server\": \"3.1.9\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"webpack-manifest-plugin\": \"2.0.4\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"workbox-webpack-plugin\": \"3.6.2\"\n&nbsp;&nbsp;},\n&nbsp;&nbsp;\"scripts\": {\n&nbsp;&nbsp;&nbsp;&nbsp;\"start\": \"node scripts\/start.js\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"build\": \"node scripts\/build.js\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"test\": \"node scripts\/test.js\"\n&nbsp;&nbsp;},\n&nbsp;&nbsp;\"eslintConfig\": {\n&nbsp;&nbsp;&nbsp;&nbsp;\"extends\": \"react-app\"\n&nbsp;&nbsp;},\n&nbsp;&nbsp;\"browserslist\": [\n&nbsp;&nbsp;&nbsp;&nbsp;\"&gt;0.2%\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"not dead\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"not ie &lt;= 11\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"not op_mini all\"\n&nbsp;&nbsp;],\n&nbsp;&nbsp;\"jest\": {\n&nbsp;&nbsp;&nbsp;&nbsp;\"collectCoverageFrom\": [\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"src\/**\/*.{js,jsx}\"\n&nbsp;&nbsp;&nbsp;&nbsp;],\n&nbsp;&nbsp;&nbsp;&nbsp;\"resolver\": \"jest-pnp-resolver\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"setupFiles\": [\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"react-app-polyfill\/jsdom\"\n&nbsp;&nbsp;&nbsp;&nbsp;],\n&nbsp;&nbsp;&nbsp;&nbsp;\"testMatch\": [\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"&lt;rootDir&gt;\/src\/**\/__tests__\/**\/*.{js,jsx}\",\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"&lt;rootDir&gt;\/src\/**\/?(*.)(spec|test).{js,jsx}\"\n&nbsp;&nbsp;&nbsp;&nbsp;],\n&nbsp;&nbsp;&nbsp;&nbsp;\"testEnvironment\": \"jsdom\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"testURL\": \"http:\/\/localhost\",\n&nbsp;&nbsp;&nbsp;&nbsp;\"transform\": {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"^.+\\\\.(js|jsx)$\": \"&lt;rootDir&gt;\/node_modules\/babel-jest\",\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"^.+\\\\.css$\": \"&lt;rootDir&gt;\/config\/jest\/cssTransform.js\",\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"^(?!.*\\\\.(js|jsx|css|json)$)\": \"&lt;rootDir&gt;\/config\/jest\/fileTransform.js\"\n&nbsp;&nbsp;&nbsp;&nbsp;},\n&nbsp;&nbsp;&nbsp;&nbsp;\"transformIgnorePatterns\": [\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"[\/\\\\\\\\]node_modules[\/\\\\\\\\].+\\\\.(js|jsx)$\",\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"^.+\\\\.module\\\\.(css|sass|scss)$\"\n&nbsp;&nbsp;&nbsp;&nbsp;],\n&nbsp;&nbsp;&nbsp;&nbsp;\"moduleNameMapper\": {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"^react-native$\": \"react-native-web\",\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"^.+\\\\.module\\\\.(css|sass|scss)$\": \"identity-obj-proxy\"\n&nbsp;&nbsp;&nbsp;&nbsp;},\n&nbsp;&nbsp;&nbsp;&nbsp;\"moduleFileExtensions\": [\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"web.js\",\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"js\",\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"json\",\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"web.jsx\",\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"jsx\",\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"node\"\n&nbsp;&nbsp;&nbsp;&nbsp;]\n&nbsp;&nbsp;},\n&nbsp;&nbsp;\"babel\": {\n&nbsp;&nbsp;&nbsp;&nbsp;\"presets\": [\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"react-app\"\n&nbsp;&nbsp;&nbsp;&nbsp;]\n&nbsp;&nbsp;}\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>NPM package manager for the Node.js using the packages, or modules if you like. www.npmjs.com hosts thousands of free packages to download and use. NPM program should be installed on your computer when you install Node.js. Now, NPM is ready to run on your computer! What is a Package? A package in Node.js which contains [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5091,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[42],"tags":[1414,1413],"class_list":["post-5055","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java-tutorials","tag-set-up-node-js","tag-setup-npm"],"_links":{"self":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/5055","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/comments?post=5055"}],"version-history":[{"count":0,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/5055\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media\/5091"}],"wp:attachment":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media?parent=5055"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/categories?post=5055"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/tags?post=5055"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}