Gadgets Gaming News Photograph Science

How to Set Up A Node.js Development Environment – Information Technology Blog

Delivering great software is the goal. Delivering great software fast? Now, that is the ultimate goal. Thus, a few hacks and shortcuts can really come in handy.

For those who rely heavily on Node.js on coding tasks and wants to breeze through setting up and to immediately get coding, here’s a guide on how we set up a Node.js development environment for a particular project:

What is Node.js?

If you’re new to web development, it can be a bit confusing as to what exactly node.js is and to what you should do with it, and there’s a lot of information out there…most of which seems to be tailored towards genius-level developers.

We’re going to cover the difference between javascript in a browser vs javascript in node.js and the common uses for node.js.

To wrap it up, we’re going to spin up a quick web server in node.js just to show you how easy it is.

Install NPM and Node.js

Of course, to get things started you need to install npm, and Node.js. You can easily do that by downloading them from here.

Create a project folder

Navigate to your folder by using your favorite terminal. Proceed to creating a package.json file in that folder. This will save all the libraries you use. Using the terminal, run the command $ npm init . Write a few details about your project.

The web framework

This should be project based, but we recommend Express.js as it is 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 $ npm install express –save.

The testing framework

To 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 $ npm install –save-dev mocha.Here, we also need to mention the assertion library. It really makes life easier. We recommend Chai.js, as it exposes all interfaces of asset. Just run $ npm install –save-dev chai in your terminal to install.

The IDE

We’ve chosen Visual Studio Code over the more widely preferred Sublime Text, as it has a native support for Node.js debugging. Also, easier to adopt for beginner- developers. You can get this free piece of software from here.

The linter

ESLint, being the most popular linter for Javascript is more preferable. Also, it 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 $ npm install eslint –save-dev in your terminal. To make it aware of Node.js and Mocha you need to install these Eslint plugins as well:
– Eslint-node: $ npm install –save-dev eslint-plugin-node
– Eslint-mocha: $ npm install –save-dev eslint-plugin-mocha

The coding standards:

The Airbnb coding standard is one of the most popular coding standard for JavaScript and Node.js for a reason. In your terminal, run $./node_modules/.bin/eslint –init and choose Airbnb as your coding standard. After that, open the newly .eslintrc.json  file that was created, and add “mocha” and “node” in the file. Basically that file needs to look like this, if you saved the file using JSON format:

json - How to Set Up A Node.js Development Environment

Install the ESLint plugin in VS Code

Go into the VS Code app and navigate to its Extensions page. Search after “eslint”, and install the first result from the list. Restart VS Code.

Now you’re all set, start coding and enjoy!

Source: IntelligentBee

Originally posted 2017-07-24 17:24:52. Republished by Blog Post Promoter