Saturday, March 28, 2020

ReferenceError: bodyParser is not defined



Error Blog 

Hi Guys ,
This blog is about the error  ReferenceError: bodyParser is not defined

Problem Statement

unable to start node js server .


Error Details 

error Log

ERROR DETAILS 

ReferenceError: bodyParser is not defined
    at Object.<anonymous> (F:\abc\study\gitRepo\new\learn\nodejs\expressjs\server.js:13:9)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)



Error Code 

You may have body parser in your code .


var express = require('express');
var bodyParser = require('body-parser');
var app = express();


var users = require('./service/users.js');

app.use(express.static('public'));

//app.get('/', function (req, res) {
  // res.send('Hello World');
//})

app.use('/users'users);
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

var server = app.listen(8082function () {
   var host = server.address().address;
   var port = server.address().port;

   console.log("Example app listening at http://%s:%s"hostport)
})
  

Solution

body parser should be installed 

Code Changes 

execute the following command 

  
        

> npm install body-parser

         

OUTPUT
npm WARN saveError ENOENT: no such file or directory, open 'F:\abc\study\gitRepo\new\learn\nodejs\expressjs\package.json'  
npm WARN enoent ENOENT: no such file or directory, open 'F:\abc\study\gitRepo\new\learn\nodejs\expressjs\package.json'     
npm WARN expressjs No description
npm WARN expressjs No repository field.
npm WARN expressjs No README data
npm WARN expressjs No license field.

+ body-parser@1.19.0
updated 1 package and audited 316 packages in 3.986s
found 0 vulnerabilities



Thanks for reading . Let me know your thoughts in the comments below    .

Friday, March 27, 2020

ERROR 1046 (3D000): No database selected



Error Blog 

Hi Guys ,
This blog is about the error   ERROR 1046 (3D000): No database selected

Problem Statement

unable to query in mysql usiing command line client 


Error Details 

error Log

ERROR DETAILS 


mysql> select * from all_tables
    -> ;
ERROR 1046 (3D000): No database selected
mysql>




Error Code 

Please check if the database is selected 

  
   
  

Solution

select a database

Code Changes 

execute the following command 

  
        

mysql> use mydb
Database changed
mysql>

         
OUTPUT



Thanks for reading . Let me know your thoughts in the comments below    .

Wednesday, March 25, 2020

java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut



Error Blog 

Hi Guys ,
This blog is about the error    java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut

Problem Statement

unable to start a spring boot application on using annotation based aspect .


Error Details 

error Log

ERROR DETAILS 
Caused by: java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut 
at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:319) ~[aspectjweaver-1.9.5.jar:na]
at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:227) ~[spring-aop-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.aop.aspectj.AspectJExpressionPointcut.obtainPointcutExpression(AspectJExpressionPointcut.java:198) ~[spring-aop-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.aop.aspectj.AspectJExpressionPointcut.getClassFilter(AspectJExpressionPointcut.java:177) ~[spring-aop-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:226) ~[spring-aop-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:289) ~[spring-aop-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:321) ~[spring-aop-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:126) ~[spring-aop-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:95) ~[spring-aop-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:76) ~[spring-aop-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:347) ~[spring-aop-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:299) ~[spring-aop-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:431) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
... 25 common frames omitted



Error Code 

Please check the aspect class

  
   
package com.example.aop;
import org.aspectj.lang.JoinPoint;import org.aspectj.lang.annotation.Aspect;import org.aspectj.lang.annotation.Before;import org.slf4j.LoggerFactory;import org.springframework.beans.factory.annotation.Configurable;import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.slf4j.Logger;import org.springframework.stereotype.Component;
@Component@Aspectpublic class MyAspect {

    private static final Logger LOGGER = LoggerFactory.getLogger(MyAspect.class);

    @Before("execution(* com.example.aop.DemoController.test() )")
    public void check(JoinPoint joinPoint){
        System.out.println("hello"+joinPoint);
        LOGGER.info("hello"+joinPoint);
    }


    @Before("@annotation(CustomAn)")
    public void annotaion(JoinPoint joinPoint,CustomAn  customAn){
        System.out.println("hello custom1"+joinPoint);

        LOGGER.info("hello custom1"+joinPoint);
        LOGGER.info("CustomAn"+customAn);

    }

}
         

Solution

remove additional parameters in your aspect class . Refer to the highlighted code .

Code Changes 

the aspect class method should not have an additional parameter .

  
        


package com.example.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

import org.slf4j.Logger;
import org.springframework.stereotype.Component;

@Component@Aspectpublic class MyAspect {

    private static final Logger LOGGER = LoggerFactory.getLogger(MyAspect.class);

    @Before("execution(* com.example.aop.DemoController.test() )")
    public void check(JoinPoint joinPoint){
        System.out.println("hello"+joinPoint);
        LOGGER.info("hello"+joinPoint);
    }


    @Before("@annotation(CustomAn)")
    public void annotaion(JoinPoint joinPoint){
        System.out.println("hello custom1"+joinPoint);

        LOGGER.info("hello custom1"+joinPoint);

    }

}


         
OUTPUT
2020-03-25 22:31:22.076 DEBUG 18068 --- [http-nio-8095-Acceptor] o.apache.tomcat.util.threads.LimitLatch  : Counting up[http-nio-8095-Acceptor] latch=0
2020-03-25 22:31:22.092  INFO 18068 --- [main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8095 (http) with context path ''
2020-03-25 22:31:22.107  INFO 18068 --- [main] com.example.aop.DemoApplication          : Started DemoApplication in 8.303 seconds (JVM running for 9.424)




Thanks for reading . Let me know your thoughts in the comments below    .

Saturday, March 21, 2020

'ng' is not recognized as an internal or external command.



Error Blog 

Hi Guys ,
This blog is about the error   Error: 'ng' is not recognized as an internal or external command.

Problem Statement

unable to run an angular app via ng serve .


Error Details 

error Log

ERROR DETAILS 
 'ng' is not recognized as an internal or external command,
operable program or batch file 



Error Code 

Please check the path 

  
   
ng serve 
         

Solution

set path for npm 

Code Changes 

set path in command prompt

  
          set path=%path%;c:\users\me\AppData\Roaming\npm;
         
OUTPUT




Thanks for reading . Let me know your thoughts in the comments below    .

Monday, March 16, 2020

No base href set . Please provide a value for the APP_BASE_HREF in the token or add a base element to the document

HiHi Guys,

This blog is about the error
No base href set . Please provide a value for the APP_BASE_HREF in the token or add a base element to the document

You may face this error while running an angular application.
The solution is to add base href tag in the head part of index.html

Sunday, March 15, 2020

Error: Cannot find module 'express'



Error Blog 

Hi Guys ,
This blog is about the error   Error: Cannot find module 'express'

Problem Statement

unable to run a file using node js .


Error Details 

error Log

ERROR DETAILS 
 Error: Cannot find module 'express'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> 
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)



Error Code 

Please validate the API endpoint .

  
     var express = require('express');
var app = express();

app.use(express.static('public'));

app.get('/'function (reqres) {
   res.send('Hello World');
})

var server = app.listen(8082function () {
   var host = server.address().address;
   var port = server.address().port;

   console.log("Example app listening at http://%s:%s"hostport)
})  
         

Solution

use npm install to install the required dependencies


Code Changes 

Install express

  
         npm install express
         
OUTPUT
node server.js     
Example app listening at http://:::8082




Thanks for reading . Let me know your thoughts in the comments below    .

ec2-user@ec2 Permission denied