Skip to content

Latest commit

 

History

History
99 lines (76 loc) · 3.69 KB

Part-1-Introduction_to_ExpressJS.md

File metadata and controls

99 lines (76 loc) · 3.69 KB

INTRO TO REPL:

REPL is nothing but read–eval–print -loop .

It a simple interactive computer programming environment that takes single user inputs, executes them, and returns the result to the user

🔑 The read function accepts an expression from the user, and parses it into a data .For example 2+3

🔑 The eval function takes this internal data structure and evaluates it. function + is called on the arguments 2 and 3, yielding the result 5.

🔑 The print function takes the result yielded by eval, and prints it out to the user. If it is a complex expression, it may be pretty-printed to make it easier to understand

🔑 The development environment then returns to the read state, creating a loop, which terminates when the program is closed.

Example:
>$ node
> 2 + 3
5
> console.log(‘hello world’)
Hello world
>

OUTPUT::point_down:

INTRO TO EXPRESS.JS:

🍄 Express.js is free 🆓 open source web application frameworks for node.js .
🍄 It is used for designing and building web application 💻 .
🍄 It is used to build both static and dynamic web pages.
🍄 click me to know more about express.js

How to get started with express.js:

Step1 : you need to install express in your node as it is not a core module.

npm i [email protected]

💊 now the version 4.16.4 is installed in node.js
step2 : then ,code your program as

const app = express()
app.get(‘’,(req,res)=>{
    res.send(‘hello world!’)
})
 app.listen(4000,()=>{
 console.log(‘the port 4000 is   running’)
 })

Step3 : Now go to the browser and enter the URL

http://localhost:4000 to see your output.

you have made your 👍 own server.🏆 congrats 🙌

THUS THE FINAL OUTPUT::point_down:

THUS THE FINAL OUTPUT IN command promt ::point_down:

📝 Explanation :

  • The get() function has a path name and a callback fuction with 2 arguments namely req-request and res-response.
  • The send() function is used to display it to the user.Here both HTML or JSON can be used to send

For example : to get HTML

res.send(‘ <h1> hello world </h1> ’)

Output:



For example : to get JSON

res.send({
  Name:’catherine’,
  Location:’chennai’
  })

Output::point_down:





WHAT IS CORE MODULE?

💡 Core module operate at lower level. They are inbuilt with node.js . So, there is no need to install separately like we do to install nodemon and request in NPM
💡 click me to know more about node core modules

Some of the core modules in node.js are,

module use
fs to work with file I/O
http to create Node.js http server
path to deal with file paths
querystring to deal with query string

📌 SYNTAX:

const module = require('module_name');

💊 core modules are complex compared to third-party modules,but anyway you don't need internet to install like third-party module