0% found this document useful (0 votes)
14 views5 pages

NodeJS Easy Notes

Node.js is a JavaScript runtime that allows server-side scripting and features asynchronous, event-driven architecture. It includes modules for HTTP servers, file systems, and supports RESTful APIs, along with a package manager (npm) for managing dependencies. The document also covers Express.js for web applications, MongoDB integration, authentication, and deployment strategies.

Uploaded by

siddhu4293
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views5 pages

NodeJS Easy Notes

Node.js is a JavaScript runtime that allows server-side scripting and features asynchronous, event-driven architecture. It includes modules for HTTP servers, file systems, and supports RESTful APIs, along with a package manager (npm) for managing dependencies. The document also covers Express.js for web applications, MongoDB integration, authentication, and deployment strategies.

Uploaded by

siddhu4293
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Node.

js Easy Notes

1. Introduction to [Link]

[Link] is a JavaScript runtime built on Chrome's V8 engine. It enables server-side scripting using

JavaScript.

2. Features of [Link]

- Asynchronous and Event Driven

- Very Fast

- Single Programming Language

- Community Driven Packages via npm

3. Installing [Link]

Download and install from [Link]

Check version:

$ node -v

$ npm -v

4. First [Link] Program

Create a file named [Link]:

[Link]('Hello, [Link]');

Run with:

$ node [Link]

5. Modules in [Link]

[Link] has built-in modules like fs, http, etc.

Example:

const fs = require('fs');

[Link]('[Link]', 'Hello');
[Link] Easy Notes

6. Creating HTTP Server

const http = require('http');

const server = [Link]((req, res) => {

[Link]('Hello World');

});

[Link](3000);

7. File System Module

const fs = require('fs');

[Link]('[Link]', 'utf8', (err, data) => {

if (!err) [Link](data);

});

8. Events and EventEmitter

const EventEmitter = require('events');

const emitter = new EventEmitter();

[Link]('message', () => [Link]('Message received'));

[Link]('message');

9. npm - Node Package Manager

$ npm init

$ npm install express

[Link] manages dependencies.

10. [Link] Framework

const express = require('express');

const app = express();

[Link]('/', (req, res) => [Link]('Home'));


[Link] Easy Notes

[Link](3000);

11. Middleware in Express

[Link]((req, res, next) => {

[Link]('Middleware');

next();

});

12. Routing in Express

[Link]('/about', (req, res) => [Link]('About Page'));

13. Handling Forms & JSON

[Link]([Link]({ extended: true }));

[Link]([Link]());

14. RESTful APIs

Use GET, POST, PUT, DELETE methods to build APIs.

Example:

[Link]('/user', (req, res) => { ... });

15. Connecting to MongoDB

Use mongoose package:

const mongoose = require('mongoose');

[Link]('mongodb://localhost/mydb');

16. Creating a Model

const User = [Link]('User', { name: String });


[Link] Easy Notes

17. Inserting Data

const user = new User({ name: 'John' });

[Link]();

18. Reading Data

[Link]({}, (err, users) => [Link](users));

19. Updating Data

[Link]({ name: 'John' }, { $set: { name: 'Doe' } });

20. Deleting Data

[Link]({ name: 'Doe' });

21. Error Handling

[Link]((err, req, res, next) => {

[Link](500).send('Something broke!');

});

22. Environment Variables

Use dotenv package:

require('dotenv').config();

[Link]([Link]);

23. Deployment

Deploy on platforms like Heroku, Render, or Vercel using git and build tools.

24. Project Structure

Organize using routes/, models/, controllers/, and [Link].


[Link] Easy Notes

25. Authentication Basics

Use packages like bcrypt for password hashing and jsonwebtoken for token-based auth.

26. Using Postman

Postman is used to test APIs by sending HTTP requests to endpoints.

27. Using Middleware for Auth

function auth(req, res, next) {

if ([Link]) next(); else [Link](403);

28. CORS in Express

const cors = require('cors');

[Link](cors());

29. Async/Await

async function getUser() {

let user = await [Link]();

[Link](user);

30. Conclusion

[Link] is fast, scalable, and ideal for building REST APIs and real-time apps.

You might also like