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.
Top comments (0)