This Node.js cheat sheet provides essential commands and modules for using Node.js and Express, including how to handle requests, manage configurations, and utilize built-in modules. It also covers NPM commands for package management, such as installing, updating, and uninstalling packages. The document serves as a quick reference for developers working with Node.js and Express applications.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
9 views2 pages
Digotetso - Nodejs Cheat Sheet
This Node.js cheat sheet provides essential commands and modules for using Node.js and Express, including how to handle requests, manage configurations, and utilize built-in modules. It also covers NPM commands for package management, such as installing, updating, and uninstalling packages. The document serves as a quick reference for developers working with Node.js and Express applications.
app.use(express.static(path emitter.emit(eventName,[ar config Storing configuration settings: .join(__dirname,'public'))) file to handle file system default, dev & prod route handle is a middleware. `config.get(confiPropert system fs = require('fs') y) request-processing-pipeline: Req - fs.readfile(path, callback) fs.copyFile(source.txt,des Node wraps you code with function Request processing pipeline lback) expression & invokes it, this function expression has these argument: exports, set environment vars: export PORT = 3 module, __dirname & __filename.N 000 ow you have access to these argument within your code. You can use these ewwee argument e.g module.exports = hell require rrnrnrnrnrnrnrnrnrnrnrnrn express.json() will pass request to o() to expose ur module route handler and route will terminate www request by sending response. Express w w install npm i express Built - in modules (mostly used) app = require('express') Debugging path to handle paths web server app.get('/', (req, res) => path = require('path') dbDebugger = require('debug')('app { path.join(__dirname, 'public') res.send('hello') startDebugger= require('debug')(' os provide operating system info }) :start') os = require('os') app.listen(3000) os.freemem() ` route params req.params os.uptime() Two names are will create:- app:db & query params req.query os.userInfo() app:start. You can replace console.l http make Node to act as webserver og with dbDebugger or startDebu server = require('http') gger. server.createServer(req, res)= >{}) Define console output:- server.listen(3000) export DEBUG=app:start or
process Node process info - global object export DEBUG=app:db or
port = process.env.PORT || export 3000 DEBUG=app:start,app:db or
export DEBUG=app:*
By digotetso Not published yet. Sponsored by Readable.com
cheatography.com/digotetso/ Last updated 11th April, 2018. Measure your website readability! Page 1 of 2. https://readable.com Nodejs Cheat Sheet Cheat Sheet by digotetso via cheatography.com/58474/cs/15450/
NPM
npm init Create package.json file
alt: npm init --yes
npm i Install npm package
alt: npm i --save-de v npm i --save
npm list lookup dependencies &
version alt: npm list --dept h=0
npm outdated check 4 outdated npm
package npm update update npm package - only updates minor & patches npm un uninstall npm package
npm login login in npm registry
npm adduser create user on npm
registry
By digotetso Not published yet. Sponsored by Readable.com
cheatography.com/digotetso/ Last updated 11th April, 2018. Measure your website readability! Page 2 of 2. https://readable.com
Python Advanced Programming: The Guide to Learn Python Programming. Reference with Exercises and Samples About Dynamical Programming, Multithreading, Multiprocessing, Debugging, Testing and More