what do you call those list in node.js site - node.js

I apologize to ask this question,I am still newbie to node.js and trying to learn on it..I am just confuse in http://nodejs.org/api/ are they all api or module? if we use this in our app.js
var http = require('http');
are calling we calling the api or the module ?please enlighten.are module and api are just the same ?
Thank you in advance.

The http api is the set of functions that the http module exposes, IE. through module.exports.

Related

What does http and https module do in Node?

Can someone help me in understanding what does http and https module do in Express?
I was going through the following docs on w3schools
From definition it says
Node.js has a built-in module called HTTP, which allows Node.js to
transfer data over the Hyper Text Transfer Protocol (HTTP).
With following example
var http = require('http');
//create a server object:
http.createServer(function (req, res) {
res.write('Hello World!'); //write a response to the client
res.end(); //end the response
}).listen(8080); //the server object listens on port 8080
This is the example to live demo
First, I am unable to comprehend their example like Where are they making (route) request so that they are receiving response?
Second by the definition, to make a request, using libraries like axios can be alternative?
third, when we make an api request, isn't the data transferred over http/https?
app.post("/", (req, res) => {
In short, Can someone please explain me in more human words the use of http package in express?
Update: I might be confusing this with express, I am used to using express and here we aren't using express
1- They aren't defining any route. That piece of code only creates a server running on port 8080 that when it's created or accessed on the home route (/) returns "Hello World". If you want to define routes you should take a closer look to a module called express that it's used by most of node users due to its simplicity and documentation (https://expressjs.com/en/starter/hello-world.html) In that link you have an example for creating the server and a basic route
2- Yes it can and should be because they are way better than the default from nodeJs. Take a look at axios or superagent, superagent it's better if you want to use formdata to send images or attachments.
3- By default, all servers created using http or express are http servers (don't have a certificate to encrypt the data so they aren't secure). If you want a https server, you can buy certificates or use https://letsencrypt.org/ this module that generates free SSL certificates with 1 month validation.
http module has multiple functions, it can be used to create a server, to make http requests and so on. It's up to you to decide which submodule from the package you want to use. Express is built over the http module making everything easier.
If you need more explanation, tell me and I will try to explain a little better.

Pure NodeJS and GraphQL, no middleware

Is there any example code implementing GraphQL on NodeJS without using any other middleware like Express, Apollo, etc. Just pure NodeJS http server with GraphQL, and any SQL db.
upd: If someone interested, you can check out my implementation on github - pureGraphQLapi
Nothing prevents you from using Node.js and GraphQL only ; you will be writing a little more code though.
Create your HTTP Server with Node.js only
Listen to incoming requests and use POST json body (for example) to pass query and variables to graphql function

Difference between a server with http.createServer and a server using express in node js

What's the difference between creating a server using http module and creating a server using express framework in node js?
Thanks.
Ultimately, express uses node's http api behind the scenes.
express framework
The express framework provides an abstraction layer above the vanilla http module to make handling web traffic and APIs a little easier. There's also tons of middleware available for express (and express-like) frameworks to complete common tasks such as: CORS, XSRF, POST parsing, cookies etc.
http api
The http api is very simple and is used to to setup and manage incoming/outgoing ,HTTP connections. Node does most of the heavy lifting here but it does provide things you'll commonly see throughout most node web framework such as: request/response objects etc.
Express uses the http module under the hood, app.listen() returns an instance of http. You would use https.createServer if you needed to serve your app using HTTPS, as app.listen only uses the http module.
Here's the source for app.listen so you can see the similarities.:
app.listen = function(){
var server = http.createServer(this);
return server.listen.apply(server, arguments);
};

Using node.js libraries on front-end

How can I use the 'request' node.js module on the front-end?
normally I would retrieve it like so:
var request = require('request');
but this is not possible on the front-end since require is not recognized.
What is the best way to solve this?
To use node modules in the browser you can use a library called Browserify . This allows you to work with the common module pattern as well as the you can use this package browser-request to get the features of request module

node.js http module http.createServer how does it work?

so i'm trying to understand how to use node.js module "http" http.createServer()
i wonder if it's possible to see how this function is defined? can i find the content of the definition? i wasn't able to find it
The Node.js source code is available on Github. For the JavaScript side of the API, take a look in the lib directory.
https://github.com/joyent/node/blob/master/lib/http.js#L61
exports.createServer = function(requestListener) {
return new Server(requestListener);
};
You can find the actual HTTP server JavaScript in lib/_http_server.js.

Resources