Fundamentals of NodeJs

Categories learning, NodeJs
section1

In this blog post I´d like to tell you what I learned in the course I´m taking about NodeJS. I decided to document every Section what I learned. This Section is dedicated to the Fundamentals about NodeJs and Javascript. Let´s start of by learning more about Require.


Require does three things:

  • It loads modules that come bundled with Node.js like file system and HTTP from the Node.js API .
  • It loads third party libraries like Express and Mongoose that you install from npm.
  • It lets you require your own files and modularize the project.
    Require is a function, and it accepts a parameter “path” and returns module.exports.


What are Node Modules ?

A Node module is a reusable block of code whose existence does not accidentally impact other code.

You can write your own modules and use it in various application. Node.js has a set of built-in modules which you can use without any further installation.The node_modules folder is a libraries folder.

The package.json file in the app root defines what libraries will be installed into node_modules when you run npm install

Bsp of package.json

Other Stuff I learned in this Section


NodeMon

When you write node code, you spin up the server and see your changes. You make some changes and restart the server again to see the changes.
Nodemon will watch the files in the directory in which nodemon was started, and if any files change, nodemon will automatically restart your node application.

How to Install nodemon

You must install nodemon globally because it is a command line command. If you dont install nodemon globally it will only get installed in your directory you are currently in.

How to start nodemon

Go to your root directory of your app and type into the command line nodemon app.js
nodemon start

Now every time you make changes to your code and hit STRG + S nodemon will reload the server by itself. There is no need to restart the server manually.


Template Strings

In JavaScript we have double quotes and single quotes to make a string. Now we have a third way to make a string, and that is with back-ticks


Arrow Functions

What are Arrow Functions

Arrow functions – also called “fat arrow” functions, from CoffeeScript (a transcompiled language) — are a more concise syntax for writing function expressions. They utilize a new token, =>, that looks like a fat arrow. Arrow functions are anonymous and change the way this binds in functions.

Arrow functions make our code more concise, and simplify function scoping and the this keyword. They are one-line mini functions which work much like Lambdas in other languages like C# or Python. (See also lambdas in JavaScript). By using arrow functions, we avoid having to type the function keyword, return keyword (it’s implicit in arrow functions), and curly brackets.

In this Section I learned what require is also I learned how to use nodemon, Template Strings and Arrow Functions.

Have a greate day greetings.

Moritz

Leave a Reply

Your email address will not be published. Required fields are marked *