{"id":2358,"date":"2017-06-12T12:12:08","date_gmt":"2017-06-12T12:12:08","guid":{"rendered":"https:\/\/intelligentbee.com\/blog\/?p=2358"},"modified":"2024-08-28T12:16:24","modified_gmt":"2024-08-28T12:16:24","slug":"how-set-up-node-js-development-environment","status":"publish","type":"post","link":"https:\/\/intelligentbee.com\/blog\/how-set-up-node-js-development-environment\/","title":{"rendered":"How to set up a Node.js development environment"},"content":{"rendered":"<h2><strong>Context:<\/strong><\/h2>\n<p>Here at IntelligentBee we wanted to establish a few ground rules that all of our developers should follow when developing an app in <a href=\"https:\/\/intelligentbee.com\/nodejs-development-company\">Node.js<\/a>. In that way all of us would be familiar with a particular set of tools, something that would make us deliver better software, fast. Here is how we set up a Node.js development environment for a particular project:<\/p>\n<ul>\n<li><strong>Installing NPM and Node.js<\/strong><br \/>\nTo get things started you need to install npm, and Node.js. You can easily do that by downloading them from <a id=\"dev\" href=\"https:\/\/nodejs.org\/en\/download\/\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>.<\/li>\n<li><strong>Create a project folder<\/strong>, and navigate to it using your favorite terminal. Then create a <strong>package.json<\/strong> file in that folder, a file that will save all the libraries you use. Using the terminal,\u00a0run the command <span class=\"lang:default decode:true crayon-inline\">$ npm init<\/span>\u00a0. Write a few details about your project, and that\u2019s it.<\/li>\n<li><strong>The web framework<\/strong><br \/>\nThis should be project based, but we recommend Express.js as it the most mature and widely used framework for Node.js. From the Terminal, navigate to the folder where you will build your project, and run <span class=\"lang:default decode:true crayon-inline \">$ npm install express &#8211;save<\/span><\/li>\n<li><strong>The testing framework<\/strong><br \/>\nTo deliver robust code, you need to write tests. Node.js has a lot of testing frameworks available, but Mocha.js is by far the most used and proven test framework out there. To install, run <span class=\"lang:default decode:true crayon-inline \">$ npm install &#8211;save-dev mocha<\/span>\u00a0.Here we also need to mention the assertion library that can make life even easier. We recommend Chai.js, as it exposes all interfaces of asset, should and expect. Just run <span class=\"lang:default decode:true crayon-inline \">$ npm install &#8211;save-dev chai<\/span>\u00a0 in your terminal to install.<\/li>\n<li><strong>The IDE<\/strong><br \/>\nWe\u2019ve chosen Visual Studio Code over the more widely preferred Sublime Text, as it has a native support for Node.js debugging. Also, it is pretty easy for newer, less experienced developers to adopt it. You can get this free piece of software from <a href=\"https:\/\/code.visualstudio.com\/download\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>.<\/li>\n<li><strong>The linter<\/strong><br \/>\nWe decided to go with <strong>ESLint<\/strong>, as it is the most popular linter for Javascript and has a plugin for linting Node.js code. It is recommended that you install ESLint in the project folder that you work in, but you could also install it globally. To install it for your project, run <span class=\"lang:default decode:true crayon-inline \">$ npm install eslint &#8211;save-dev<\/span>\u00a0 in your terminal. To make it aware of Node.js and Mocha you need to install these Eslint plugins as well:<br \/>\n&#8211; Eslint-node: <span class=\"lang:default decode:true crayon-inline \">$ npm install &#8211;save-dev eslint-plugin-node<\/span><br \/>\n&#8211; Eslint-mocha: <span class=\"lang:default decode:true crayon-inline\">$ npm install &#8211;save-dev eslint-plugin-mocha<\/span><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul>\n<li>\n<h3><strong>The coding standards:<\/strong><\/h3>\n<p>The Airbnb coding standard is one of the most popular out there, for JavaScript and Node.js. That would help you write clean code, that will be easier to understand later on, or by other people. In your terminal, run <span class=\"lang:default decode:true crayon-inline \">$ .\/node_modules\/.bin\/eslint &#8211;init<\/span>\u00a0 and choose Airbnb as your coding standard. After you do that, you need to open the newly <span class=\"lang:default decode:true crayon-inline \">.eslintrc.json<\/span>\u00a0\u00a0file that was created, and add &#8220;mocha&#8221; and &#8220;node&#8221; in the file. Basically that file needs to look like this, if you saved the file using JSON format:<\/li>\n<\/ul>\n<pre class=\"width-set:true width:300 h-align:2 lang:default decode:true right-margin: left-margin: right-margin: right-margin:\">{\r\n\t\"extends\": \"airbnb-base\",\r\n\t\"plugins\": {\r\n\t\t\"import\",\r\n\t\t\"mocha\",\r\n\t\t\"node\"\r\n\t}\r\n}<\/pre>\n<ul>\n<li><strong>Install the ESLint plugin in VS Code<\/strong><br \/>\nGo into the VS Code app, and navigate to its Extensions page. Search after &#8220;eslint&#8221;, and install the first result from the list. Restart VS Code.<\/li>\n<\/ul>\n<p>Now\u00a0you should be all set up and\u00a0start coding. Enjoy!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Context: Here at IntelligentBee we wanted to establish a few ground rules that all of our developers should follow when [&hellip;]<\/p>\n","protected":false},"author":28,"featured_media":2387,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73,77],"tags":[],"yst_prominent_words":[394,426,970,990,1013,1888],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/posts\/2358"}],"collection":[{"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/users\/28"}],"replies":[{"embeddable":true,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/comments?post=2358"}],"version-history":[{"count":4,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/posts\/2358\/revisions"}],"predecessor-version":[{"id":133195,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/posts\/2358\/revisions\/133195"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/media\/2387"}],"wp:attachment":[{"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/media?parent=2358"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/categories?post=2358"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/tags?post=2358"},{"taxonomy":"yst_prominent_words","embeddable":true,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/yst_prominent_words?post=2358"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}