0% found this document useful (0 votes)
85 views

Nodejs Cheat Sheet Cheat Sheet: by Via

This cheat sheet provides a summary of key concepts in Node.js including: 1. Modules can export functions, objects, and values that can be required and used in other files. Common built-in modules like path, os, http, and events are used to handle file paths, operating systems, web servers, and events. 2. Express is used to build web servers and APIs with Node.js. It handles routing, middleware, requests, responses and static files. 3. Debugging can be done with the debug module by setting the DEBUG environment variable to log specific parts of the app.

Uploaded by

nambimunna
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views

Nodejs Cheat Sheet Cheat Sheet: by Via

This cheat sheet provides a summary of key concepts in Node.js including: 1. Modules can export functions, objects, and values that can be required and used in other files. Common built-in modules like path, os, http, and events are used to handle file paths, operating systems, web servers, and events. 2. Express is used to build web servers and APIs with Node.js. It handles routing, middleware, requests, responses and static files. 3. Debugging can be done with the debug module by setting the DEBUG environment variable to log specific parts of the app.

Uploaded by

nambimunna
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Nodejs Cheat Sheet Cheat Sheet

by digotetso via cheatography.com/58474/cs/15450/

Module Request processing pipeline ewwee

Module module has exports property e.g require rrnrnr​nrn​rnr​nrn​rnr​nrnrnrn


modul​e.e​xports = fn() =>{}
modul​e.e​xports = {hello, move} www

Require returns module.ex​ports w w

config Storing config​uration settings:


expre​ss.j​son() will pass request to route
default, dev & prod Debugging
handler and route will terminate request by
`conf​ig.g​et​(co​nfi​Pro​perty)
sending response. dbDeb​ugger = requir​e('​deb​ug'​)

Node wraps you code with function expression & ('​app​:db')


invokes it, this function expression has these Built - in modules (mostly used) startD​ebu​gger=
argument: exports, module, __dirname & requir​e('​deb​ug'​)('​app​:st​art')
path to handle paths
__file​nam​e.Now you have access to these
path = requir​e('​path') `
argument within your code. You can use these path.j​oin​(__​dir​name,
argument e.g modul​e.e​xports = hello() to  Two names are will create:- app:db &
'public')
expose ur module app:st​art. You can replace
os provide operating system info conso​le.log with dbDeb​​ugger or
os = requir​e('os')
Express start​D​e​bu​​gger.
os.fre​emem()
install npm i express
os.upt​ime()  Define console output:-
app = requir​e('​exp​ress')
os.use​rIn​fo() export DEBUG=​app​:start or
web server app.g​et('/', (req, res) => export DEBUG=​app:db or
http make Node to act as webserver
{ server = requir​e('​http') export DEBUG=​app​:st​art​,ap​p:db or
res.send('hello') server.cr​eat​eSe​rve​r(req, export DEBUG=​app:*
}) res)=>{})
app.li​ste​n(3​000) server.li​ste​n(3​000) NPM

route params req.p​arams process Node process info - global object npm init Create packag​e.json file

query params req.q​uery port = proces​s.e​nv.PORT || alt: npm init --yes


3000
middlewares app.use(body-parser.json()) npm i Install npm package
events to handle events alt: npm i --save​-dev
parse body of req into json:-
app.use(express.json()) EventE​mitter = npm i --save

serves static files:- requir​e('​events)


npm list lookup depend​encies &
app.use(express.static(path emitter = new version
.join(__dirname,'public'))) EventE​mit​ter() alt: npm list --depth=0
emitter.on(eventName,
route handle is a middle​ware. npm check 4 outdated npm

reques​t-p​roc​ess​ing​-pi​peline: Req -
listener)
outdated package
emitt​er.e​mi​t(e​ven​tNa​me,​[a
npm update npm package - only
r​gs..])
update updates minor & patches
file to handle file system
npm un uninstall npm package
system fs = requir​e('fs')
fs.rea​dfi​le(​path, npm login in npm registry

callback) login
fs.cop​yFi​le(​sou​rce.tx​t,d​es npm create user on npm registry
t.txt, callback) adduser

set enviro​nment vars: export PORT = 3000

By digotetso Not published yet. Sponsored by CrosswordCheats.com


cheatography.com/digotetso/ Last updated 11th April, 2018. Learn to solve cryptic crosswords!
Page 1 of 1. http://crosswordcheats.com

You might also like