Javascript | Javascript kata |Node JS | Data Types | Variables | Control Flow | Scope and Environment | Objects | Functions | Events | Prototypal Inheritance | Three.js | 3DE Code Editor |
Node Js
ln -s /usr/bin/nodejs /usr/bin/node
Install NVM Manjaro Linux
Use Node Version Manager, NVM.sudo pacman -S nvm nvm install --lts npm install "package name" nvm uninstall --lts
Getting Started npm
npm install <package-name>flags:
--save-dev saves to devDependencies --no-save saves to Dependencies --save-optional saves to optionalDependencies --no-optional -S --save -D --save-ve -O --save-optional
npm update
npm update <package-name>
npm install <package-name>@<version>
Running Tasks
npm run <task-name> { "scripts":{ "start-dev": "node lib/server-development" "start": "node lib/server-production" } } npm run start-devHow do I find which version of V8 ships with a particular version of Node.js?
node -p process.versions.v8
http Server Sample
const http = require('http'); const hostname = '127.0.0.1'; const port = 3000; const server = http.createServer((req, res) => { res.status = 200; res.setHeader('Content-Type','text/plain'); res.end('Hello World'); }); server.listen(port, hostname, () => { console.log(`Server running at http://${hostname}:${port}/`); });
Development, Production Environment
{ "scripts":{ "start-dev": "node lib/server-development" "start": "node lib/server-production" } }
in bash: export NODE_ENV=production NODE_ENV=production node app.js if (process.env.NODE_ENV === 'development'){ app.use(express.errorHandler({ dumpExecptions: true, showStack: true })); } if (process.env.NODE_ENV === 'production'){ app.use(express.errorHandler()); } if (['production', 'staging'].includes(process.env.NODE_ENV)){ // }
11apr23 | admin |