Sponsored Content
Top Forums Web Development Node.js and mysql - ER_ACCESS_DENIED_ERROR Post 303021093 by Neo on Saturday 4th of August 2018 01:06:49 AM
Old 08-04-2018
Here is the final node.js test script (index.js):

Code:
var express = require("express");
var fs = require("fs");
var https = require("https");
var app = express();
require("dotenv").config();
const privateKey = fs.readFileSync(process.env.SSL_PRIVKEY, "utf8");
const certificate = fs.readFileSync(process.env.SSL_CERT, "utf8");
const ca = fs.readFileSync(process.env.SSL_CHAIN, "utf8");
const user = process.env.DATABASE_USER;
const password = process.env.DATABASE_PASSWORD;
const database = process.env.DATABASE_NAME;
const port = process.env.DATABASE_SOCKET;

app.get("/", function(req, res) {
  res.send("hello world");
});

app.get("/test", function(req, res) {
  var mysql = require("mysql");
  var con = mysql.createConnection({
    host: "127.0.0.1",
    user: user,
    password: password,
    database: database,
    port: port
  });

  con.connect(function(error) {
    if (error) {
      console.log(error);
      return;
    } else {
      con.query("SELECT username FROM user WHERE userid < 10", function(
        err,
        rows,
        fields
      ) {
        if (err) {
          console.log(err);
          return;
        } else {
          rows.forEach(function(result) {
            console.log(result.username);
          });
        }
      });
      con.end();
      res.send("MySQL Query Complete");
    }
  });
});

https
  .createServer(
    {
      key: privateKey,
      cert: certificate,
      ca: ca
    },
    app
  )
  .listen(8080, function(error) {
    if (error) {
      console.log(error);
    } else console.log("Example app listening on port 8080");
  });

 

6 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

MySQL problem >> missing mysql.sock

MySQL on my server is down.... I figured out that the mysqld process isn't running. When I try to run it, it says it can't find mysql.sock Any suggestions? Here's what I can't do: can't be root don't have physical access (do stuff via SSH) reinstall MySQL (need to keep the current MySQL... (8 Replies)
Discussion started by: _hp_
8 Replies

2. Solaris

SVM metaset on 2 node Solaris cluster storage replicated to non-clustered Solaris node

Hi, Is it possible to have a Solaris cluster of 2 nodes at SITE-A using SVM and creating metaset using say 2 LUNs (on SAN). Then replicating these 2 LUNs to remote site SITE-B via storage based replication and then using these LUNs by importing them as a metaset on a server at SITE-B which is... (0 Replies)
Discussion started by: dn2011
0 Replies

3. UNIX and Linux Applications

MySQL Daemon failed to start - no mysql.sock file

After doing a yum install mysql mysql-server on Fedora 14 I wasn't able to fully install the packages correctly. It installed MySQL 5.1. I was getting the following error when running the: mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)... (3 Replies)
Discussion started by: jastanle84
3 Replies

4. Homework & Coursework Questions

Accessing one UNIX node from another node of the same server

Hi Experts, I am in need of running a script from one node say node 1 via node 2. My scheduling tool dont have access to node2 , so i need to invoke the list file from node1 but the script needs to run from node2. because the server to which i am hitting, is having access only for the node... (5 Replies)
Discussion started by: arun1377
5 Replies

5. HP-UX

Mount FIle systems from node-1 onto node-2

Hi, We have HP UX service guard cluster on OS 11.23. Recently 40+ LUNs presented to both nodes by SAN team but I was asked to mount them on only one node. I created required VGs/LVs, created VxFS and mounted all of them and they are working fine. Now client requested those FS on 2nd node as... (4 Replies)
Discussion started by: prvnrk
4 Replies

6. Programming

Node-RED: Writing MQTT Messages to MySQL DB with UNIX timestamp

First, I want to thank Neo (LOL) for this post from 2018, Node.js and mysql - ER_ACCESS_DENIED_ERROR I could not get the Node-RED mysql module to work and searched Google until all my links were purple! I kept getting ER_ACCESS_DENIED_ERROR with the right credentials. Nothing on the web was... (0 Replies)
Discussion started by: Neo
0 Replies
Net::Server::PSGI(3pm)					User Contributed Perl Documentation				    Net::Server::PSGI(3pm)

NAME
Net::Server::PSGI - basic Net::Server based PSGI HTTP server class TEST ONE LINER
perl -e 'use base qw(Net::Server::PSGI); main->run(port => 8080, ipv => "*")' # runs a default echo server SYNOPSIS
use base qw(Net::Server::PSGI); __PACKAGE__->run(app => &my_echo_handler); # will bind IPv4 port 80 sub my_echo_handler { my $env = shift; my $txt = qq{<form method="post" action="/bam"><input type="text" name="foo"><input type="submit"></form> }; require Data::Dumper; local $Data::Dumper::Sortkeys = 1; require CGI::PSGI; my $form = {}; my $q = CGI::PSGI->new($env); $form->{$_} = $q->param($_) for $q->param; $txt .= "<pre>".Data::Dumper->Dump([$env, $form], ['env', 'form'])."</pre>"; return [200, ['Content-type', 'text/html'], [$txt]]; } DESCRIPTION
If you want a more fully featured PSGI experience, it would be wise to look at the Plack and Starman set of modules. Net::Server::PSGI is intended as an easy gateway into PSGI. But to get the most out of all that PSGI has to offer, you should review the Plack and Plack::Middleware. If you only need something a little more rudimentary, then Net::Server::PSGI may be good for you. Net::Server::PSGI takes Net::Server::HTTP one level farther. It begins with base type MultiType defaulting to Net::Server::Fork. It is easy to change it to any of the other Net::Server flavors by passing server_type => $other_flavor in the server configurtation. The port has also been defaulted to port 80 - but could easily be changed to another through the server configuration. You can also very easily add ssl by including, proto=>"ssl" and provide a SSL_cert_file and SSL_key_file. For example, here is a basic server that will bind to all interfaces, will speak both HTTP on port 8080 as well as HTTPS on 8443, and will speak both IPv4, as well as IPv6 if it is available. use base qw(Net::Server::PSGI); __PACKAGE__->run( port => [8080, "8443/ssl"], ipv => '*', # IPv6 if available SSL_key_file => '/my/key', SSL_cert_file => '/my/cert', ); METHODS
"process_request" This method has been overridden in Net::Server::PSGI - you should not use it while using Net::Server::PSGI. This overridden method parses the environment and sets up request alarms and handles dying failures. It calls process_psgi_request once the request is ready and headers have been parsed. "process_psgi_request" Used when psgi_enabled is true. During this method, find_psgi_handler will be called to return the appropriate psgi response handler. Once finished, print_psgi_headers and print_psgi_body are used to print out the response. See PSGI. Typically this method should not be overridden. Instead, an appropriate method for finding the app should be given to find_psgi_handler or app. "find_psgi_handler" Used to lookup the appropriate PSGI handler. A reference to the already parsed $env hashref is passed. PATH_INFO will be initialized to the full path portion of the URI. SCRIPT_NAME will be initialized to the empty string. This handler should set the appropriate values for SCRIPT_NAME and PATH_INFO depending upon the path matched. A code reference for the handler should be returned. The default find_psgi_handler will call the "app" method. If that fails a reference to the psgi_echo_handler is returned as the default application. sub find_psgi_handler { my ($self, $env) = @_; if ($env->{'PATH_INFO'} && $env->{'PATH_INFO'} =~ s{^ (/foo) (?= $ | /) }{}x) { $env->{'SCRIPT_NAME'} = $1; return &foo_app; } return $self->SUPER::find_psgi_handler($env); } "app" Return a reference to the application being served. This should be a valid PSGI application. See PSGI. By default it will look at the value of the "app" configuration option. The "app" method may also be used to set the "app" configuration option. package MyApp; use base qw(Net::Server::PSGI); sub default_server_type { 'Prefork' } sub my_app { my $env = shift; return [200, ['Content-type', 'text/html'], ["Hello world"]]; } MyApp->run(app => &my_app); # OR sub app { &my_app } MyApp->run; # OR my $server = MyApp->new; $server->app(&my_app); $server->run; OPTIONS
In addition to the command line arguments of the Net::Server::HTTP base classes you can also set the following options. app Should return a coderef of the PSGI application. Is returned by the app method. AUTHOR
Paul T. Seamons paul@seamons.com SEE ALSO
Please see also Plack, Starman, Net::Server::Fork, Net::Server::INET, Net::Server::PreFork, Net::Server::PreForkSimple, Net::Server::MultiType, Net::Server::Single Net::Server::SIG Net::Server::Daemonize Net::Server::Proto Net::Server::HTTP perl v5.14.2 2012-06-11 Net::Server::PSGI(3pm)
All times are GMT -4. The time now is 02:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy