nodeJs get code example
Example 1: node http request
const https = require('https')
const options = {
hostname: 'whatever.com',
port: 443,
path: '/todos',
method: 'GET'
}
const req = https.request(options, res => {
console.log(`statusCode: ${res.statusCode}`)
res.on('data', d => {
process.stdout.write(d)
})
})
req.on('error', error => {
console.error(error)
})
req.end()
Example 2: node js server
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => res.send('Hello World!'))
app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`))
Example 3: node js
NodeJs is Runtime environment for executing Js code, Outside Of Browser.
it is build upon Chrome v8 engine using c++.
Uses of Node:
-can build back-end services like API which can be used as backend for
diferent platform Apps(Website, MobileApp, Desktop App).
-is Asynchronous by default means Single thread handle all the request
and response, thereby providing more speed, highly scalable, built time half
compare to other tech in market, 33% few line of code, 40% fewer files,
can handle 2times more requests/secs, 35% fast response time.
// Hope you like the short Description.