Visual Studio Code supports many features for JavaScript and Node.js development. The features that ship with the downloaded product are the core features: debugging, IntelliSense, code navigation, etc. In addition, to these core features, you can install a large number of quality extensions to add features to VS Code for JavaScript development. Visual Studio Code has a large amount of functionality built in, including support for debugging applications. However, configuring VS Code to debug Node.js can be counterintuitive. In this article, you will configure VS Code to debug Node.js by downl. Launch or attach to your Node.js processes and debug JavaScript code right in the editor - with breakpoints, a full call stack, and an interactive debugging console. IntelliSense: JavaScript APIs at your fingertips. Bracket Pair Colorizer 2. I try to keep my code as simple as possible and not nest.
As we know, Node.js is just advanced version of server side JavaScript programming , so all file we create in this app will be saved with .js extension, just like any other JavaScript file.
In previous article we have read what is node.js? and why to learn node js development. Now we are going to create Node Js App using Visual Studio Code Editor.
Learn how to create a simple NodeJs Application
First we create a folder for our app, let's call that 'wtr-nodeapp' you can give any name. Remember in node console we can write same dos command for files and folders , Go to the drive you want to create your folder just by typing cd e:
Then create the folder mkdir wtr-nodeapp
Now follow the following few steps carefully, simple step , but understand how it works with VS Editor
- 1. Click on explorer, then create a file called app.js (you can give any name)
- 2. Write simple javascript in the file.
- 3. Save the file ( File=> Save), Don't forget
- 4. Now call the file from console just by typing node app.js
To open a new terminal click on 'Terminal' => 'New Terminal'.
Before you execute node filename.js
command, make sure you are at the right file location, means the folder path where you have saved the file
As you can see in the above screen, 'Hello Avishkar, Welcome to WTR'
is the result of executing the Javascript file.
Exports in Node Js
Now we learn how to use exports in node application.
When we want some function to be accessed outside the module then we need to use exports, suppose in above example we want some functionality to be accessible in different file, then we have to write them with 'exports'
keywords, let's look at the example below
Now we call the function written in above file from a different JavaScript file below.
Built-in Modules
When we install Node it comes with many Built-in Modules. Here are some of the most commonly used core modules.
- http: create HTTP servers and clients for web application development.
- fs: This module allows you to manipulate files and directories on server.
- path: Useful to work with directories and files paths.
- url: Used for parsing URLs and extracting values from it
Create Node Js Project In Visual Studio Code
You can add any module just by executing npm command like npm install package_name
. for example, execute following command to install express module.
Node http module example
Create Dynamic Content from JavaScript Server Side
We need to include some module for this task loader.js
Node fs module example
Fs module is used when we want to work with file system, like creating, reading, editing, deleting file from server, here i have given a small example of reading file in node application.
In my application I have a file called 'content.txt' , in application we will be reading the content using fs module
I have created a small JavaScript file called fso.js (you can give any name) with following code, then calling the file in node terminal to see the result.
To call any JavaScript file, go to file location and execute the node command like example below.
Node Js Visual Studio 2017
Learn more about each module in following links: