Table of contents
Hi, I'm Subham Maity, a software engineer. I also enjoy teaching others how to code through my tutorials. I'm always eager to learn new things and share my knowledge with the community.
⚡ I recently wrote an article on Fundamentals and Features of Node.js and wanted to share it with you all. You can find the article on my website https://codexam.vercel.app/docs/node/node1 [Better View]
⚡ I also have a repository on GitHub where you can find all the code and projects related to this topic. You can find the repository at https://github.com/Subham-Maity/node-js-full-stack-tutorial
❗ For a more in-depth look at this topic, including a detailed table of contents, check out the complete tutorial on my GitHub Repo
If you want to stay updated with my latest projects and articles, you can follow me on:
For NodeJs you need to have a basic knowledge of Javascript. If you are new to Javascript then you can check out my tutorial on Javascript
Some Important Notes
- Suppose you make a file
app.js
and another fileindex.js
and you want to import theapp.js
file like this
export const name = "Subham Maity"
export const age = 20
import {name,age} from "./app.js"
And in your terminal you run node index.js
then you will get an error like this
SyntaxError: Cannot use import statement outside a module
This is because NodeJs doesn't support the import
and export
syntax. So you have to use the module.exports
and require
syntax.
module.exports = {
name: "Subham Maity",
age: 20
}
const {name,age} = require("./app.js")
console.log(name,age)
Now if you run node index.js
then you will get the output like this.
Subham Maity 20
- You can even create a function in
app.js
and export it and then import it inindex.js
and use it.
module.exports = {
add: (a,b) => a+b
}
const app = require("./app.js")
console.log(app.add(2,3))
Now if you run node index.js
then you will get the output like this
5
What is filter in JavaScript ?
- If you have an array like this
const arr = [1,2,3,4,5,6,7,8,9,10]
and you want to traverse through the array and get the elements which are greater than 5 then you can use the filter
method.
const arr = [1,2,3,4,5,6,7,8,9,10]
const greaterThan5 = arr.filter((element) => element > 5)
console.log(greaterThan5)
Now if you run node index.js
then you will get the output like this.
[ 6, 7, 8, 9, 10 ]
- If you have an array like this
const arr1 = [1,2,3,4,4,4,5,6,7,8,9,10]
and you want to traverse and find the value that is repeated the most then you can use the filter
method.
const arr1 = [1,2,3,4,4,4,5,6,7,8,9,10]
const mostRepeated = arr1.filter((element) =>
{
return element === 4
})
console.log(mostRepeated)
Even you can do greater than 5 and less than 8
const arr1 = [1,2,3,4,4,4,5,6,7,8,9,10]
const mostRepeated = arr1.filter((element) =>
{
return element > 5 && element < 8
})
console.log(mostRepeated)