Node Js by Aryadrj
Node Js by Aryadrj
1. How to check whether Node Js is installed in your system or not ?
- Start your command prompt and type "node -v".
2. How to run Node Js program?
- node yourfilename.js
3. First Program in Node JS?
var http = require("http");
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Welcome to Aryadrj Website.\n');
}).listen(8082);
console.log('Our Server running at http://127.0.0.1:8082/');
3. Note
- Node.js allows you to run JavaScript on the server and Node.js has a a lots of set of built-in modules.
4. What require() function will do?
- require() function is used to add module.
- Example:
- require('http');
- Remember : We can create our own module.
5. How to take input in Node js?
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
readline.question('What is your name? ?', str => {
console.log(`Hey ${str}!`);
readline.close();
});
6. Routing in Node js?
const http = require('http');
function index (request, response) {
response.writeHead(200);
response.end('Hello, India!');
}
http.createServer(function (request, response) {
if (request.url === '/aryadrj') {
return index(request, response);
}
response.writeHead(404);
response.end(http.STATUS_CODES[404]);
}).listen(8081);
- Enter URL : localhost:8081/aryadrj in your browser
7. How to exit the server?
- Use CTRL+C in your command prompt.
8. Can we use node shell prompt?
- Yes we can, types node in command prompt.
9. How to exit from shell of node js?
- press "ctrl+c" twice.
10. Is node JS frontend or backend?
- It is used to launch both the frontend and backend of web apps using JavaScript
Comments
Post a Comment