What is Node.js? And How anyone can make manually Pokemon API without using inbu...

What is Node.js? And How anyone can make manually Pokemon API without using inbu...

What is Node.js?

Node.js is built against modern versions of?V8. By keeping up-to-date with the latest releases of this engine, we ensure new features from the?JavaScript ECMA-262 specification are brought to Node.js developers in a timely manner, as well as continued performance and stability improvements.

All ECMAScript 2015 (ES6) features are split into three groups for?shipping,?staged, and?in progress?features:

  • All?shipping?features, which V8 considers stable, are turned?on by default on Node.js?and do?NOT?require any kind of runtime flag.
  • Staged?features, which are almost-completed features that are not considered stable by the V8 team, require a runtime flag:?--harmony.
  • In progress?features can be activated individually by their respective harmony flag, although this is highly discouraged unless for testing purposes. Note: these flags are exposed by V8 and will potentially change without any deprecation notice.


Why node.js?

Node. js is primarily used?for non-blocking, event-driven servers, due to its single-threaded nature. It's used for traditional websites and back-end API services but was designed with real-time, push-based architectures in mind.

The task of a web server is to open a file on the server and return the content to the client. Node. js has a built-in module called HTTP, which allows Node.


?Purpose of Nodejs

Node. js brings?event-driven programming to web servers, enabling the development of fast web servers in JavaScript. Developers can create scalable servers without using threading, by using a simplified model of event-driven programming that uses callbacks to signal the completion of a task.?This tool is mostly used by programmers who use JavaScript to write Server-Side scripts.

Node. js is an open-source and cross-platform runtime environment for executing JavaScript code outside a browser. You need to remember that?NodeJS is not a framework?and it's not a programming language.


What exactly does Nodejs do?

Node?is used for server-side programming in javascript, and the control given to the programmer is single-threaded unlike Java where concurrency is dealt with multi-threading, in Node most (read all) of the functions are asynchronous and this makes the web app more responsive.

Node heavily uses the concepts of callbacks, closures, and promises, thus in order to use Node one needs to grasp these topics of?functional?javascript.

Node is a wrapper around google’s V8 engine (built using c++ ) and uses an event-driven programming style facilitated by an in-built feature (read process) called the event loop.

“How do I use it?”

Use it for?DIRTy?(Data-Intensive Real-Time) apps, mainly where the Input/Output is extensive without much CPU intensive operations, for example, a video streaming site, you do not need to intensively process the chunks of video bytes before delivering them. Also, its has fine libraries for networking apps, thus you can build high-performance networking apps too.

The basic idea in node:

Normally, we handle IO is :

  • take the path of the file
  • read it from the path
  • Once the file is read, do something with the file

Now, while reading the file the world stops, the server does not do anything else except reading the file in those milliseconds but has the capability to, thus node’s asynchronous functions come into the scene as:

  • take the path of the file
  • once the file is read, do something with the file,?meanwhile,?do something else that the programmer says.

This (along with event-driven programming) enables nodes to make high-performance apps.


What is difference between the Nodejs and Javascript?

Node.js is a software platform that is used to build scalable network (especially server-side) applications. Node.js utilizes JavaScript as its scripting language and achieves high throughput via non-blocking I/O and a single-threaded event loop.

Node.js contains a built-in HTTP server library, making it possible to run a web server without the use of external software, such as Apache or Lighttpd, and allowing more control of how the webserver works.

JavaScript (JS) is a dynamic computer programming language. It is most commonly used as part of web browsers, whose implementations allow client-side scripts to interact with the user, control the browser, communicate asynchronously, and alter the document content that has also become common in server-side programming, game development, and the creation of desktop applications.

No alt text provided for this image


What is express js?

Express?is a fast, assertive, essential and moderate web framework of Node.js. It can be?used?to design single-page, multi-page and hybrid web applications. It allows us to setup middlewares to respond to HTTP Requests. It defines a routing table that is?used?to perform different actions based on the HTTP method and URL.

  1. Express supports MVC Architecture with little bit of work.
  2. You can build RESTful APIs faster.
  3. You can use many templating languages like Jade or EJS which reduce the amount of HTML code you have to write for a page.
  4. Has support for NoSQL databases out of the box. And pretty simple implementing it too. (You can also use relation Databases like MySQL, no worries..)


What is use?

Express lets you build single-page, multi-page, and hybrid web and mobile applications. Another common backend use is to provide an API for a client (whether web or mobile).

It comes with a default template engine, Jade which helps to facilitate the flow of data into a website structure and does support other template engines.

It supports MVC (Model-View-Controller), a very common architecture to design web applications.

It is cross-platform and is not limited to any particular operating system.

It leverages upon Node.JS single-threaded and asynchronous model.

No alt text provided for this image


What is MongoDB Atlas?

Atlas is?MongoDB's database-as-a-service offering that provides users with a managed database service. The service will offer pay-as-you-go pricing and will initially allow users to deploy on Amazon Web Services (AWS), with support for Microsoft Azure and Google Cloud Platform coming later.


Advantages of MongoDB Atlas:

  • Global clusters for world-class applications:?Using MongoDB Atlas, we are free to choose the cloud partner and ecosystem that fit our business strategy.
  • Secure for sensitive data:?It offers built-in security controls for all our data. It enables enterprise-grade features to integrate with our existing security protocols and compliance standard.
  • Designed for developer productivity:?MongoDB Atlas moves faster with general tools to work with our data and a platform of services that makes it easy to build, secure, and extend applications that run on MongoDB.


What is the difference between the MongoDB and MongoDB Altas?

MongoDB:?The database for giant ideas. MongoDB stores data in JSON-like documents that can vary in structure, offering a dynamic, flexible schema. MongoDB was also designed for high availability and scalability, with built-in replication and auto-sharding;?MongoDB Atlas:?Deploy and scale a MongoDB cluster in the cloud with just a few clicks. MongoDB Atlas is a global cloud database service built and run by the team behind MongoDB. Enjoy the flexibility and scalability of a document database, with the ease and automation of a fully managed service on your preferred cloud.

No alt text provided for this image

Step 1: Create a folder then inside that folder create a index.js file and then open a terminal and set a path of the current directory and then write a command as below as given:

>>npm init

No alt text provided for this image


Step 2: Then we have to install the required libraries in our application such as express, mongoose and nodemon, etc.

express:

Installation :This is a Node.js module available through the npm registry.Before installing, download and install Node.js. Node.js 0.10 or higher is required.Installation is done using the npm install command:

>>npm install express

https://www.npmjs.com/package/express

mongoose:

Mongoose is a MongoDB object modeling tool designed to work in an asynchronous environment. Mongoose supports both promises and callbacks.

>>npm install mongoose

https://www.npmjs.com/package/mongoose

nodemon:

nodemon is a tool that helps develop node.js-based applications by automatically restarting the node application when file changes in the directory are detected.

nodemon does not require any additional changes to your code or method of development. nodemon is a replacement wrapper for node. To use nodemon, replace the word node on the command line when executing your script.

>>npm install -g nodemon

https://www.npmjs.com/package/nodemon

Step 3:Then we have to create all the request such as get,post,put,delete and many more such as in this we are using the pokemon data in that we are passing the different properties

name,type and imageUrl as a schema and then we create a model object as pokemonModel and then we do get selected id of the pokemon,get the type of particular pokemon and so on operation.

As we can do many statistical calucaulation in easy way by using MongoDB such as in this we are using count the number of pokemons in our dataset or in data and many more we can create.

No alt text provided for this image


Step 4: Then we create a server in which we are passing a 3001 port number initial and then we can also change as per user requirement or we can given any port number its not compailsary that to use only 3000 only.

And then we write a command as npm start in console automatically we received an output as server is running successfully and mongodb connected successfully.

No alt text provided for this image

Step 5: As we are using a postman,as we writing a post request then we passing this URL in the and as many as we can make our own data manually without using any inbuilt API of pokemon.


No alt text provided for this image


Step 6:then we passing the query in the postman as get then we getting all the data which is present in our database.


No alt text provided for this image


Step 7:Then if we want to get a particular pokemon information such us Pikachu then we have to passing it own id.

id means MongoDB create its own or unique id so by using this we can get a particular pokemon information.

No alt text provided for this image


Step 8:if we want to delete a particular pokemon information from our database then we using this delete ,and then passing the query.

No alt text provided for this image



Step 9:what if when the user wants a query such that when it writes in the query as a type of that particular pokemon it shows that pokemon type and its necessary data, then we pass this query.

>>https://127.0.0.1:3000/pokemon/type/Flying

No alt text provided for this image

Step 10:you can see that we have earlier in our database having information of the Arbok pokemon and when we passing the delete query then its deleted from our database.

>>https://127.0.0.1:3001/pokemons


No alt text provided for this image


Step 11:If we want to see in MongoDB server whole our operations and so on things .firstly we create a database such as pokeapi and then we create a collection name such as pokemon.

and then we also put manually our data, just use an additional data and then in then in the form of JSON we can pass the parameters. we can view our data in three forms such as besides the add data there is a button as a table, JSON, and normal like this form which is showing in below.


No alt text provided for this image


Step 12: This is the table representation of the given dataset it's looking pretty must good as image URLs, type of the pokemon and id_objects fileds.

No alt text provided for this image


Step13:If the same data we want to see, so that for we are using MongoDB Altas.

MongoDB Atlas is a?fully managed cloud database?developed by the same people that build MongoDB. Atlas handles all the complexity of deploying, managing, and healing your deployments on the cloud service provider of your choice (AWS, Azure, and GCP).

In the all the data that we create are showing in the output.

No alt text provided for this image


Step 14: we can number of times users trigger or form action by using the MongoDB Altas as we are connected in our application.

as we know that...

MongoDB Atlas is a next-generation database built to support the needs of dynamic and evolving applications. Fully supporting AWS, Azure, and Google Cloud Platform, ... It's easy to get started with MongoDB Atlas, and?it's free

No alt text provided for this image


Step 15: At last, we can also check the rest of API operation or testing by using an in-built extension as Thunder Client .

Thunder Client is?a Rest API Client Extension for Visual Studio Code, with a simple and clean design. The extension makes API testing very easy with Scriptless GUI-based testing. Thunder Client is a tool in the API Tools category of a tech stack.

ThunderClient supports the concept of Environment and Environment Variables to store and re-use values within multiple requests. Finally, ThunderClinet offers a UI that you can use to set the expected response code, response time, and response body for testing APIs.PIs.

No alt text provided for this image

Material Required in Our Project :

1.Nodejs Download

https://nodejs.org/en/download/

2. VS CODE download

https://code.visualstudio.com/download

3.MongoDB Altas Download

https://www.mongodb.com/cloud/atlas

4.MongoDB Compass Download

https://www.mongodb.com/try/download/compass

5. Postman Download:

https://www.postman.com/


Hope you all like it...

Thank you so much...





Saikiran Sondarkar

Founder & CEO- LetsUpgrade.in (India's largest Tech Learning Community)

2 年

Congratulations ??

Suraj Pawar (スラジパワール)

Technical Services Trainee at Fujitsu | Full Stack Developer | Java | JDBC | SpringBoot | Bootstrap | Angular14 | Angular Material | MySQL | Github | DevOps | Artistry Unleashed

3 年

Thank you so much...????

回复
Sonu Kumar

Search Engine optimization | Digital Marketing | SEO |SEM | Keyword Research | Link-Building | Off-page Optimization | SEO Strategies | SWOT Analyst

3 年

Inspiring

Devanshi Mishra

Associate Software Engineer

3 年

Great work buddy

Er. Harsh Raj

System Engineer @TATA Consultancy Services

3 年

Inspiring

要查看或添加评论,请登录

社区洞察

其他会员也浏览了