Hi friends, it has been a while since my last post. But I am back with a small introduction of NodeJS for VS 2017.
A lot of .Net developers (me included) we don’t want to give up using VS for other non .Net type of projects. I was playing a little bit with VS2017 version and its integration to several new templates. In this post I am going to talk about NodeJS projects.
Well, I suppose we all know what is NodeJS if not I am going to explain it in one sentence: It is server side code written in JavaScript. If you want to know more you can google it because there are a lot of great explanations out there.
Open VS and let’s create a new project (NodeJS one) and we can see different types of templates for NodeJS:
For this post we created a Web Application named HelloWorld (I know, I am not very original). As we can see on the left side the template it’s going to contain the necessary code to create the server and the http objects.
The solution will automatically contain a project with the same name. This project contains:
- NPM: all the needed dependencies for the project. Later I am going to explain how to install those dependencies.
- Package.json: It serves as documentation for what packages your project depends on. Also, gives information about the application.
- Readme.md: a simple text file you can put some notes of the project.
- Server.js: main JavaScript file.
If we execute the code it will work but nothing is going to happen because there is no render code.
As I mention before, NodeJS projects are not like .Net projects where the dependencies is managed by the Nugget Package. So the way to install those dependencies is quite different. First of all we should know what package we want to install to our project, chekc this https://www.npmjs.com/ to find the package name.
Once you have the package name, you can use the following steps to add in package.json directly.
- Open up the package.json and type the name and the version of the package on “dependencies”. You may write the “dependencies” tag.
In my expemple I want to install “express” with the version “4.15.4”. Save the package.json and magic will happen. Automatically will start to install the package. If you go to the “nmp” section you will notice that.
If it still missing, right click and “Install Missing npm Pacakge(s)”.
And that’s all! Easy right? Now enjoy coding amazing applications in NodeJS. Good luck!