DEV Community

Cover image for Nodejs Studies
Orion
Orion

Posted on

1

Nodejs Studies

Download Nodejs:
https://nodejs.org

What is Nodejs?
An open source server environment
Free
Runs on various platforms
Uses JS on the server

Why Nodejs?
Uses async programming

What can you do with nodejs?
Generate dynamic page content
Create, open, read, write, delete and close files on the server.
Collect from data
add , delete, modify data in your database.

What is a nodejs file?
Contains tasks that will be executed on certain events
A typical event is someone trying to access a port on the server
Files must be initiated on the server before having any effect
Must have a .js extension (‘.js’)

CLI:
Node files MUST be initiated in the CLI

Initiate the node file?
node
Access then on the localhost

What is a module?
A set of functions you want to include in your applications.
Built-in Modules 0 you can use without installing

Include Modules
Use the require() function with the name of the module:

Create and Include Modules:
You can create and include your own modules as well as them in your applications.

Built-in HTTP Module:
Allows Node to transfer data over the HyperText Transfer Protocol (HTTP).

Nodejs as a Web Server
The HTTP module can create an HTTP server that listens to server ports and gives a response back to the client

Add an HTTP Header:
HTTP server is supposed to be displayed as HTML, you should include a HTTP header with the correct content type

Built-in URL module
splits up a web address into readable parts.

Node as a File Server:
This module allows you to work with the file system on your computer. Uses the “require()” method.

Reading Nodejs Files

  • fs.readFile() method is used to read files on the computer

Create Files

  • fs.appendFile()
  • fs.open()
  • fs.writeFile()

Update Files:

  • fs.appendFile()
  • fs.writeFile()

Delete Files with system module:

  • fs.unlink()

Rename Files
fs.rename()

Nodejs NPM

  • package manager for Nodejs packages or modules if you like

Nodejs Events
Every action on a computer is an event. This is perfect for event driven applications.

Nodemailer Module
Makes it easy to send emails from your computer.

SurveyJS custom survey software

Build Your Own Forms without Manual Coding

SurveyJS UI libraries let you build a JSON-based form management system that integrates with any backend, giving you full control over your data with no user limits. Includes support for custom question types, skip logic, an integrated CSS editor, PDF export, real-time analytics, and more.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay