Sources : https://nodejs.org/en/, http://nodeguide.com/beginner.html
Steps to create new app and run on node.
Took a new Centos machine. downloaded Jetbrain's WebStorm.tar.gz(trial 30 days) & node6.9.x.tar.xz .
xz -d node..tar.xz
tar xf node.tar
tar xzf WebStorm.tar.gz
WS/bin/webstorm.sh
create new node-express app.
configure node interpreter (select node.sh in node/bin/)
choose lower version of express generator (3.x worked for me).
run project
browse http://localhost:3000
Working in node shell:
node #This invokes node shell.
var http=require('http');
var server = http.createServer(function(req,res){
res.writeHead(200);
res.end('hello world');
});
server.listen(8000);
.exit #Terminates the node shell
.help #shows list of node shell commands
.save FILE_NAME.js # Stores your executed commands into FILE_NAME.js file.
.load FILE_NAME.js # loads FILE_NAME.js file previously saved by .save
.break, .clear or Ctrl + c # lets you quit from incomplete multi line statements such as function.
Starts server configured in server.js with gc log collector and gc logs are displayed on console.
node --trace_gc server.js
Inbuilt Modules : fs, path, http, events
Global Objects: global.process,
global.process
global.process.version
global.process.versions
process.cwd()
var logger = function(d){
process.stdout.write(d + "\n");
}
logger("Hello world");
Debugging with nodejs in visualstudiocode, picks main file specified in package.json.
#List all globally installed npm modules..
npm list -g --depth=0;
#How to debug test modules?
1.Add nodejs configuration in visual studio code by click on "add configuration" in debug panel, this will add 'launch.json' file in .vscode folder within current project.
2.Edit launch.json
3.Hit CTR+SPACE and select "{} NodeJS: Mocha Tests". thats all... remove any extra configuration
4.Hit F5 to begin debug..
#How to require a module using node from the command line. Source:stackoverflow
1. node --require <PKG_NAME> //This will require <PKG_NAME> to be installed locally. I prefer getting into node_modules dir of any project where PKG_NAME is available.
2. node
3. var pkg_var = require('PKG_NAME'); //within node shell works fine..
Prob#1: After d3 install getting following errors.
error TS2345: Argument of type 'string' is not assignable to parameter of type 'Expected<Promise<string>>'.
, node_modules/protractor/built/browser.d.ts(368,26): error TS2503: Cannot find namespace 'webdriver'.
& error TS5055: Cannot write file
Prob#2: running test file using node results in, "ReferenceError: describe is not defined".
Soln:- installed mocha either globally or for current project and run test file using same.
Prob#3: ✖ Verifying Cypress can run /home/rohit/mck-cri-master/node_modules/cypress/dist/Cypress
→ Cypress Version: 1.1.2
Cypress failed to start.
This is usually caused by a missing library or dependency.
The error below should indicate which dependency is missing.
https://on.cypress.io/required-dependencies
If you using Docker, we provide containers with all required dependencies installed.
----------
/home/rohit/mck-cri-master/node_modules/cypress/dist/Cypress/Cypress: error while loading shared libraries: libXtst.so.6: cannot open shared object file: No such file or directory
----------
Platform: linux (Ubuntu Linux - 14.04)
Soln: from given url in error
sudo apt-get install xvfb libgtk2.0-0 libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2