How to start nodejs? Reviewed by Momizat on . install nodejs and npmuse command "yum install nodejs npm" After installation check ituse command for npm "npm --version"use command for nodejs "node --version" install nodejs and npmuse command "yum install nodejs npm" After installation check ituse command for npm "npm --version"use command for nodejs "node --version" Rating: 0

How to start nodejs?

  • install nodejs and npm

    use command “yum install nodejs npm”

  • After installation check it

    use command for npm “npm –version”

    use command for nodejs “node –version”

  • Get start

    • then create folder “mkdir mynode”
    • then use “cd mynode”
    • then use “npm init” to create package.json
    • then install module which are your need.Like “npm install express”,”npm install mysql”
    • then use “node” for nodejs run command
      #############
      [manish@localhost mnode]$ node
      > console.log('Manish');
      Manish
      #########################
      
    • to exit from node use ctrl+c key
    • to run with file create “index.js”
    • write code in index.js file
      index.js
      var mysql = require('mysql');//use mysql module here
      
      var con = mysql.createConnection({
        host: "localhost",
        user: "root",
        password: "xxxxxx",
        database: "zf3"
      });
      
      con.connect(function(err) {
        if (err) throw err;
        con.query("SELECT * FROM album", function (err, result, fields) {
          if (err) throw err;
          console.log(result);
        });
      });
      
    • use to run “node index.js” then show all record of table
    • To run in url write this code in test.js file
      var http = require('http');
      http.createServer(function (req, res) {
          res.writeHead(200, {'Content-Type': 'text/html'});
          res.write(req.url);
          res.end();
      }).listen(8080);
      
    • then run it “node test.js” here server is start then use “http://localhost:8080/manish”

      it is totally depend on excution of node if run then this localhost is working fine you stop node command then it will not be working

Leave a Comment

© 2014 Powered By