What is Nodejs?
An open source server environment
Runs on various platforms
Uses JS on the server
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’)
Node files MUST be initiated in the CLI
Initiate the node file?
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
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
Delete Files with system module:
- package manager for Nodejs packages or modules if you like
Every action on a computer is an event. This is perfect for event driven applications.
Makes it easy to send emails from your computer.