{"id":87557,"date":"2023-05-20T09:00:24","date_gmt":"2023-05-20T03:30:24","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=87557"},"modified":"2023-05-20T09:00:24","modified_gmt":"2023-05-20T03:30:24","slug":"nodejs-installation","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/nodejs-installation\/","title":{"rendered":"Install Node.js in Easy Steps"},"content":{"rendered":"<p>Node.js is an open-source, cross-platform, server-side JavaScript runtime environment that allows developers to build scalable and high-performance web applications using JavaScript. Setting up a Node.js development environment is the first step in getting started with Node.js development. In this article, we will walk you through the steps required to install Node.js development environment on your machine. By following these steps, you can start building Node.js applications and take advantage of the many benefits that Node.js has to offer.<\/p>\n<h3>How to setup an Environment for NodeJs<\/h3>\n<p>Setting up Node.js for development can be a simple process with just a few steps. In this article, we will discuss how to set up the environment for Node.js<\/p>\n<h4>Step 1: Download and Install Node.js<\/h4>\n<ul>\n<li>Go to the <a href=\"https:\/\/nodejs.org\/en\/download\/\">official Node.js website<\/a> and download the recommended LTS (Long-Term Support) version for Windows.<\/li>\n<li>Once the download is complete, double-click on the downloaded .msi file to launch the installer.<\/li>\n<li>Follow the on-screen instructions to complete the installation. You can choose the default installation settings or customize them as needed.<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-87794\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/nodejs-lts.webp\" alt=\"nodejs lts\" width=\"697\" height=\"327\" \/><\/p>\n<h4>Step 2: Verify Installation<\/h4>\n<ul>\n<li>Once the installation is complete, open the command prompt by pressing the Windows key + R and then typing &#8220;cmd&#8221; in the Run dialog box.<\/li>\n<li>Type &#8220;node -v&#8221; in the command prompt to check if Node.js is installed correctly. If it is installed, the version number will be displayed.<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-87796\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/nodejs-version-1.webp\" alt=\"nodejs version\" width=\"778\" height=\"228\" \/><\/p>\n<h4>Step 3: Create a Project<\/h4>\n<ul>\n<li>Open your terminal or command prompt and create a new directory for your project. You can do this by typing the following command: <strong>\u2018mkdir my-nodejs-project\u2019.<\/strong><\/li>\n<li>Change into the newly created directory by typing <strong>\u2018cd my-nodejs-project\u2019.<\/strong><\/li>\n<li>Initialize a new Node.js project by typing<strong> \u2018npm init\u2019<\/strong> in the terminal. This will prompt you to provide some information about your project, such as the name, version, and description.<\/li>\n<li>Follow the prompts and fill in the necessary information. You can use the default settings or customize them as needed.<\/li>\n<li>Once the initialization is complete, a<strong> \u2018package.json\u2019<\/strong> file will be created in your project directory. This file contains information about your project, as well as a list of dependencies that your project requires to run.<\/li>\n<li>Install any necessary dependencies by typing <strong>\u2018npm install &lt;package-name&gt;\u2019<\/strong> in the terminal. For example, if you need to install the Express.js framework, you would type<strong> \u2018npm install express\u2019.<\/strong><\/li>\n<\/ul>\n<h4>Step 4: Install Dependencies<\/h4>\n<p>To install dependencies for your project, use the &#8220;npm install&#8221; command followed by the name of the package you want to install. For example, &#8220;npm install express&#8221; will install the Express.js package.<\/p>\n<h4>Step 5: Create a Server<\/h4>\n<p>To create a basic server in Node.js, create a new JavaScript file in your project folder and add the following code:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">const http = require('http');\nconst hostname = '127.0.0.1';\nconst port = 8000;\nconst server = http.createServer((req, res) =&gt; {\nres.statusCode = 200;\nres.setHeader('Content-Type', 'text\/plain');\nres.end('Hello, World!\\n');\n});\nserver.listen(port, hostname, () =&gt; {\nconsole.log(`Server running at http:\/\/${hostname}:${port}\/`);\n});<\/pre>\n<p>This code creates a server that listens on port 3000 and responds with a &#8220;Hello, World!&#8221; message.<\/p>\n<h4>Step 6: Run the Server<\/h4>\n<p>To run the server, type &#8220;node&#8221; followed by the name of your JavaScript file. For example, &#8220;node server.js&#8221;. This will start the server and you should see a message in the terminal that says &#8220;Server running at http:\/\/127.0.0.1:8000\/ &#8220;. something like this<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-87797\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/nodejs-server.webp\" alt=\"nodejs server\" width=\"718\" height=\"278\" \/><\/p>\n<h3>Setting up NodeJS for MAC:<\/h3>\n<p>1. Open your web browser and go to the official <a href=\"https:\/\/nodejs.org\/en\/download\/\">Node.js website<\/a>.<\/p>\n<p>2. Download the recommended LTS (Long-Term Support) version for Mac by clicking on the &#8220;macOS Installer&#8221; button.<\/p>\n<p>3. Once the download is complete, open the downloaded .pkg file to launch the installer.<\/p>\n<p>4. Follow the on-screen instructions to complete the installation. You can choose the default installation settings or customize them as needed.<\/p>\n<p>5. Once the installation is complete, open your terminal and type <strong>node -v<\/strong> to check if Node.js is installed correctly. If it is installed, the version number will be displayed.<\/p>\n<p>6. To set up the Node.js environment variables, open the Terminal app and type <strong>nano ~\/.bash_profile<\/strong> to open the bash profile file.<\/p>\n<p>7. Add the following line at the end of the file to set the PATH variable to the location of the Node.js binary:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">export PATH=\"\/usr\/local\/bin:$PATH\"<\/pre>\n<p>8. Save the changes by pressing <strong>CTRL + X<\/strong>, then<strong> Y<\/strong>, and then <strong>Enter<\/strong>.<\/p>\n<p>9. To apply the changes to the current terminal session, type <strong>source ~\/.bash_profile<\/strong> in the terminal.<\/p>\n<p>10. Verify that the environment variables have been set correctly by typing<strong> echo $PATH<\/strong> in the terminal. The output should include the path to the Node.js binary.<\/p>\n<h3>Supporting browser:<\/h3>\n<p>When building a web application, it&#8217;s important to consider the browsers that your users will be using. Different browsers have different capabilities and support for web standards. To ensure your application works well across a variety of browsers, it&#8217;s important to test it in multiple browsers.<\/p>\n<p>The most commonly used browsers are Google Chrome, Mozilla Firefox, Microsoft Edge, and Apple Safari. These browsers have a large user base and are regularly updated to support the latest web standards. It&#8217;s important to test your application in these browsers to ensure it works well for the majority of your users.<\/p>\n<p>In addition to these popular browsers, it&#8217;s also important to consider less common browsers, such as Opera, Brave, and Vivaldi. While they may have a smaller user base, it&#8217;s still important to ensure your application works well in these browsers to provide the best experience for all users.<\/p>\n<h3>Installing the Express Application Generator in Node.js:<\/h3>\n<p>The Express Application Generator is a command-line tool that helps you quickly create an Express.js web application. To install the generator, you need to have Node.js installed on your system. If you don&#8217;t have Node.js installed, you can download it from the official website.<br \/>\nOnce you have Node.js installed, you can install the Express Application Generator using npm, the Node.js package manager. Open your terminal or command prompt and run the following command:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">npm install -g express-generator<\/pre>\n<p>This will install the generator globally on your system. Once the installation is complete, you can use the<strong> express<\/strong> command to generate a new Express.js application.<br \/>\nTo create a new application, navigate to the directory where you want to create the application and run the following command:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">express myapp<\/pre>\n<p>This will create a new directory called <strong>myapp<\/strong> with the basic structure of an Express.js application. You can then navigate into the directory and install the dependencies using the following commands:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">cd myapp\nnpm install<\/pre>\n<p>This will install all the required dependencies for the application. You can then start the application using the following command:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">npm start<\/pre>\n<h3>Conclusion:<\/h3>\n<p>Setting up a Node.js development environment is an essential step for building server-side applications using JavaScript. In this article, we walked you through:<\/p>\n<ul>\n<li>The steps required to set up a Node.js development environment<\/li>\n<li>Including installing Node.js.<\/li>\n<li>verifying the installation.<\/li>\n<li>Installing a text editor.<\/li>\n<li>Creating a new Node.js project<\/li>\n<\/ul>\n<p>By following these steps, you can start building Node.js applications and take advantage of the many benefits that Node.js has to offer.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Node.js is an open-source, cross-platform, server-side JavaScript runtime environment that allows developers to build scalable and high-performance web applications using JavaScript. Setting up a Node.js development environment is the first step in getting started&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":87559,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4984],"tags":[4986,4987,4988],"class_list":["post-87557","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-node-js-tutorials","tag-install-nodejs","tag-nodejs-environment-setup","tag-nodejs-installation"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Install Node.js in Easy Steps - TechVidvan<\/title>\n<meta name=\"description\" content=\"See the steps to setup Node.js development environment - installing Node.js, verifying installation, Installing text editor, Creating project\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/nodejs-installation\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Install Node.js in Easy Steps - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"See the steps to setup Node.js development environment - installing Node.js, verifying installation, Installing text editor, Creating project\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/nodejs-installation\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-05-20T03:30:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2023\/04\/node-js-environment-setup.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Install Node.js in Easy Steps - TechVidvan","description":"See the steps to setup Node.js development environment - installing Node.js, verifying installation, Installing text editor, Creating project","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:\/\/techvidvan.com\/tutorials\/nodejs-installation\/","og_locale":"en_US","og_type":"article","og_title":"Install Node.js in Easy Steps - TechVidvan","og_description":"See the steps to setup Node.js development environment - installing Node.js, verifying installation, Installing text editor, Creating project","og_url":"https:\/\/techvidvan.com\/tutorials\/nodejs-installation\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2023-05-20T03:30:24+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2023\/04\/node-js-environment-setup.webp","type":"image\/webp"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/nodejs-installation\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/nodejs-installation\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Install Node.js in Easy Steps","datePublished":"2023-05-20T03:30:24+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/nodejs-installation\/"},"wordCount":1134,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/nodejs-installation\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2023\/04\/node-js-environment-setup.webp","keywords":["install nodejs","nodejs environment setup","nodejs installation"],"articleSection":["Node Js Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/nodejs-installation\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/nodejs-installation\/","url":"https:\/\/techvidvan.com\/tutorials\/nodejs-installation\/","name":"Install Node.js in Easy Steps - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/nodejs-installation\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/nodejs-installation\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2023\/04\/node-js-environment-setup.webp","datePublished":"2023-05-20T03:30:24+00:00","description":"See the steps to setup Node.js development environment - installing Node.js, verifying installation, Installing text editor, Creating project","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/nodejs-installation\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/nodejs-installation\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/nodejs-installation\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2023\/04\/node-js-environment-setup.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2023\/04\/node-js-environment-setup.webp","width":1200,"height":628,"caption":"node js environment setup"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/nodejs-installation\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Install Node.js in Easy Steps"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/87557","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=87557"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/87557\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/87559"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=87557"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=87557"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=87557"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}