Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/namkatcedrickjumtock/node-blogger-app

Mern stack blogging web app with simple Crud functionalities
https://github.com/namkatcedrickjumtock/node-blogger-app

ejs-templates express mongodb mongoo nodejs

Last synced: 1 day ago
JSON representation

Mern stack blogging web app with simple Crud functionalities

Awesome Lists containing this project

README

        

## Node JS Notes

#### Global objects in Node

Global Objects in Node is similar to the Global Window Object in the browser.

Broswer: Window -> returns all accessible methos within the object
node: Gloable return all the accessible methods

#### NB:-

Accessing Files

__dirname -> returns the absolute path of file
__filname - > return the absolute path of file with the ile name

#### Modules import and Export Modularity in node js
exporting file name: resources.js
importing files name: app.js

const values = [23,"hey","johne", true]
const values2 = [...values]

// export multiple rescources
modules.export = {values, values2}

const {values, values2} = require("./resources.js") //import destructuring

#### FileSstems Operations in Node
const fs = require('fs')

// reading file
fs.readFile(, (err, data) => { //async fxn
if(err){log(err)}
log(data.toString)
})

// writing files
fs.writeFile(, data, (err) =>{
...code
})

// making Directories
check if dir exists

if(!fs.existsSync()){
fs.mkdir(, (err)=>{ // rmdir removes a directories
... log message
})
}

// deletings files

if(fs.existsSync()){
fs.unlink("path to file", (err)=>{
.. log err if found
})
}
### Streams and Buffers for large files

- ## Streams
- ## Buffers

- [ ] Read Streams
- [ ] Write Streams

Using Streams data can be used while it's loading

const readStream = fs.createReadStream(, {encoding: "utf8})

const writeStream = fs.createWriteStream(, {encoding: "utf8})

readStream.on('data', (chunck)=>{
writeStream.write('\n Chunk \n')
})

// piping
reading data from read stream into the write stream
// much easier
readStream.pipe(writeStream)
setHeader - > redirect to a particular screen.

#### Express MiddleWares
it's simply functions or peac of code that run between the request coming in and the response going out of the server.
##### Uses of Middleware can be used in:
- As a logger for looing details of every request
- Authentication check middleware for protected Routes
- Middleware to parse json data from request
- Return 404 pages
```
for example:
the use((res, req)) // we use for displaying th e 404 pages.
// the use fxn runs for every request sent the Browser