How to set up your javascript development environment (PART 2)

Building a javascript development environment from scratch can be overwhelming, but with a custom template, you can save you and your teams’ precious time.

Regardless of your stack or role, client or server-side. We are going to be building a powerful and interactive javascript environment that enables you to kickstart your project in no time.

Before, we begin, the project repository can be found here.

To build a robust javascript development environment, we shall be considering a lot of things which I have divided under subtopics as below:

https://www.malditanerea.com/Video-dyatlof-3.html
https://www.espinaler.com/dev/Video-grosniy-3.html
https://www.aepcc.org/tpv/Video-drpreob-2.html
https://www.flamencoonfire.org/Video-grosniy-1.html
https://www.vlsu.ru/uploads/Video-drpreob-1.html
http://www.rockdelux.com/sur/Video-meglin-3.html
https://www.vlsu.ru/uploads/Video-grosniy-2.html
https://www.aepcc.org/tpv/Video-dyatlof-2.html
https://www.martinazua.com/2020/Video-drpreob-3.html
https://www.espinaler.com/dev/Video-meglin-1.html
https://www.malditanerea.com/Video-drpreob-4.html
https://www.flamencoonfire.org/Video-meglin-5.html
https://www.vlsu.ru/uploads/Video-dyatlof-4.html
https://www.martinazua.com/2020/Video-meglin-4.html
https://www.shoko.biz/Video-meglin-2.html
https://www.shoko.biz/Video-dyatlof-1.html

  1. Editors and Environments
  2. Package Management
  3. Development Web Server
  4. Automation
  5. Transpiling
  6. Bundling
  7. Linting
  8. Testing and Configuration
  9. Http Calls
  10. Project Structure
  11. Production Build
  12. Production Deploy
  13. Editors and Environments

For several reasons, choosing a code editor can be a subject of debate among engineers.

However, regardless of your preference, the following code editors are still good choices to pick from.

  1. Atom
  2. Webstorm
  3. Bracket
  4. VSCode

I use VSCode but all of these code editors offer

Good intellisense so you can go beyond syntax highlighting and autocomplete with IntelliSense, which provides smart completions based on variable types, function definitions, and imported modules.

Git commands built-in.

You can review diffs, stage files, and make commits right from the editor. Push and pull from any hosted SCM service.

2. Package Management

When managing your javascript-based project, there are arrays of package managers you can choose from:

Npm, Bower, jspm, jam, Volo

Bower:

Bower can manage components that contain HTML, CSS, JavaScript, fonts or even image files. Bower doesn’t concatenate or minify code or do anything else — it just installs the right versions of the packages you need and their dependencies.

However, over the years, npm which is the package manager for the Node JavaScript platform has toppled bower and is now the most used package manager for several reasons ( which is not the scope of this discussion).

We will be using npm throughout the course of this project.

3. Development Web Server

So, enough of the stories, let’s get into business. Of course, when you are starting a javascript project, you will want to consider having a development web server.

Just like the package managers, there are arrays of web servers to choose from.

  • Http-server
  • live-server

Or even function based servers such as

  • Express
  • Budo
  • Webpack dev server

For the sake of this project, we will be using Express

Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications.

Let us start by setting up our project :

npm init

Npm init creates a package.json file for you, we will install several dependencies which we will be using at different steps during the course of the project.

Copy the following data into your package.json file.

Run npm install to install all the dependencies

Now that you have dependencies installed, to ensure uniformity and make sure that everybody has the same editor configuration, install the editorconfig plugin on your code editor

  • Create a .editorconfig file and copy the following into it
  • You can also get the configuration at the editorconfig website here

# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
# insert_final_newline = true

# Matches multiple files with brace expansion notation
# Set default charset
[*.{js,py}]
charset = utf-8

# Indentation override for all JS under lib directory
[lib/**.js]
indent_style = space
indent_size = 2

# Matches the exact files either package.json or .travis.yml
[{package.json,.travis.yml}]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false

Using this ensures we are following a uniform standard of code editing.

3.1 Security

We are building a robust javascript development environment, security is not an option. Thankfully, node has its own built-in security platform called node security platform.

The Node Security Platform is a suite of continuous security products and services focused on helping you ship and maintain secure node software. We can install it globally using the command

npm i -g nsp

We can use the nsp command nsp check to run a series of checks against our dependencies.

3.2 Express

Now that we have installed necessary dependencies and checked for vulnerabilities, let us now set up express. To install express, just like we did for nsp, run npm install express.

Create a folder called buildScripts.js in your root directory and create a file srcServer.js inside it.

Inside srcServer.js, type the following lines of code

import express from express;
import path from ‘path’;
import open from open;

var port = 3000; // we declared the port in which our server is going to be running
var app = express();

app.get(‘/’, (req, res)=>{
res.sendFile(path.join(__dirname, ‘../src/index.html’))
});

app.listen(port, (err)=>{
if(err){
console.log(err);
}
else{
open(‘http://localhost:’ + port)
}
});

So, basically we import express, path and open modules. Path and open are built in node js modules which we can import at any time during our project without having to install them separately. We also used the express() syntax which is the equivalent of saying new express(). It creates a new instance of express that you can then assign to a variable and interact with. We also required a file (index.html) which we are going to be creating shortly, we hope to render this file anytime we run the server.

Lastly, we listened to our port (3000) and logged an error in the case where we encountered an error.

So with this, we have a basic server running on a predefined port.

3.3 Sharing your work in progress

I understand that at any point in time during the course of building a project, you might want to share your work in progress. That shouldn’t be a difficult thing really. There are different ways to share your ongoing work. There are different platforms which offer this functionality. These includes

  • Ngrok
  • LocalTunnel
  • Now
  • Surge

While each offers its own relative advantages and disadvantages over each other. I’ll advise you to check their documentation to learn more. I chose local tunnel because of its simplicity.

Install localtunnel globally by running npm install localtunnel -g

Then run lt-h “http://serverless-social” -p -3000 where 3000 refers to the port you are running on. Local tunnel works by quickly deploying node to the cloud and gives you an access link immediately

3.4 Conclusion

In order not to bore you out, I have decided to split this article into parts. So far, we have been able to cover important requirements to build a secure and effective javascript development area.

In Part 2 of this article , we will be treating subheading 4–7

  • Automation
  • Transpiling
  • Bundling
  • Linting